Open ChiTimesChi opened 11 months ago
sdk-router
TestsStop Using Tests with Forked Chains:
synapseRouter.test.ts
, replace getTestProvider
with a mocked provider.
import { mock } from 'jest-mock-extended';
const ethProvider = mock<Provider>();
fastBridgeRouter.test.ts
and synapseCCTPRouter.test.ts
.Increase Test Coverage:
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');
});
synapseRouter.ts
, fastBridgeRouter.ts
, and synapseCCTPRouter.ts
are fully tested.Introduce More Generic Test Cases:
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));
});
Make Tests Easier to Read/Write:
const createSynapseRouter = () => new SynapseRouter(SupportedChainId.ETH, ethProvider, ethAddress);
fastBridgeRouter.test.ts
and synapseCCTPRouter.test.ts
.Follow Best TypeScript Practices:
any
type.ticker.test.ts
, use specific types for test data.
const arbUSDC: ChainToken = { chainId: 42161, token: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831' };
/packages/sdk-router/src/router/synapseRouter.test.ts
/packages/sdk-router/src/rfq/fastBridgeRouter.test.ts
/packages/sdk-router/src/router/synapseCCTPRouter.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/entities/ether.test.ts
/packages/sdk-router/src/utils/computePriceImpact.test.ts
/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
A few things to tackle there: