From 6dcaf33044fab0099aa43cb463763f8c43225669 Mon Sep 17 00:00:00 2001 From: sotnikov-s Date: Thu, 14 Nov 2024 17:29:38 +0300 Subject: [PATCH] fix race in TX ICQ resubmit test and fix ICQ ID field type --- src/helpers/interchainqueries.ts | 5 +++-- .../interchain_tx_query_resubmit.test.ts | 11 ++++++++--- .../run_in_band/interchain_kv_query.test.ts | 18 +++++++++--------- .../interchain_tx_query_plain.test.ts | 14 +++++++------- 4 files changed, 27 insertions(+), 21 deletions(-) diff --git a/src/helpers/interchainqueries.ts b/src/helpers/interchainqueries.ts index 51bc596f..7e641652 100644 --- a/src/helpers/interchainqueries.ts +++ b/src/helpers/interchainqueries.ts @@ -511,7 +511,7 @@ export const getRegisteredQuery = async ( contractAddress: string, queryId: number, ): Promise<{ - id: number; + id: string; owner: string; keys: { path: string; @@ -634,7 +634,7 @@ export const registerTransfersQuery = async ( connectionId: string, updatePeriod: number, recipients: string[], -) => { +): Promise => { const res = await client.execute(contractAddress, { register_transfers_query: { connection_id: connectionId, @@ -646,6 +646,7 @@ export const registerTransfersQuery = async ( if (res.code != 0) { throw new Error('res.code != 0'); } + return parseInt(getEventAttribute(res.events, 'neutron', 'query_id')); }; /** diff --git a/src/testcases/parallel/interchain_tx_query_resubmit.test.ts b/src/testcases/parallel/interchain_tx_query_resubmit.test.ts index b1ae758d..9f2bb5f2 100644 --- a/src/testcases/parallel/interchain_tx_query_resubmit.test.ts +++ b/src/testcases/parallel/interchain_tx_query_resubmit.test.ts @@ -71,6 +71,7 @@ describe('Neutron / Interchain TX Query Resubmit', () => { const watchedAddr1: string = addrFirst; const query1UpdatePeriod = 4; + let queryId: number; describe('utilise single transfers query', () => { test('register transfers query', async () => { // Top up contract address before running query @@ -82,7 +83,7 @@ describe('Neutron / Interchain TX Query Resubmit', () => { amount: [{ denom: NEUTRON_DENOM, amount: '1000' }], }, ); - await registerTransfersQuery( + queryId = await registerTransfersQuery( neutronClient, contractAddress, connectionId, @@ -92,8 +93,12 @@ describe('Neutron / Interchain TX Query Resubmit', () => { }); test('check registered transfers query', async () => { - const query = await getRegisteredQuery(neutronClient, contractAddress, 1); - expect(query.id).toEqual('1'); + const query = await getRegisteredQuery( + neutronClient, + contractAddress, + queryId, + ); + expect(+query.id).toEqual(queryId); expect(query.owner).toEqual(contractAddress); expect(query.keys.length).toEqual(0); expect(query.query_type).toEqual('tx'); 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 1e589183..417b07e9 100644 --- a/src/testcases/run_in_band/interchain_kv_query.test.ts +++ b/src/testcases/run_in_band/interchain_kv_query.test.ts @@ -373,7 +373,7 @@ describe('Neutron / Interchain KV Query', () => { contractAddress, queryId, ); - expect(queryResult.id).toEqual(queryId.toString()); + expect(+queryResult.id).toEqual(queryId); expect(queryResult.owner).toEqual(contractAddress); expect(queryResult.keys.length).toEqual(1); expect(queryResult.keys[0].path).toEqual('bank'); @@ -394,7 +394,7 @@ describe('Neutron / Interchain KV Query', () => { contractAddress, queryId, ); - expect(queryResult.id).toEqual(queryId.toString()); + expect(+queryResult.id).toEqual(queryId); expect(queryResult.keys.length).toEqual(1); expect(queryResult.update_period).toEqual( updatePeriods[queryId].toString(), @@ -408,7 +408,7 @@ describe('Neutron / Interchain KV Query', () => { contractAddress, queryId, ); - expect(queryResult.id).toEqual(queryId.toString()); + expect(+queryResult.id).toEqual(queryId); expect(queryResult.owner).toEqual(contractAddress); // we expect three keys, 1 always + 2 per validator expect(queryResult.keys.length).toEqual(3); @@ -427,7 +427,7 @@ describe('Neutron / Interchain KV Query', () => { contractAddress, queryId, ); - expect(queryResult.id).toEqual(queryId.toString()); + expect(+queryResult.id).toEqual(queryId); expect(queryResult.owner).toEqual(contractAddress); expect(queryResult.keys.length).toEqual(2); expect(queryResult.keys[0].path).toEqual('bank'); @@ -449,7 +449,7 @@ describe('Neutron / Interchain KV Query', () => { contractAddress, queryId, ); - expect(queryResult.id).toEqual(queryId.toString()); + expect(+queryResult.id).toEqual(queryId); expect(queryResult.owner).toEqual(contractAddress); expect(queryResult.keys.length).toEqual(100); for (let i = 0; i < queryResult.keys.length; i++) { @@ -961,7 +961,7 @@ describe('Neutron / Interchain KV Query', () => { contractAddress, queryId, ); - expect(queryResult.id).toEqual(queryId.toString()); + expect(+queryResult.id).toEqual(queryId); expect(queryResult.owner).toEqual(contractAddress); // XXX: I could actually check that "key" is correctly derived from contractAddress, // but this requires bech32 decoding/encoding shenanigans @@ -1042,7 +1042,7 @@ describe('Neutron / Interchain KV Query', () => { contractAddress, queryId, ); - expect(queryResult.id).toEqual(queryId.toString()); + expect(+queryResult.id).toEqual(queryId); expect(queryResult.owner).toEqual(contractAddress); // XXX: I could actually check that "key" is correctly derived from contractAddress, // but this requires bech32 decoding/encoding shenanigans @@ -1148,7 +1148,7 @@ describe('Neutron / Interchain KV Query', () => { contractAddress, queryId, ); - expect(queryResult.id).toEqual(queryId.toString()); + expect(+queryResult.id).toEqual(queryId); expect(queryResult.owner).toEqual(contractAddress); expect(queryResult.keys.length).toEqual(1); expect(queryResult.keys[0].path).toEqual('slashing'); @@ -1232,7 +1232,7 @@ describe('Neutron / Interchain KV Query', () => { contractAddress, queryId, ); - expect(queryResult.id).toEqual(queryId.toString()); + expect(+queryResult.id).toEqual(queryId); expect(queryResult.owner).toEqual(contractAddress); expect(queryResult.keys.length).toEqual(1); expect(queryResult.keys[0].path).toEqual('staking'); diff --git a/src/testcases/run_in_band/interchain_tx_query_plain.test.ts b/src/testcases/run_in_band/interchain_tx_query_plain.test.ts index 923ee031..7944aba0 100644 --- a/src/testcases/run_in_band/interchain_tx_query_plain.test.ts +++ b/src/testcases/run_in_band/interchain_tx_query_plain.test.ts @@ -136,7 +136,7 @@ describe('Neutron / Interchain TX Query', () => { test('check registered transfers query', async () => { const query = await getRegisteredQuery(neutronClient, contractAddress, 1); - expect(query.id).toEqual('1'); + expect(+query.id).toEqual(1); expect(query.owner).toEqual(contractAddress); expect(query.keys.length).toEqual(0); expect(query.query_type).toEqual('tx'); @@ -299,7 +299,7 @@ describe('Neutron / Interchain TX Query', () => { test('check registered transfers query', async () => { const query = await getRegisteredQuery(neutronClient, contractAddress, 2); - expect(query.id).toEqual('2'); + expect(+query.id).toEqual(2); expect(query.owner).toEqual(contractAddress); expect(query.keys.length).toEqual(0); expect(query.query_type).toEqual('tx'); @@ -368,7 +368,7 @@ describe('Neutron / Interchain TX Query', () => { test('check registered transfers query', async () => { const query = await getRegisteredQuery(neutronClient, contractAddress, 3); - expect(query.id).toEqual('3'); + expect(+query.id).toEqual(3); expect(query.owner).toEqual(contractAddress); expect(query.keys.length).toEqual(0); expect(query.query_type).toEqual('tx'); @@ -698,7 +698,7 @@ describe('Neutron / Interchain TX Query', () => { test('check registered transfers query', async () => { let query = await getRegisteredQuery(neutronClient, contractAddress, 4); - expect(query.id).toEqual('4'); + expect(+query.id).toEqual(4); expect(query.owner).toEqual(contractAddress); expect(query.keys.length).toEqual(0); expect(query.query_type).toEqual('tx'); @@ -711,7 +711,7 @@ describe('Neutron / Interchain TX Query', () => { expect(query.update_period).toEqual(query4UpdatePeriod.toString()); query = await getRegisteredQuery(neutronClient, contractAddress, 5); - expect(query.id).toEqual('5'); + expect(+query.id).toEqual(5); expect(query.owner).toEqual(contractAddress); expect(query.keys.length).toEqual(0); expect(query.query_type).toEqual('tx'); @@ -845,7 +845,7 @@ describe('Neutron / Interchain TX Query', () => { test('check registered transfers query', async () => { const query = await getRegisteredQuery(neutronClient, contractAddress, 6); - expect(query.id).toEqual('6'); + expect(+query.id).toEqual(6); expect(query.owner).toEqual(contractAddress); expect(query.keys.length).toEqual(0); expect(query.query_type).toEqual('tx'); @@ -937,7 +937,7 @@ describe('Neutron / Interchain TX Query', () => { }); it('seems registered transfers query is updated', async () => { const query = await getRegisteredQuery(neutronClient, contractAddress, 3); - expect(query.id).toEqual('3'); + expect(+query.id).toEqual(3); expect(query.owner).toEqual(contractAddress); expect(query.keys.length).toEqual(0); expect(query.query_type).toEqual('tx');