Skip to content

Commit

Permalink
use getWIthAttempts instead of waitBlocks for howto ICQ tests in ICQ …
Browse files Browse the repository at this point in the history
…result submission wait
  • Loading branch information
sotnikov-s committed Nov 14, 2024
1 parent 6dcaf33 commit bd13ff2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 25 deletions.
23 changes: 13 additions & 10 deletions src/testcases/parallel/icq_howto_register_custom_kv_icq.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import {
} from '../../helpers/constants';
import { GasPrice } from '@cosmjs/stargate/build/fee';
import { SigningNeutronClient } from '../../helpers/signing_neutron_client';
import { waitBlocks } from '@neutron-org/neutronjsplus/dist/wait';
import { getWithAttempts } from '@neutron-org/neutronjsplus/dist/wait';
import { BaseAccount } from '@neutron-org/neutronjs/src/cosmos/auth/v1beta1/auth';

// just a fresh test-specific address. don't use it in other parallel test cases to avoid races
const WATCHED_GAIA_ADDR = 'cosmos1yfhvt7uje9ztwr9mk6xnkg0thf83r2d53w38ja';
Expand All @@ -20,7 +21,7 @@ const CONNECTION_ID = 'connection-0';
const ICQ_UPDATE_PERIOD = 5;

describe(
'Neutron / docs / interchainqueries / howto / register KV ICQ',
'Neutron / docs / interchainqueries / howto / register KV ICQ with custom keys',
{},
() => {
let testState: LocalState;
Expand Down Expand Up @@ -114,15 +115,17 @@ describe(
});

test('check ICQ submitted value result', async () => {
await waitBlocks(ICQ_UPDATE_PERIOD, neutronClient);

const queryResult = await neutronClient.queryContractSmart(
contractAddress,
{ account: { address: WATCHED_GAIA_ADDR } },
await getWithAttempts(
neutronClient,
async (): Promise<BaseAccount> =>
await neutronClient.queryContractSmart(contractAddress, {
account: { address: WATCHED_GAIA_ADDR },
}),
async (response) =>
response.address == WATCHED_GAIA_ADDR &&
response.sequence == BigInt(0) &&
response.accountNumber != BigInt(0),
);
expect(queryResult.address).toEqual(WATCHED_GAIA_ADDR);
expect(+queryResult.sequence).toEqual(0);
expect(+queryResult.account_number).not.toEqual(0);
});
});
},
Expand Down
28 changes: 13 additions & 15 deletions src/testcases/parallel/icq_howto_register_kv_icq.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import config from '../../config.json';
import { inject, RunnerTestSuite } from 'vitest';
import { LocalState } from '../../helpers/local_state';
import { Registry } from '@cosmjs/proto-signing';
import { Registry, Coin } from '@cosmjs/proto-signing';
import { Wallet } from '../../helpers/wallet';
import { defaultRegistryTypes, SigningStargateClient } from '@cosmjs/stargate';
import {
Expand All @@ -11,7 +11,7 @@ import {
} from '../../helpers/constants';
import { GasPrice } from '@cosmjs/stargate/build/fee';
import { SigningNeutronClient } from '../../helpers/signing_neutron_client';
import { waitBlocks } from '@neutron-org/neutronjsplus/dist/wait';
import { getWithAttempts } from '@neutron-org/neutronjsplus/dist/wait';

// just a fresh test-specific address. don't use it in other parallel test cases to avoid races
const WATCHED_GAIA_ADDR = 'cosmos1gdzru2fzdn7czxn89phu9ergn7v8c7zpladz6f';
Expand Down Expand Up @@ -114,20 +114,18 @@ describe(
});

test('check ICQ submitted value result', async () => {
await waitBlocks(ICQ_UPDATE_PERIOD, neutronClient);

const queryResult = await neutronClient.queryContractSmart(
contractAddress,
{ balances: { address: WATCHED_GAIA_ADDR } },
await getWithAttempts(
neutronClient,
async (): Promise<{ coins: Coin[] }> =>
await neutronClient.queryContractSmart(contractAddress, {
balances: { address: WATCHED_GAIA_ADDR },
}),
async (response) =>
response.coins.length == 1 &&
response.coins[0].amount ==
WATCHED_GAIA_ADDR_BALANCE_UATOM.toString() &&
response.coins[0].denom == COSMOS_DENOM,
);
expect(queryResult).toEqual({
coins: [
{
denom: COSMOS_DENOM,
amount: WATCHED_GAIA_ADDR_BALANCE_UATOM.toString(),
},
],
});
});
});
},
Expand Down

0 comments on commit bd13ff2

Please sign in to comment.