Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: contract manager resubmit #ntrn-84 #190

Merged
merged 11 commits into from
Aug 29, 2023
22 changes: 20 additions & 2 deletions src/helpers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,27 @@ export type AckFailuresResponse = {
// Failure represents a single contractmanager failure
type Failure = {
address: string;
id: number;
ack_id: number;
id: string;
ack: {
response: {
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 = {
Expand Down
119 changes: 116 additions & 3 deletions src/testcases/parallel/simple.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -470,7 +470,9 @@ describe('Neutron / Simple', () => {
await neutronAccount.executeContract(
contractAddress,
JSON.stringify({
integration_tests_set_sudo_failure_mock: {},
integration_tests_set_sudo_failure_mock: {
state: 'enabled',
},
}),
);

Expand Down Expand Up @@ -516,7 +518,7 @@ describe('Neutron / Simple', () => {
const failuresAfterCall = await getWithAttempts<AckFailuresResponse>(
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,
);

Expand Down Expand Up @@ -551,7 +553,118 @@ describe('Neutron / Simple', () => {
}),
);
});

// 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<AckFailuresResponse>(
// 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
await neutronAccount.executeContract(
contractAddress,
JSON.stringify({
integration_tests_set_sudo_failure_mock: {
state: 'enabled',
},
}),
);

await neutronChain.blockWaiter.waitBlocks(2);

// Try to resubmit failure
const failuresResBefore = await neutronChain.queryAckFailures(
contractAddress,
);

await expect(
neutronAccount.executeContract(
contractAddress,
JSON.stringify({
resubmit_failure: {
failure_id: +failuresResBefore.failures[0].id,
},
}),
),
).rejects.toThrowError();

await neutronChain.blockWaiter.waitBlocks(5);

// check that failures count is the same
const failuresResAfter = await neutronChain.queryAckFailures(
contractAddress,
);
expect(failuresResAfter.failures.length).toEqual(4);

// Restore sudo handler's normal state
await neutronAccount.executeContract(
contractAddress,
JSON.stringify({
integration_tests_unset_sudo_failure_mock: {},
}),
);
await neutronChain.blockWaiter.waitBlocks(5);
});

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);

await neutronChain.blockWaiter.waitBlocks(5);

// check that failures count is changed
const failuresResAfter = await neutronChain.queryAckFailures(
contractAddress,
);
expect(failuresResAfter.failures.length).toEqual(3);
});
});

describe('Failures limit test', () => {
test("failures with small limit doesn't return an error", async () => {
const pagination: PageRequest = {
Expand Down
Loading