core icon indicating copy to clipboard operation
core copied to clipboard

refactor: flatten nested test helpers and remove any types

Open cryptodev-2s opened this issue 3 months ago • 0 comments

Explanation

Tests with RPC failover required triple-nested withMockedCommunications blocks, creating excessive indentation and reducing readability. Test helpers also used 20+ instances of any types.

Solution

  • Added mockedEndpoints array option to withNetworkClient - eliminates nested blocks
  • Replaced any types with proper types (Json, unknown, generics)
  • Reduced test indentation from 3 levels to 1 level

Before

await withMockedCommunications({ ... }, async (primaryComms) => {
  await withMockedCommunications({ ... }, async (failoverComms) => {
    await withNetworkClient({ ... }, async ({ ... }) => {
      // test logic
    });
  });
});

After

await withNetworkClient({
  mockedEndpoints: [
    { providerType: networkClientType },
    { providerType: 'custom', customRpcUrl: failoverEndpointUrl },
  ],
}, async ({ comms }) => {
  const [primaryComms, failoverComms] = comms;
  // test logic
});

References

Checklist

  • [ ] I've updated the test suite for new or updated code as appropriate
  • [ ] I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • [ ] I've communicated my changes to consumers by updating changelogs for packages I've changed
  • [ ] I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

cryptodev-2s avatar Nov 25 '25 18:11 cryptodev-2s