From 16b1f5ad627c554be8240338d9809ab352d73396 Mon Sep 17 00:00:00 2001 From: sotnikov-s Date: Fri, 31 May 2024 15:58:40 +0300 Subject: [PATCH] add multiple denoms balances ICQ test --- .../run_in_band/interchain_kv_query.test.ts | 126 +++++++++++++++--- 1 file changed, 107 insertions(+), 19 deletions(-) diff --git a/src/testcases/run_in_band/interchain_kv_query.test.ts b/src/testcases/run_in_band/interchain_kv_query.test.ts index f482f3b9..b9f0cd83 100644 --- a/src/testcases/run_in_band/interchain_kv_query.test.ts +++ b/src/testcases/run_in_band/interchain_kv_query.test.ts @@ -171,20 +171,20 @@ const getQueryDelegatorDelegationsResult = ( }, }); -const registerBalanceQuery = async ( +const registerBalancesQuery = async ( cm: WalletWrapper, contractAddress: string, connectionId: string, updatePeriod: number, - denom: string, + denoms: string[], addr: cosmosclient.AccAddress, ) => { const txResult = await cm.executeContract( contractAddress, JSON.stringify({ - register_balance_query: { + register_balances_query: { connection_id: connectionId, - denom: denom, + denoms: denoms, addr: addr.toString(), update_period: updatePeriod, }, @@ -463,6 +463,7 @@ describe('Neutron / Interchain KV Query', () => { 2: 3, 3: 4, 4: 3, + 5: 4, }; let testState: TestStateLocalCosmosTestNet; let neutronChain: CosmosWrapper; @@ -526,9 +527,9 @@ describe('Neutron / Interchain KV Query', () => { await neutronAccount.executeContract( contractAddress, JSON.stringify({ - register_balance_query: { + register_balances_query: { connection_id: connectionId, - denom: gaiaChain.denom, + denoms: [gaiaChain.denom], addr: testState.wallets.cosmos.demo2.address.toString(), update_period: 10, }, @@ -588,12 +589,12 @@ describe('Neutron / Interchain KV Query', () => { let balances = await neutronChain.queryBalances(contractAddress); expect(balances.balances[0].amount).toEqual('1000000'); - await registerBalanceQuery( + await registerBalancesQuery( neutronAccount, contractAddress, connectionId, 10, - gaiaChain.denom, + [gaiaChain.denom], testState.wallets.cosmos.demo2.address, ); @@ -609,23 +610,23 @@ describe('Neutron / Interchain KV Query', () => { }); test('register icq #2: balance', async () => { - await registerBalanceQuery( + await registerBalancesQuery( neutronAccount, contractAddress, connectionId, updatePeriods[2], - gaiaChain.denom, + [gaiaChain.denom], testState.wallets.cosmos.demo2.address, ); }); test('register icq #3: balance', async () => { - await registerBalanceQuery( + await registerBalancesQuery( neutronAccount, contractAddress, connectionId, updatePeriods[3], - gaiaChain.denom, + [gaiaChain.denom], testState.wallets.cosmos.val1.address, ); }); @@ -640,6 +641,17 @@ describe('Neutron / Interchain KV Query', () => { [testState.wallets.cosmos.val1.address], ); }); + + test('register icq #5: multiple balances', async () => { + await registerBalancesQuery( + neutronAccount, + contractAddress, + connectionId, + updatePeriods[5], + [gaiaChain.denom, 'nonexistentdenom'], + testState.wallets.cosmos.val1.address, + ); + }); }); }); @@ -700,8 +712,34 @@ describe('Neutron / Interchain KV Query', () => { ); }); - test("registered icq #5 doesn't exist", async () => { + test('get registered icq #5: multiple balances', async () => { const queryId = 5; + const queryResult = await getRegisteredQuery( + neutronChain, + contractAddress, + queryId, + ); + expect(queryResult.registered_query.id).toEqual(queryId); + expect(queryResult.registered_query.owner).toEqual(contractAddress); + expect(queryResult.registered_query.keys.length).toEqual(2); + expect(queryResult.registered_query.keys[0].path).toEqual('bank'); + expect(queryResult.registered_query.keys[0].key.length).toBeGreaterThan( + 0, + ); + expect(queryResult.registered_query.keys[1].path).toEqual('bank'); + expect(queryResult.registered_query.keys[1].key.length).toBeGreaterThan( + 0, + ); + expect(queryResult.registered_query.query_type).toEqual('kv'); + expect(queryResult.registered_query.transactions_filter).toEqual(''); + expect(queryResult.registered_query.connection_id).toEqual(connectionId); + expect(queryResult.registered_query.update_period).toEqual( + updatePeriods[queryId], + ); + }); + + test("registered icq #6 doesn't exist", async () => { + const queryId = 6; await expect( getRegisteredQuery(neutronChain, contractAddress, queryId), ).rejects.toThrow(); @@ -780,6 +818,56 @@ describe('Neutron / Interchain KV Query', () => { (1500000).toString(), ); }); + + test('perform icq #5: multiple balances', async () => { + const queryId = 5; + await waitForICQResultWithRemoteHeight( + neutronChain, + contractAddress, + queryId, + await getHeight(gaiaChain.sdk), + ); + + const interchainQueryResult = await getQueryBalanceResult( + neutronChain, + contractAddress, + queryId, + ); + const directQueryResult = await cosmosclient.rest.bank.allBalances( + gaiaChain.sdk, + testState.wallets.cosmos.val1.address.toAccAddress().toString(), + ); + + expect(interchainQueryResult.balances.coins.length).toEqual(2); + expect( + interchainQueryResult.balances.coins.find( + (c) => c.denom == gaiaChain.denom, + ), + ).toBeDefined(); + expect( + interchainQueryResult.balances.coins.find( + (c) => c.denom == gaiaChain.denom, + )?.amount, + ).toEqual( + directQueryResult.data.balances?.find((c) => c.denom == gaiaChain.denom) + ?.amount, + ); + expect( + directQueryResult.data.balances?.find( + (c) => c.denom == 'nonexistentdenom', + ), + ).toEqual(undefined); + expect( + interchainQueryResult.balances.coins.find( + (c) => c.denom == 'nonexistentdenom', + ), + ).toBeDefined(); + expect( + interchainQueryResult.balances.coins.find( + (c) => c.denom == 'nonexistentdenom', + )?.amount, + ).toEqual('0'); + }); }); // In this test suite we aim to ensure contract state gets correctly reverted @@ -878,12 +966,12 @@ describe('Neutron / Interchain KV Query', () => { test('should check query creation with governance parameters', async () => { const params = await neutronChain.queryInterchainqueriesParams(); - const queryId = await registerBalanceQuery( + const queryId = await registerBalancesQuery( neutronAccount, contractAddress, connectionId, 2, - gaiaChain.denom, + [gaiaChain.denom], gaiaAccount.wallet.address, ); @@ -938,12 +1026,12 @@ describe('Neutron / Interchain KV Query', () => { JSON.stringify(queryDepositParam), ); - const queryId = await registerBalanceQuery( + const queryId = await registerBalancesQuery( neutronAccount, contractAddress, connectionId, 10, - gaiaChain.denom, + [gaiaChain.denom], testState.wallets.cosmos.demo2.address, ); @@ -994,12 +1082,12 @@ describe('Neutron / Interchain KV Query', () => { balancesBeforeRegistration.balances as ICoin[], ); - const queryId = await registerBalanceQuery( + const queryId = await registerBalancesQuery( neutronAccount, contractAddress, connectionId, 15, - gaiaChain.denom, + [gaiaChain.denom], testState.wallets.cosmos.demo2.address, );