synapsecns / sanguine

Synapse Monorepo
MIT License
37 stars 30 forks source link

Rework `sdk-router` tests #1562

Open ChiTimesChi opened 11 months ago

ChiTimesChi commented 11 months ago

A few things to tackle there:

greptile-apps[bot] commented 4 months ago

Steps to Rework sdk-router Tests

  1. Stop Using Tests with Forked Chains:

    • Replace forked chain tests with mocks.
    • Example: In synapseRouter.test.ts, replace getTestProvider with a mocked provider.
      import { mock } from 'jest-mock-extended';
      const ethProvider = mock<Provider>();
    • Apply similar changes in fastBridgeRouter.test.ts and synapseCCTPRouter.test.ts.
  2. Increase Test Coverage:

    • Add tests for untested branches and edge cases.
    • Example: In synapseRouter.test.ts, add tests for error cases in bridge method.
      it('throws error on invalid recipient', async () => {
      await expect(synapseRouter.bridge('', ...)).rejects.toThrow('Invalid recipient');
      });
    • Ensure all methods in synapseRouter.ts, fastBridgeRouter.ts, and synapseCCTPRouter.ts are fully tested.
  3. Introduce More Generic Test Cases:

    • Add parameterized tests to cover a wider range of inputs.
    • Example: In query.test.ts, use test.each for applySlippageToQuery.
      test.each([
      [0, 10000, 1000000],
      [50, 10000, 995000],
      [10, 100, 900000],
      ])('applies %i%% slippage', (slippage, denominator, expected) => {
      const newQuery = applySlippageToQuery(query, slippage, denominator);
      expect(newQuery.minAmountOut).toEqual(BigNumber.from(expected));
      });
  4. Make Tests Easier to Read/Write:

    • Refactor to remove duplication and follow best TypeScript practices.
    • Example: Extract common setup code into helper functions.
      const createSynapseRouter = () => new SynapseRouter(SupportedChainId.ETH, ethProvider, ethAddress);
    • Apply similar refactoring in fastBridgeRouter.test.ts and synapseCCTPRouter.test.ts.
  5. Follow Best TypeScript Practices:

    • Ensure type safety and avoid any type.
    • Example: In ticker.test.ts, use specific types for test data.
      const arbUSDC: ChainToken = { chainId: 42161, token: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831' };

Files to Modify

References

/packages/sdk-router/src/router/synapseRouter.test.ts /packages/sdk-router/src/rfq/fastBridgeRouter.test.ts /packages/sdk-router/src/module/query.test.ts /packages/sdk-router/src/rfq/ticker.test.ts /packages/sdk-router/src/rfq/api.integration.test.ts /packages/sdk-router/src/rfq/quote.test.ts /packages/sdk-router/src/router/synapseCCTPRouter.test.ts /packages/sdk-router/src/entities/ether.test.ts /packages/sdk-router/src/utils/computePriceImpact.test.ts /packages/sdk-router/src/constants /packages/sdk-router/src/router /packages/sdk-router/src/utils

Ask Greptile