Skip to content

Dedupe builder/validator test apiStub helpers into packages/test-utils #9819

Description

@lodekeeper

Follow-up from #9781.

packages/builder/test/unit/utils/apiStub.ts (added in #9781) largely duplicates packages/validator/test/utils/apiStub.ts. Per discussion on #9781, the shared parts should be deduped into packages/test-utils as a follow-up so the two don't drift.

Current state

Comparing the two, it's a bit more than a 1:1 dup — a few things need reconciling:

  • mockApiResponse — identical in both; trivially shareable.
  • getApiClientStub — function lists differ. Builder stubs only beacon.getStateBuilders + node.getSyncingStatus; validator stubs a much larger beacon/node/validator set plus httpClient. Note the builder adds beacon.getStateBuilders, which the validator stub doesn't have. A shared helper would need to expose a superset or be parameterized so each consumer only stubs the endpoints it needs.
  • mockApiErrorResponse — already aligned on unstable: the validator version is async + await res.errorBody() there. (An earlier revision of this issue flagged it as diverged, but that compared against the feat(builder): add readiness gating and builder identity resolution #9781 branch snapshot, which predates that change — thanks @markolazic01.) Once feat(builder): add readiness gating and builder identity resolution #9781 is on top of unstable, both are identical, so no reconciliation needed here.
  • httpClientStub + httpClient field — present in validator, omitted in builder.
  • ApiClientStub type — exported in builder, local in validator.

Suggested approach

Move the shared pieces (the ApiClientStub type, mockApiResponse, mockApiErrorResponse, and a base getApiClientStub / httpClientStub) into packages/test-utils, and have both the builder and validator suites import from there, stubbing package-specific endpoints on top as needed.

Not urgent — filing so it isn't lost after #9781 merges.

Refs: #9781, #9781 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status
    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions