Skip to content

Commit

Permalink
tests: coverage on fungible token balances and null token cases
Browse files Browse the repository at this point in the history
  • Loading branch information
simsbluebox committed Jul 18, 2024
1 parent 996328e commit 60ba9b7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
8 changes: 8 additions & 0 deletions test/alexSDK.mock-exceptions.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { AlexSDK, Currency } from '../src';
import * as ammRouteResolver from '../src/utils/ammRouteResolver';
import { assertNever } from '../src/utils/utils';
import { configs } from '../src/config';

const sdk = new AlexSDK();
Expand Down Expand Up @@ -37,4 +38,11 @@ describe('AlexSDK - mock exceptions', () => {
)
).rejects.toThrow('Too many AMM pools in route');
}, 10000);

it('Attempt assertNever to throw unexpected object', () => {
const unexpectedObject = '' as never;
expect(() => assertNever(unexpectedObject)).toThrowError(
'Unexpected object: ' + unexpectedObject
);
});
});
24 changes: 17 additions & 7 deletions test/alexSDK.mock-helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ import {
dummyBalances,
dummyCurrencies,
dummyFee,
dummyPrices,
dummyRate,
dummyTx,
parsedDummyPrices,
dummyTokenA,
dummyTokenB,
dummyFactorA,
dummyFactorB,
dummyTokenC, DUMMY_DEPLOYER,
dummyTokenC,
DUMMY_DEPLOYER,
} from './mock-data/alexSDKMockResponses';
import { cvToValue, FungibleConditionCode } from '@stacks/transactions';

Expand Down Expand Up @@ -53,10 +53,16 @@ jest.mock('../src/helpers/SwapHelper', () => {
});
jest.mock('../src/utils/fetchData', () => {
const originalModule = jest.requireActual('../src/utils/fetchData');
const { dummyPrices, dummyCurrencies } = jest.requireActual(
'./mock-data/alexSDKMockResponses'
);
return {
__esModule: true,
...originalModule,
getPrices: jest.fn(async () => dummyPrices),
getPrices: jest
.fn()
.mockReturnValueOnce(dummyPrices)
.mockReturnValueOnce(originalModule.getPrices(dummyCurrencies)),
fetchBalanceForAccount: jest.fn(async () => dummyBalances),
getAlexSDKData: jest.fn(async () => dummyAlexSDKData),
};
Expand All @@ -70,7 +76,7 @@ jest.mock('../src/utils/ammRouteResolver', () => {
}
return originalModule.resolveAmmRoute(tokenX, ...args);
}),
}
};
});

describe('AlexSDK - mock helpers', () => {
Expand Down Expand Up @@ -146,9 +152,7 @@ describe('AlexSDK - mock helpers', () => {
amount,
BigInt(0)
)
).rejects.toThrow(
'Can\'t find AMM route'
);
).rejects.toThrow("Can't find AMM route");
});

it('Verify response value of getLatestPrices function', async () => {
Expand All @@ -157,6 +161,12 @@ describe('AlexSDK - mock helpers', () => {
expect(result).toStrictEqual(parsedDummyPrices);
});

it('Verify response value of getLatestPrices function (null token cases)', async () => {
expect(jest.isMockFunction(fetchData.getPrices)).toBeTruthy();
const result = await sdk.getLatestPrices();
expect(result).toBeDefined();
});

it('Verify response value of getBalances function', async () => {
expect(jest.isMockFunction(fetchData.fetchBalanceForAccount)).toBeTruthy();
const stxAddress = 'SM2MARAVW6BEJCD13YV2RHGYHQWT7TDDNMNRB1MVT';
Expand Down
6 changes: 6 additions & 0 deletions test/alexSDK.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,12 @@ describe('AlexSDK', () => {
});
}, 10000);

it('Verify response of getBalances function (with fungible token balance)', async () => {
const stxAddress = 'SP3ANPTPEQE72PNE31WE8BEV4VCKB2C38P48TPH0Q';
const balances = await sdk.getBalances(stxAddress);
expect(balances).toBeDefined();
}, 10000);

it('Attempt to Get Tx with an invalid stx address (checksum mismatch)', async () => {
await expect(
sdk.runSwap(
Expand Down

0 comments on commit 60ba9b7

Please sign in to comment.