Skip to content

Commit

Permalink
fix race in TX ICQ resubmit test and fix ICQ ID field type
Browse files Browse the repository at this point in the history
  • Loading branch information
sotnikov-s committed Nov 14, 2024
1 parent 226c867 commit 6dcaf33
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 21 deletions.
5 changes: 3 additions & 2 deletions src/helpers/interchainqueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ export const getRegisteredQuery = async (
contractAddress: string,
queryId: number,
): Promise<{
id: number;
id: string;
owner: string;
keys: {
path: string;
Expand Down Expand Up @@ -634,7 +634,7 @@ export const registerTransfersQuery = async (
connectionId: string,
updatePeriod: number,
recipients: string[],
) => {
): Promise<number> => {
const res = await client.execute(contractAddress, {
register_transfers_query: {
connection_id: connectionId,
Expand All @@ -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'));
};

/**
Expand Down
11 changes: 8 additions & 3 deletions src/testcases/parallel/interchain_tx_query_resubmit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -82,7 +83,7 @@ describe('Neutron / Interchain TX Query Resubmit', () => {
amount: [{ denom: NEUTRON_DENOM, amount: '1000' }],
},
);
await registerTransfersQuery(
queryId = await registerTransfersQuery(
neutronClient,
contractAddress,
connectionId,
Expand All @@ -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');
Expand Down
18 changes: 9 additions & 9 deletions src/testcases/run_in_band/interchain_kv_query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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(),
Expand All @@ -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);
Expand All @@ -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');
Expand All @@ -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++) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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');
Expand Down
14 changes: 7 additions & 7 deletions src/testcases/run_in_band/interchain_tx_query_plain.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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');
Expand All @@ -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');
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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');
Expand Down

0 comments on commit 6dcaf33

Please sign in to comment.