core
core copied to clipboard
refactor: flatten nested test helpers and remove any types
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
mockedEndpointsarray option towithNetworkClient- eliminates nested blocks - Replaced
anytypes 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