Skip to content

Commit

Permalink
[TS SDK] Add e2e tests for Coin utility functions (MystenLabs#6829)
Browse files Browse the repository at this point in the history
  • Loading branch information
xydas97 authored Dec 19, 2022
1 parent 826c1cd commit dc76d2d
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions sdk/typescript/test/e2e/coin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
Coin,
getObjectId,
LocalTxnDataSerializer,
normalizeSuiObjectId,
ObjectId,
RawSigner,
SuiObjectInfo,
Expand Down Expand Up @@ -46,6 +47,39 @@ describe('Coin related API', () => {
expect(coinsAfterSplit.length).toEqual(coins.length + SPLIT_AMOUNTS.length);
});

it('test Coin utility functions', async () => {
const coins = await toolbox.provider.getGasObjectsOwnedByAddress(
toolbox.address()
);
coins.forEach((c) => {
expect(Coin.isCoin(c)).toBeTruthy;
expect(Coin.isSUI(c)).toBeTruthy;
})
});

it('test getCoinStructTag', async () => {
const exampleStructTag = {
address: normalizeSuiObjectId('0x2'),
module: 'sui',
name: 'SUI',
typeParams: []
};
const coins = await toolbox.provider.getGasObjectsOwnedByAddress(
toolbox.address()
);
const coinTypeArg: string = Coin.getCoinTypeArg(coins[0])!;
expect(Coin.getCoinStructTag(coinTypeArg)).toStrictEqual(exampleStructTag);
});

it('test Coin balance functions', async () => {
const coins =
await toolbox.provider.getCoinBalancesOwnedByAddress(
toolbox.address(),
'0x2::sui::SUI'
);
expect(Coin.totalBalance(coins)).toBeGreaterThan(BigInt(0));
});

it('test selectCoinsWithBalanceGreaterThanOrEqual', async () => {
await Promise.all(
SPLIT_AMOUNTS.map(async (a, i) => {
Expand Down

0 comments on commit dc76d2d

Please sign in to comment.