From f21480f57d9ad10da214e400a32d794ecff5a50a Mon Sep 17 00:00:00 2001 From: sotnikov-s Date: Thu, 9 Nov 2023 18:59:23 +0300 Subject: [PATCH] add tests for Failure's error field and failure details retrieved via CLI query --- .../run_in_band/interchaintx.test.ts | 111 +++++++++++++----- 1 file changed, 79 insertions(+), 32 deletions(-) diff --git a/src/testcases/run_in_band/interchaintx.test.ts b/src/testcases/run_in_band/interchaintx.test.ts index 39a4c2c8..bcbf953e 100644 --- a/src/testcases/run_in_band/interchaintx.test.ts +++ b/src/testcases/run_in_band/interchaintx.test.ts @@ -1,4 +1,5 @@ import 'jest-extended'; +import { execSync } from 'child_process'; import cosmosclient from '@cosmos-client/core'; import { AccAddress } from '@cosmos-client/core/cjs/types'; import { @@ -890,44 +891,85 @@ describe('Neutron / Interchain TXs', () => { test('check stored failures and acks', async () => { const failures = await neutronChain.queryAckFailures(contractAddress); // 4 ack failures, 2 timeout failure, just as described in the tests above - expect(failures.failures).toEqual([ - expect.objectContaining({ - address: - 'neutron1m0z0kk0qqug74n9u9ul23e28x5fszr628h20xwt6jywjpp64xn4qatgvm0', - id: '0', - }), - expect.objectContaining({ - address: - 'neutron1m0z0kk0qqug74n9u9ul23e28x5fszr628h20xwt6jywjpp64xn4qatgvm0', - id: '1', - }), - expect.objectContaining({ - address: - 'neutron1m0z0kk0qqug74n9u9ul23e28x5fszr628h20xwt6jywjpp64xn4qatgvm0', - id: '2', - }), - expect.objectContaining({ - address: - 'neutron1m0z0kk0qqug74n9u9ul23e28x5fszr628h20xwt6jywjpp64xn4qatgvm0', - id: '3', - }), - expect.objectContaining({ - address: - 'neutron1m0z0kk0qqug74n9u9ul23e28x5fszr628h20xwt6jywjpp64xn4qatgvm0', - id: '4', - }), - expect.objectContaining({ - address: - 'neutron1m0z0kk0qqug74n9u9ul23e28x5fszr628h20xwt6jywjpp64xn4qatgvm0', - id: '5', - }), - ]); + expect(failures.failures).toEqual( + expect.arrayContaining([ + expect.objectContaining({ + address: + 'neutron1m0z0kk0qqug74n9u9ul23e28x5fszr628h20xwt6jywjpp64xn4qatgvm0', + id: '0', + error: 'codespace: wasm, code: 5', // execute wasm contract failer + }), + expect.objectContaining({ + address: + 'neutron1m0z0kk0qqug74n9u9ul23e28x5fszr628h20xwt6jywjpp64xn4qatgvm0', + id: '1', + error: 'codespace: wasm, code: 5', // execute wasm contract failer + }), + expect.objectContaining({ + address: + 'neutron1m0z0kk0qqug74n9u9ul23e28x5fszr628h20xwt6jywjpp64xn4qatgvm0', + id: '2', + error: 'codespace: wasm, code: 5', // execute wasm contract failer + }), + expect.objectContaining({ + address: + 'neutron1m0z0kk0qqug74n9u9ul23e28x5fszr628h20xwt6jywjpp64xn4qatgvm0', + id: '3', + error: 'codespace: contractmanager, code: 1103', // contractmanager sudo limit exceeded + }), + expect.objectContaining({ + address: + 'neutron1m0z0kk0qqug74n9u9ul23e28x5fszr628h20xwt6jywjpp64xn4qatgvm0', + id: '4', + error: 'codespace: wasm, code: 5', // execute wasm contract failer + }), + expect.objectContaining({ + address: + 'neutron1m0z0kk0qqug74n9u9ul23e28x5fszr628h20xwt6jywjpp64xn4qatgvm0', + id: '5', + error: 'codespace: contractmanager, code: 1103', // contractmanager sudo limit exceeded + }), + ]), + ); const acks = await getAcks(neutronChain, contractAddress); // no acks at all because all sudo handling cases resulted in an error expect(acks).toEqual([]); }); + describe('get failure details via contractmanager failure-details query', () => { + test('ack failure during sudo', async () => { + expect(queryFailureDetails(contractAddress, 0)).toContain( + 'Generic error: Integrations test mock error: execute wasm contract failed', + ); + }); + test('ack failure during sudo submsg', async () => { + expect(queryFailureDetails(contractAddress, 1)).toContain( + 'dispatch: submessages: Generic error: Integrations test mock submsg error: execute wasm contract failed', + ); + }); + test('ack failure during sudo submsg reply', async () => { + expect(queryFailureDetails(contractAddress, 2)).toContain( + 'dispatch: submessages: reply: Generic error: Integrations test mock reply error: execute wasm contract failed', + ); + }); + test('ack failure during sudo out of gas', async () => { + expect(queryFailureDetails(contractAddress, 3)).toContain( + 'sudo handling went beyond the gas limit allowed by the module', + ); + }); + test('timeout failure during sudo', async () => { + expect(queryFailureDetails(contractAddress, 4)).toContain( + 'Generic error: Integrations test mock error: execute wasm contract failed', + ); + }); + test('out of gas failure during sudo timeout', async () => { + expect(queryFailureDetails(contractAddress, 5)).toContain( + 'sudo handling went beyond the gas limit allowed by the module', + ); + }); + }); + test('failed attempt to resubmit failure', async () => { // Mock sudo handler to fail await neutronAccount.executeContract( @@ -1074,3 +1116,8 @@ type AcksResponse = { port_id: string; sequence_id: number; }; + +const queryFailureDetails = (address: string, failureID: number) => + execSync( + `neutrond q contractmanager failure-details ${address} ${failureID}`, + ).toString();