From e32ae5e4e3f30fb589904a216f767296aa8d4cff Mon Sep 17 00:00:00 2001 From: nhpd Date: Fri, 11 Aug 2023 15:29:01 +0400 Subject: [PATCH 1/8] feat: add resubmit_failure tests --- src/testcases/run_in_band/interchaintx.test.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/testcases/run_in_band/interchaintx.test.ts b/src/testcases/run_in_band/interchaintx.test.ts index 416ae8d0..6be8a6dd 100644 --- a/src/testcases/run_in_band/interchaintx.test.ts +++ b/src/testcases/run_in_band/interchaintx.test.ts @@ -713,6 +713,10 @@ describe('Neutron / Interchain TXs', () => { ); }); + test('out of gas during sudo', async () => { + + }); + test('check stored failures and acks', async () => { const failures = await neutronChain.queryAckFailures(contractAddress); // 3 ack failures, 1 timeout failure, just as described in the tests above @@ -755,6 +759,14 @@ describe('Neutron / Interchain TXs', () => { // no acks at all because all sudo handling cases resulted in an error expect(acks).toEqual([]); }); + + test('failed attempt to resubmit failure', async () => { + + }); + + test('successful resubmit failure', async () => { + + }); }); }); }); From a00ae56678a63c6dc171ada9d15e4b8ea98531b8 Mon Sep 17 00:00:00 2001 From: nhpd Date: Fri, 11 Aug 2023 16:30:25 +0400 Subject: [PATCH 2/8] feat: add resubmit_failure tests and out of gas test --- src/helpers/types.ts | 2 +- .../run_in_band/interchaintx.test.ts | 128 +++++++++++++++++- 2 files changed, 126 insertions(+), 4 deletions(-) diff --git a/src/helpers/types.ts b/src/helpers/types.ts index 10b964e9..180cf792 100644 --- a/src/helpers/types.ts +++ b/src/helpers/types.ts @@ -80,7 +80,7 @@ export type AckFailuresResponse = { type Failure = { address: string; id: number; - ack_id: number; + sequence_id: number; ack_type: string; }; diff --git a/src/testcases/run_in_band/interchaintx.test.ts b/src/testcases/run_in_band/interchaintx.test.ts index 6be8a6dd..bf367a59 100644 --- a/src/testcases/run_in_band/interchaintx.test.ts +++ b/src/testcases/run_in_band/interchaintx.test.ts @@ -545,7 +545,11 @@ describe('Neutron / Interchain TXs', () => { await neutronAccount.executeContract( contractAddress, JSON.stringify({ - integration_tests_set_sudo_failure_mock: {}, + integration_tests_set_sudo_failure_mock: { + state: { + integration_tests_sudo_failure_mock: 'enabled', + }, + }, }), ); @@ -674,7 +678,11 @@ describe('Neutron / Interchain TXs', () => { await neutronAccount.executeContract( contractAddress, JSON.stringify({ - integration_tests_set_sudo_failure_mock: {}, + integration_tests_set_sudo_failure_mock: { + state: { + integration_tests_sudo_failure_mock: 'enabled', + }, + }, }), ); @@ -713,8 +721,51 @@ describe('Neutron / Interchain TXs', () => { ); }); - test('out of gas during sudo', async () => { + test('ack failure during sudo out of gas', async () => { + // Mock sudo handler to fail + await neutronAccount.executeContract( + contractAddress, + JSON.stringify({ + integration_tests_set_sudo_failure_mock: { + state: { + integration_tests_sudo_failure_mock: 'enabled_infinite_loop', + }, + }, + }), + ); + // Testing ACK failure + await neutronAccount.executeContract( + contractAddress, + JSON.stringify({ + delegate: { + interchain_account_id: icaId1, + validator: testState.wallets.cosmos.val1.address.toString(), + amount: '10', + denom: gaiaChain.denom, + }, + }), + ); + + // wait until sudo is called and processed and failure is recorder + await getWithAttempts( + neutronChain.blockWaiter, + async () => neutronChain.queryAckFailures(contractAddress), + async (data) => data.failures.length == 5, + 100, + ); + + // make sure contract's state hasn't been changed + const acks = await getAcks(neutronChain, contractAddress); + expect(acks.length).toEqual(0); + + // Restore sudo handler's normal state + await neutronAccount.executeContract( + contractAddress, + JSON.stringify({ + integration_tests_unset_sudo_failure_mock: {}, + }), + ); }); test('check stored failures and acks', async () => { @@ -761,11 +812,82 @@ describe('Neutron / Interchain TXs', () => { }); test('failed attempt to resubmit failure', async () => { + // Mock sudo handler to fail + await neutronAccount.executeContract( + contractAddress, + JSON.stringify({ + integration_tests_set_sudo_failure_mock: { + state: { + integration_tests_sudo_failure_mock: 'enabled', + }, + }, + }), + ); + + // Try to resubmit failure + const failuresResBefore = await neutronChain.queryAckFailures( + contractAddress, + ); + const res = await neutronAccount.executeContract( + contractAddress, + JSON.stringify({ + resubmit_failure: { + failure_id: failuresResBefore.failures[0].id, + }, + }), + ); + expect(res.code).toBe(0); + + // TODO: wait? + + // check that failures count is the same + const failuresResAfter = await neutronChain.queryAckFailures( + contractAddress, + ); + expect(failuresResAfter.failures.length).toEqual(5); + + // make sure contract's state hasn't been changed + const acks = await getAcks(neutronChain, contractAddress); + expect(acks.length).toEqual(0); + // Restore sudo handler's normal state + await neutronAccount.executeContract( + contractAddress, + JSON.stringify({ + integration_tests_unset_sudo_failure_mock: {}, + }), + ); }); test('successful resubmit failure', async () => { + // Resubmit failure + const failuresResBefore = await neutronChain.queryAckFailures( + contractAddress, + ); + const failure = failuresResBefore.failures[0]; + const failureId = failure.id; + const res = await neutronAccount.executeContract( + contractAddress, + JSON.stringify({ + resubmit_failure: { + failure_id: failureId, + }, + }), + ); + expect(res.code).toBe(0); + + // TODO: wait? + // check that failures count is the same + const failuresResAfter = await neutronChain.queryAckFailures( + contractAddress, + ); + expect(failuresResAfter.failures.length).toEqual(4); + + // make sure contract's state hasn't been changed + const acks = await getAcks(neutronChain, contractAddress); + expect(acks.length).toEqual(1); + expect(acks[0].sequence_id).toEqual(failure.sequence_id); }); }); }); From 083fc27e347f15c47770e4fb969ca18de9ad5e98 Mon Sep 17 00:00:00 2001 From: nhpd Date: Fri, 11 Aug 2023 16:48:35 +0400 Subject: [PATCH 3/8] add resubmit and out of gas tests for simple.test --- src/testcases/parallel/simple.test.ts | 113 +++++++++++++++++++++++++- 1 file changed, 111 insertions(+), 2 deletions(-) diff --git a/src/testcases/parallel/simple.test.ts b/src/testcases/parallel/simple.test.ts index 2851b9e4..6f1f29b4 100644 --- a/src/testcases/parallel/simple.test.ts +++ b/src/testcases/parallel/simple.test.ts @@ -470,7 +470,11 @@ describe('Neutron / Simple', () => { await neutronAccount.executeContract( contractAddress, JSON.stringify({ - integration_tests_set_sudo_failure_mock: {}, + integration_tests_set_sudo_failure_mock: { + state: { + integration_tests_sudo_failure_mock: 'enabled', + }, + }, }), ); @@ -516,7 +520,7 @@ describe('Neutron / Simple', () => { const failuresAfterCall = await getWithAttempts( neutronChain.blockWaiter, async () => neutronChain.queryAckFailures(contractAddress), - // Wait until there 4 failure in the list + // Wait until there 4 failures in the list async (data) => data.failures.length == 4, ); @@ -551,7 +555,112 @@ describe('Neutron / Simple', () => { }), ); }); + + test('execute contract with sudo out of gas', async () => { + // Mock sudo handler to fail + await neutronAccount.executeContract( + contractAddress, + JSON.stringify({ + integration_tests_set_sudo_failure_mock: { + state: { + integration_tests_sudo_failure_mock: 'enabled_infinite_loop', + }, + }, + }), + ); + + await neutronAccount.executeContract( + contractAddress, + JSON.stringify({ + send: { + channel: 'channel-0', + to: gaiaAccount.wallet.address.toString(), + denom: NEUTRON_DENOM, + amount: '1000', + }, + }), + ); + + const failuresAfterCall = await getWithAttempts( + neutronChain.blockWaiter, + async () => neutronChain.queryAckFailures(contractAddress), + // Wait until there 6 failures in the list + async (data) => data.failures.length == 6, + ); + expect(failuresAfterCall.failures.length).toEqual(6); + }); + + test('failed attempt to resubmit failure', async () => { + // Mock sudo handler to fail + await neutronAccount.executeContract( + contractAddress, + JSON.stringify({ + integration_tests_set_sudo_failure_mock: { + state: { + integration_tests_sudo_failure_mock: 'enabled', + }, + }, + }), + ); + + // Try to resubmit failure + const failuresResBefore = await neutronChain.queryAckFailures( + contractAddress, + ); + const res = await neutronAccount.executeContract( + contractAddress, + JSON.stringify({ + resubmit_failure: { + failure_id: failuresResBefore.failures[0].id, + }, + }), + ); + expect(res.code).toBe(0); + + // TODO: wait? + + // check that failures count is the same + const failuresResAfter = await neutronChain.queryAckFailures( + contractAddress, + ); + expect(failuresResAfter.failures.length).toEqual(6); + + // Restore sudo handler's normal state + await neutronAccount.executeContract( + contractAddress, + JSON.stringify({ + integration_tests_unset_sudo_failure_mock: {}, + }), + ); + }); + + test('successful resubmit failure', async () => { + // Resubmit failure + const failuresResBefore = await neutronChain.queryAckFailures( + contractAddress, + ); + const failure = failuresResBefore.failures[0]; + const failureId = failure.id; + const res = await neutronAccount.executeContract( + contractAddress, + JSON.stringify({ + resubmit_failure: { + failure_id: failureId, + }, + }), + ); + expect(res.code).toBe(0); + + // TODO: wait? + + // check that failures count is the same + const failuresResAfter = await neutronChain.queryAckFailures( + contractAddress, + ); + expect(failuresResAfter.failures.length).toEqual(5); + }); }); + describe('Failures limit test', () => { test("failures with small limit doesn't return an error", async () => { const pagination: PageRequest = { From 1636d928d26c4547f7ae86b10ed5e793f25bbb7c Mon Sep 17 00:00:00 2001 From: nhpd Date: Fri, 11 Aug 2023 18:50:57 +0400 Subject: [PATCH 4/8] fix tests --- src/helpers/types.ts | 2 +- src/testcases/parallel/simple.test.ts | 46 +++++++++---------- .../run_in_band/interchaintx.test.ts | 4 +- 3 files changed, 25 insertions(+), 27 deletions(-) diff --git a/src/helpers/types.ts b/src/helpers/types.ts index 180cf792..f6bb6755 100644 --- a/src/helpers/types.ts +++ b/src/helpers/types.ts @@ -79,7 +79,7 @@ export type AckFailuresResponse = { // Failure represents a single contractmanager failure type Failure = { address: string; - id: number; + id: string; sequence_id: number; ack_type: string; }; diff --git a/src/testcases/parallel/simple.test.ts b/src/testcases/parallel/simple.test.ts index 6f1f29b4..7d6db43c 100644 --- a/src/testcases/parallel/simple.test.ts +++ b/src/testcases/parallel/simple.test.ts @@ -471,9 +471,7 @@ describe('Neutron / Simple', () => { contractAddress, JSON.stringify({ integration_tests_set_sudo_failure_mock: { - state: { - integration_tests_sudo_failure_mock: 'enabled', - }, + state: 'enabled', }, }), ); @@ -562,9 +560,7 @@ describe('Neutron / Simple', () => { contractAddress, JSON.stringify({ integration_tests_set_sudo_failure_mock: { - state: { - integration_tests_sudo_failure_mock: 'enabled_infinite_loop', - }, + state: 'enabled_infinite_loop', }, }), ); @@ -581,13 +577,15 @@ describe('Neutron / Simple', () => { }), ); - const failuresAfterCall = await getWithAttempts( + await neutronChain.blockWaiter.waitBlocks(30); + + const res = await getWithAttempts( neutronChain.blockWaiter, async () => neutronChain.queryAckFailures(contractAddress), // Wait until there 6 failures in the list async (data) => data.failures.length == 6, ); - expect(failuresAfterCall.failures.length).toEqual(6); + expect(res.failures.length).toEqual(6); }); test('failed attempt to resubmit failure', async () => { @@ -596,9 +594,7 @@ describe('Neutron / Simple', () => { contractAddress, JSON.stringify({ integration_tests_set_sudo_failure_mock: { - state: { - integration_tests_sudo_failure_mock: 'enabled', - }, + state: 'enabled', }, }), ); @@ -607,17 +603,19 @@ describe('Neutron / Simple', () => { const failuresResBefore = await neutronChain.queryAckFailures( contractAddress, ); - const res = await neutronAccount.executeContract( - contractAddress, - JSON.stringify({ - resubmit_failure: { - failure_id: failuresResBefore.failures[0].id, - }, - }), - ); - expect(res.code).toBe(0); - // TODO: wait? + await expect( + neutronAccount.executeContract( + contractAddress, + JSON.stringify({ + resubmit_failure: { + failure_id: +failuresResBefore.failures[0].id, + }, + }), + ), + ).rejects.toThrowError(); + + await neutronChain.blockWaiter.waitBlocks(30); // check that failures count is the same const failuresResAfter = await neutronChain.queryAckFailures( @@ -640,18 +638,18 @@ describe('Neutron / Simple', () => { contractAddress, ); const failure = failuresResBefore.failures[0]; - const failureId = failure.id; + const failureId = +failure.id; const res = await neutronAccount.executeContract( contractAddress, JSON.stringify({ resubmit_failure: { - failure_id: failureId, + failure_id: +failureId, }, }), ); expect(res.code).toBe(0); - // TODO: wait? + await neutronChain.blockWaiter.waitBlocks(30); // check that failures count is the same const failuresResAfter = await neutronChain.queryAckFailures( diff --git a/src/testcases/run_in_band/interchaintx.test.ts b/src/testcases/run_in_band/interchaintx.test.ts index bf367a59..23075543 100644 --- a/src/testcases/run_in_band/interchaintx.test.ts +++ b/src/testcases/run_in_band/interchaintx.test.ts @@ -832,7 +832,7 @@ describe('Neutron / Interchain TXs', () => { contractAddress, JSON.stringify({ resubmit_failure: { - failure_id: failuresResBefore.failures[0].id, + failure_id: +failuresResBefore.failures[0].id, }, }), ); @@ -870,7 +870,7 @@ describe('Neutron / Interchain TXs', () => { contractAddress, JSON.stringify({ resubmit_failure: { - failure_id: failureId, + failure_id: +failureId, }, }), ); From 668de7ef0a63eec5517981dd15e5b437ac6946ee Mon Sep 17 00:00:00 2001 From: nhpd Date: Mon, 14 Aug 2023 17:06:33 +0400 Subject: [PATCH 5/8] comment out not working for now out of gas --- src/testcases/parallel/simple.test.ts | 84 +++++++------ .../run_in_band/interchaintx.test.ts | 115 +++++++++--------- 2 files changed, 100 insertions(+), 99 deletions(-) diff --git a/src/testcases/parallel/simple.test.ts b/src/testcases/parallel/simple.test.ts index 7d6db43c..e756d57e 100644 --- a/src/testcases/parallel/simple.test.ts +++ b/src/testcases/parallel/simple.test.ts @@ -446,7 +446,7 @@ describe('Neutron / Simple', () => { }); }); - describe('Not enough amount of tokens on contract to pay fee', () => { + describe('Failing sudo handlers', () => { beforeAll(async () => { await neutronAccount.executeContract( contractAddress, @@ -554,39 +554,42 @@ describe('Neutron / Simple', () => { ); }); - test('execute contract with sudo out of gas', async () => { - // Mock sudo handler to fail - await neutronAccount.executeContract( - contractAddress, - JSON.stringify({ - integration_tests_set_sudo_failure_mock: { - state: 'enabled_infinite_loop', - }, - }), - ); - - await neutronAccount.executeContract( - contractAddress, - JSON.stringify({ - send: { - channel: 'channel-0', - to: gaiaAccount.wallet.address.toString(), - denom: NEUTRON_DENOM, - amount: '1000', - }, - }), - ); - - await neutronChain.blockWaiter.waitBlocks(30); - - const res = await getWithAttempts( - neutronChain.blockWaiter, - async () => neutronChain.queryAckFailures(contractAddress), - // Wait until there 6 failures in the list - async (data) => data.failures.length == 6, - ); - expect(res.failures.length).toEqual(6); - }); + // TODO: uncomment when LIMIT param is https://www.notion.so/hadron/Gas-Errors-Interchain-Txs-2b2f1caacdcd4981950641e0996cac27 implemented + // then for this test need to add limit low enough to trigger out of gas + // then change later tests length of failures (should be +2 more) + // test('execute contract with sudo out of gas', async () => { + // // Mock sudo handler to fail + // await neutronAccount.executeContract( + // contractAddress, + // JSON.stringify({ + // integration_tests_set_sudo_failure_mock: { + // state: 'enabled_infinite_loop', + // }, + // }), + // ); + + // await neutronAccount.executeContract( + // contractAddress, + // JSON.stringify({ + // send: { + // channel: 'channel-0', + // to: gaiaAccount.wallet.address.toString(), + // denom: NEUTRON_DENOM, + // amount: '1000', + // }, + // }), + // ); + + // await neutronChain.blockWaiter.waitBlocks(5); + + // const res = await getWithAttempts( + // neutronChain.blockWaiter, + // async () => neutronChain.queryAckFailures(contractAddress), + // // Wait until there 6 failures in the list + // async (data) => data.failures.length == 6, + // ); + // expect(res.failures.length).toEqual(6); + // }); test('failed attempt to resubmit failure', async () => { // Mock sudo handler to fail @@ -599,6 +602,8 @@ describe('Neutron / Simple', () => { }), ); + await neutronChain.blockWaiter.waitBlocks(2); + // Try to resubmit failure const failuresResBefore = await neutronChain.queryAckFailures( contractAddress, @@ -615,13 +620,13 @@ describe('Neutron / Simple', () => { ), ).rejects.toThrowError(); - await neutronChain.blockWaiter.waitBlocks(30); + await neutronChain.blockWaiter.waitBlocks(5); // check that failures count is the same const failuresResAfter = await neutronChain.queryAckFailures( contractAddress, ); - expect(failuresResAfter.failures.length).toEqual(6); + expect(failuresResAfter.failures.length).toEqual(4); // Restore sudo handler's normal state await neutronAccount.executeContract( @@ -630,6 +635,7 @@ describe('Neutron / Simple', () => { integration_tests_unset_sudo_failure_mock: {}, }), ); + await neutronChain.blockWaiter.waitBlocks(2); }); test('successful resubmit failure', async () => { @@ -649,13 +655,13 @@ describe('Neutron / Simple', () => { ); expect(res.code).toBe(0); - await neutronChain.blockWaiter.waitBlocks(30); + await neutronChain.blockWaiter.waitBlocks(5); - // check that failures count is the same + // check that failures count is changed const failuresResAfter = await neutronChain.queryAckFailures( contractAddress, ); - expect(failuresResAfter.failures.length).toEqual(5); + expect(failuresResAfter.failures.length).toEqual(3); }); }); diff --git a/src/testcases/run_in_band/interchaintx.test.ts b/src/testcases/run_in_band/interchaintx.test.ts index 23075543..5ee73f4e 100644 --- a/src/testcases/run_in_band/interchaintx.test.ts +++ b/src/testcases/run_in_band/interchaintx.test.ts @@ -546,9 +546,7 @@ describe('Neutron / Interchain TXs', () => { contractAddress, JSON.stringify({ integration_tests_set_sudo_failure_mock: { - state: { - integration_tests_sudo_failure_mock: 'enabled', - }, + state: 'enabled', }, }), ); @@ -679,9 +677,7 @@ describe('Neutron / Interchain TXs', () => { contractAddress, JSON.stringify({ integration_tests_set_sudo_failure_mock: { - state: { - integration_tests_sudo_failure_mock: 'enabled', - }, + state: 'enabled', }, }), ); @@ -721,52 +717,52 @@ describe('Neutron / Interchain TXs', () => { ); }); - test('ack failure during sudo out of gas', async () => { - // Mock sudo handler to fail - await neutronAccount.executeContract( - contractAddress, - JSON.stringify({ - integration_tests_set_sudo_failure_mock: { - state: { - integration_tests_sudo_failure_mock: 'enabled_infinite_loop', - }, - }, - }), - ); - - // Testing ACK failure - await neutronAccount.executeContract( - contractAddress, - JSON.stringify({ - delegate: { - interchain_account_id: icaId1, - validator: testState.wallets.cosmos.val1.address.toString(), - amount: '10', - denom: gaiaChain.denom, - }, - }), - ); - - // wait until sudo is called and processed and failure is recorder - await getWithAttempts( - neutronChain.blockWaiter, - async () => neutronChain.queryAckFailures(contractAddress), - async (data) => data.failures.length == 5, - 100, - ); - - // make sure contract's state hasn't been changed - const acks = await getAcks(neutronChain, contractAddress); - expect(acks.length).toEqual(0); - - // Restore sudo handler's normal state - await neutronAccount.executeContract( - contractAddress, - JSON.stringify({ - integration_tests_unset_sudo_failure_mock: {}, - }), - ); - }); + // TODO: uncomment when LIMIT param is https://www.notion.so/hadron/Gas-Errors-Interchain-Txs-2b2f1caacdcd4981950641e0996cac27 implemented + // then for this test need to add limit low enough to trigger out of gas + // test('ack failure during sudo out of gas', async () => { + // // Mock sudo handler to fail + // await neutronAccount.executeContract( + // contractAddress, + // JSON.stringify({ + // integration_tests_set_sudo_failure_mock: { + // state: 'enabled_infinite_loop', + // }, + // }), + // ); + + // // Testing ACK failure + // await neutronAccount.executeContract( + // contractAddress, + // JSON.stringify({ + // delegate: { + // interchain_account_id: icaId1, + // validator: testState.wallets.cosmos.val1.address.toString(), + // amount: '10', + // denom: gaiaChain.denom, + // }, + // }), + // ); + + // // wait until sudo is called and processed and failure is recorder + // await getWithAttempts( + // neutronChain.blockWaiter, + // async () => neutronChain.queryAckFailures(contractAddress), + // async (data) => data.failures.length == 5, + // 100, + // ); + + // // make sure contract's state hasn't been changed + // const acks = await getAcks(neutronChain, contractAddress); + // expect(acks.length).toEqual(0); + + // // Restore sudo handler's normal state + // await neutronAccount.executeContract( + // contractAddress, + // JSON.stringify({ + // integration_tests_unset_sudo_failure_mock: {}, + // }), + // ); + // }); test('check stored failures and acks', async () => { const failures = await neutronChain.queryAckFailures(contractAddress); @@ -817,9 +813,7 @@ describe('Neutron / Interchain TXs', () => { contractAddress, JSON.stringify({ integration_tests_set_sudo_failure_mock: { - state: { - integration_tests_sudo_failure_mock: 'enabled', - }, + state: 'enabled', }, }), ); @@ -838,13 +832,13 @@ describe('Neutron / Interchain TXs', () => { ); expect(res.code).toBe(0); - // TODO: wait? + await neutronChain.blockWaiter.waitBlocks(5); // check that failures count is the same const failuresResAfter = await neutronChain.queryAckFailures( contractAddress, ); - expect(failuresResAfter.failures.length).toEqual(5); + expect(failuresResAfter.failures.length).toEqual(4); // make sure contract's state hasn't been changed const acks = await getAcks(neutronChain, contractAddress); @@ -857,6 +851,7 @@ describe('Neutron / Interchain TXs', () => { integration_tests_unset_sudo_failure_mock: {}, }), ); + await neutronChain.blockWaiter.waitBlocks(5); }); test('successful resubmit failure', async () => { @@ -876,13 +871,13 @@ describe('Neutron / Interchain TXs', () => { ); expect(res.code).toBe(0); - // TODO: wait? + await neutronChain.blockWaiter.waitBlocks(5); - // check that failures count is the same + // check that failures count is changed const failuresResAfter = await neutronChain.queryAckFailures( contractAddress, ); - expect(failuresResAfter.failures.length).toEqual(4); + expect(failuresResAfter.failures.length).toEqual(3); // make sure contract's state hasn't been changed const acks = await getAcks(neutronChain, contractAddress); From de5ddf06538a13b4297f88891a130711cf8bccce Mon Sep 17 00:00:00 2001 From: nhpd Date: Mon, 14 Aug 2023 17:58:39 +0400 Subject: [PATCH 6/8] fix interchain tx test --- src/helpers/types.ts | 19 ++++++- src/testcases/parallel/simple.test.ts | 2 +- .../run_in_band/interchaintx.test.ts | 55 +++++++++++-------- 3 files changed, 52 insertions(+), 24 deletions(-) diff --git a/src/helpers/types.ts b/src/helpers/types.ts index f6bb6755..13864c04 100644 --- a/src/helpers/types.ts +++ b/src/helpers/types.ts @@ -80,8 +80,25 @@ export type AckFailuresResponse = { type Failure = { address: string; id: string; - sequence_id: number; + sequence_id: string; + ack: { + result: string | null; // base64 encoded bytes + error: string | null; // error text + }; ack_type: string; + packet: { + data: string; + destination_channel: string; + destination_port: string; + sequence: string; + source_channel: string; + source_port: string; + timeout_height: { + revision_height: string; + revision_number: string; + }; + timeout_timestamp: string; + }; }; export type ScheduleResponse = { diff --git a/src/testcases/parallel/simple.test.ts b/src/testcases/parallel/simple.test.ts index e756d57e..b9568fb3 100644 --- a/src/testcases/parallel/simple.test.ts +++ b/src/testcases/parallel/simple.test.ts @@ -635,7 +635,7 @@ describe('Neutron / Simple', () => { integration_tests_unset_sudo_failure_mock: {}, }), ); - await neutronChain.blockWaiter.waitBlocks(2); + await neutronChain.blockWaiter.waitBlocks(5); }); test('successful resubmit failure', async () => { diff --git a/src/testcases/run_in_band/interchaintx.test.ts b/src/testcases/run_in_band/interchaintx.test.ts index 5ee73f4e..3ebd585d 100644 --- a/src/testcases/run_in_band/interchaintx.test.ts +++ b/src/testcases/run_in_band/interchaintx.test.ts @@ -768,38 +768,46 @@ describe('Neutron / Interchain TXs', () => { const failures = await neutronChain.queryAckFailures(contractAddress); // 3 ack failures, 1 timeout failure, just as described in the tests above expect(failures.failures).toEqual([ - { + expect.objectContaining({ channel_id: 'channel-3', address: 'neutron1m0z0kk0qqug74n9u9ul23e28x5fszr628h20xwt6jywjpp64xn4qatgvm0', id: '0', - ack_id: '2', + packet: expect.objectContaining({ + sequence: '2', + }), ack_type: 'ack', - }, - { + }), + expect.objectContaining({ channel_id: 'channel-3', address: 'neutron1m0z0kk0qqug74n9u9ul23e28x5fszr628h20xwt6jywjpp64xn4qatgvm0', id: '1', - ack_id: '3', + packet: expect.objectContaining({ + sequence: '3', + }), ack_type: 'ack', - }, - { + }), + expect.objectContaining({ channel_id: 'channel-3', address: 'neutron1m0z0kk0qqug74n9u9ul23e28x5fszr628h20xwt6jywjpp64xn4qatgvm0', id: '2', - ack_id: '4', + packet: expect.objectContaining({ + sequence: '4', + }), ack_type: 'ack', - }, - { + }), + expect.objectContaining({ channel_id: 'channel-3', address: 'neutron1m0z0kk0qqug74n9u9ul23e28x5fszr628h20xwt6jywjpp64xn4qatgvm0', id: '3', - ack_id: '5', + packet: expect.objectContaining({ + sequence: '5', + }), ack_type: 'timeout', - }, + }), ]); const acks = await getAcks(neutronChain, contractAddress); @@ -818,19 +826,22 @@ describe('Neutron / Interchain TXs', () => { }), ); + await neutronChain.blockWaiter.waitBlocks(5); + // Try to resubmit failure const failuresResBefore = await neutronChain.queryAckFailures( contractAddress, ); - const res = await neutronAccount.executeContract( - contractAddress, - JSON.stringify({ - resubmit_failure: { - failure_id: +failuresResBefore.failures[0].id, - }, - }), - ); - expect(res.code).toBe(0); + await expect( + neutronAccount.executeContract( + contractAddress, + JSON.stringify({ + resubmit_failure: { + failure_id: +failuresResBefore.failures[0].id, + }, + }), + ), + ).rejects.toThrowError(); await neutronChain.blockWaiter.waitBlocks(5); @@ -882,7 +893,7 @@ describe('Neutron / Interchain TXs', () => { // make sure contract's state hasn't been changed const acks = await getAcks(neutronChain, contractAddress); expect(acks.length).toEqual(1); - expect(acks[0].sequence_id).toEqual(failure.sequence_id); + expect(acks[0].sequence_id).toEqual(+failure.packet.sequence); }); }); }); From c25cb020c2c86d4a4e7081b3b2bc7e18f851c74b Mon Sep 17 00:00:00 2001 From: nhpd Date: Thu, 17 Aug 2023 18:55:49 +0400 Subject: [PATCH 7/8] remove contractmanager stargate queries --- .../parallel/stargate_queries.test.ts | 22 ------------------- 1 file changed, 22 deletions(-) diff --git a/src/testcases/parallel/stargate_queries.test.ts b/src/testcases/parallel/stargate_queries.test.ts index 13ee54a6..0303083f 100644 --- a/src/testcases/parallel/stargate_queries.test.ts +++ b/src/testcases/parallel/stargate_queries.test.ts @@ -228,28 +228,6 @@ describe('Neutron / Simple', () => { expect(res).toBe(`{"denoms":["${newTokenDenom}"]}`); }); - test('contractmanager address failures should work', async () => { - const res = JSON.parse( - await querySmart({ - contractmanager_address_failures: { - address: neutronAccount.wallet.address.toString(), - }, - }), - ); - expect(res.failures).toEqual([]); - }); - - test('contractmanager failures should work', async () => { - const res = JSON.parse( - await querySmart({ - contractmanager_failures: { - address: neutronAccount.wallet.address.toString(), - }, - }), - ); - expect(res.failures).toEqual([]); - }); - test('interchaintx params should work', async () => { const res = JSON.parse(await querySmart({ interchaintx_params: {} })); expect(+res.params.msg_submit_tx_max_messages).toBeGreaterThan(0); From 625b035062d01138ef8010039d5ee4c7a8108ee7 Mon Sep 17 00:00:00 2001 From: nhpd Date: Fri, 18 Aug 2023 01:39:45 +0400 Subject: [PATCH 8/8] change fields for failure struct check --- src/helpers/types.ts | 7 ++++--- src/testcases/run_in_band/interchaintx.test.ts | 10 +++++----- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/helpers/types.ts b/src/helpers/types.ts index 95416f2e..9780bf12 100644 --- a/src/helpers/types.ts +++ b/src/helpers/types.ts @@ -80,10 +80,11 @@ export type AckFailuresResponse = { type Failure = { address: string; id: string; - sequence_id: string; ack: { - result: string | null; // base64 encoded bytes - error: string | null; // error text + response: { + result: string | null; // base64 encoded bytes + error: string | null; // error text + }; }; ack_type: string; packet: { diff --git a/src/testcases/run_in_band/interchaintx.test.ts b/src/testcases/run_in_band/interchaintx.test.ts index 3ebd585d..26cb218b 100644 --- a/src/testcases/run_in_band/interchaintx.test.ts +++ b/src/testcases/run_in_band/interchaintx.test.ts @@ -769,41 +769,41 @@ describe('Neutron / Interchain TXs', () => { // 3 ack failures, 1 timeout failure, just as described in the tests above expect(failures.failures).toEqual([ expect.objectContaining({ - channel_id: 'channel-3', address: 'neutron1m0z0kk0qqug74n9u9ul23e28x5fszr628h20xwt6jywjpp64xn4qatgvm0', id: '0', packet: expect.objectContaining({ + source_channel: 'channel-3', sequence: '2', }), ack_type: 'ack', }), expect.objectContaining({ - channel_id: 'channel-3', address: 'neutron1m0z0kk0qqug74n9u9ul23e28x5fszr628h20xwt6jywjpp64xn4qatgvm0', id: '1', packet: expect.objectContaining({ + source_channel: 'channel-3', sequence: '3', }), ack_type: 'ack', }), expect.objectContaining({ - channel_id: 'channel-3', address: 'neutron1m0z0kk0qqug74n9u9ul23e28x5fszr628h20xwt6jywjpp64xn4qatgvm0', id: '2', packet: expect.objectContaining({ + source_channel: 'channel-3', sequence: '4', }), ack_type: 'ack', }), expect.objectContaining({ - channel_id: 'channel-3', address: 'neutron1m0z0kk0qqug74n9u9ul23e28x5fszr628h20xwt6jywjpp64xn4qatgvm0', id: '3', packet: expect.objectContaining({ + source_channel: 'channel-3', sequence: '5', }), ack_type: 'timeout', @@ -890,7 +890,7 @@ describe('Neutron / Interchain TXs', () => { ); expect(failuresResAfter.failures.length).toEqual(3); - // make sure contract's state hasn't been changed + // make sure contract's state has been changed const acks = await getAcks(neutronChain, contractAddress); expect(acks.length).toEqual(1); expect(acks[0].sequence_id).toEqual(+failure.packet.sequence);