Skip to content

Commit

Permalink
tests: empty route coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
simsbluebox committed Jul 18, 2024
1 parent 251d9d0 commit 996328e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
35 changes: 30 additions & 5 deletions test/alexSDK.mock-helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
dummyTokenB,
dummyFactorA,
dummyFactorB,
dummyTokenC,
dummyTokenC, DUMMY_DEPLOYER,
} from './mock-data/alexSDKMockResponses';
import { cvToValue, FungibleConditionCode } from '@stacks/transactions';

Expand Down Expand Up @@ -61,9 +61,17 @@ jest.mock('../src/utils/fetchData', () => {
getAlexSDKData: jest.fn(async () => dummyAlexSDKData),
};
});
jest.mock('../src/utils/ammRouteResolver', () => ({
resolveAmmRoute: jest.fn(() => dummyAmmRoute),
}));
jest.mock('../src/utils/ammRouteResolver', () => {
const originalModule = jest.requireActual('../src/utils/ammRouteResolver');
return {
resolveAmmRoute: jest.fn((tokenX, ...args) => {
if (tokenX === dummyTokenA) {
return dummyAmmRoute;
}
return originalModule.resolveAmmRoute(tokenX, ...args);
}),
}
});

describe('AlexSDK - mock helpers', () => {
it('Verify response value of getFeeRate function', async () => {
Expand Down Expand Up @@ -97,7 +105,7 @@ describe('AlexSDK - mock helpers', () => {
it('Verify response value of runSwap function', async () => {
expect(jest.isMockFunction(SwapHelper.runSpot)).toBeTruthy();
const result = await sdk.runSwap(
'SP111111111111111111111111111111111111111',
DUMMY_DEPLOYER,
tokenAlex,
tokenWUSDA,
BigInt(1),
Expand Down Expand Up @@ -126,6 +134,23 @@ describe('AlexSDK - mock helpers', () => {
expect(result.postConditions[0].amount).toStrictEqual(BigInt(0));
});

it('Verify response value of runSwap function (empty pools)', async () => {
expect(jest.isMockFunction(SwapHelper.runSpot)).toBeTruthy();
expect(jest.isMockFunction(ammRouteResolver.resolveAmmRoute)).toBeTruthy();
const amount = BigInt(2) * BigInt(1e8);
await expect(
sdk.runSwap(
configs.CONTRACT_DEPLOYER,
dummyTokenB,
dummyTokenC,
amount,
BigInt(0)
)
).rejects.toThrow(
'Can\'t find AMM route'
);
});

it('Verify response value of getLatestPrices function', async () => {
expect(jest.isMockFunction(fetchData.getPrices)).toBeTruthy();
const result = await sdk.getLatestPrices();
Expand Down
3 changes: 2 additions & 1 deletion test/mock-data/alexSDKMockResponses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { AMMRouteSegment } from '../../src/utils/ammRouteResolver';
import { configs } from '../../src/config';

const validDeployer = configs.CONTRACT_DEPLOYER;
export const DUMMY_DEPLOYER = 'SP111111111111111111111111111111111111111';

export const dummyFee = BigInt(777);

Expand Down Expand Up @@ -116,5 +117,5 @@ export const dummyPools: PoolData[] = [

export const dummyAlexSDKData: AlexSDKResponse = {
tokens: dummyCurrencies,
pools: dummyPools,
pools: [],
};

0 comments on commit 996328e

Please sign in to comment.