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: icatx refactor #204

Merged
merged 1 commit into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 1 addition & 20 deletions src/helpers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,26 +80,7 @@ export type AckFailuresResponse = {
type Failure = {
address: string;
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;
};
sudo_payload: string; // base64 encoded json bytes
};

export type ScheduleResponse = {
Expand Down
37 changes: 33 additions & 4 deletions src/testcases/parallel/simple.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -526,25 +526,54 @@ describe('Neutron / Simple', () => {
expect.objectContaining({
address: contractAddress,
id: '0',
ack_type: 'ack',
}),
expect.objectContaining({
address: contractAddress,
id: '1',
ack_type: 'ack',
}),
expect.objectContaining({
address: contractAddress,
id: '2',
ack_type: 'timeout',
}),
expect.objectContaining({
address: contractAddress,
id: '3',
ack_type: 'timeout',
}),
]);

expect(
JSON.parse(
Buffer.from(
failuresAfterCall.failures[0].sudo_payload,
'base64',
).toString(),
),
).toHaveProperty('response');
expect(
JSON.parse(
Buffer.from(
failuresAfterCall.failures[1].sudo_payload,
'base64',
).toString(),
),
).toHaveProperty('response');
expect(
JSON.parse(
Buffer.from(
failuresAfterCall.failures[2].sudo_payload,
'base64',
).toString(),
),
).toHaveProperty('timeout');
expect(
JSON.parse(
Buffer.from(
failuresAfterCall.failures[3].sudo_payload,
'base64',
).toString(),
),
).toHaveProperty('timeout');

// Restore sudo handler to state
await neutronAccount.executeContract(
contractAddress,
Expand Down
57 changes: 19 additions & 38 deletions src/testcases/run_in_band/interchaintx.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ describe('Neutron / Interchain TXs', () => {
});
});
describe('Create ICAs and setup contract', () => {
test('fund contract to pay fees', async () => {
const res = await neutronAccount.msgSend(contractAddress, '100000');
expect(res.code).toEqual(0);
});
test('create ICA1', async () => {
const res = await neutronAccount.executeContract(
contractAddress,
Expand All @@ -98,6 +102,13 @@ describe('Neutron / Interchain TXs', () => {
);
expect(res.code).toEqual(0);
});
test('check contract balance', async () => {
const res = await neutronChain.queryBalances(contractAddress);
const balance = res.balances.find(
(b) => b.denom === neutronChain.denom,
)?.amount;
expect(balance).toEqual('98000');
});
test('multiple IBC accounts created', async () => {
const channels = await getWithAttempts(
neutronChain.blockWaiter,
Expand Down Expand Up @@ -157,10 +168,7 @@ describe('Neutron / Interchain TXs', () => {
);
expect(res.code).toEqual(0);
});
test('fund contract to pay fees', async () => {
const res = await neutronAccount.msgSend(contractAddress, '100000');
expect(res.code).toEqual(0);
});

test('add some money to ICAs', async () => {
const res1 = await gaiaAccount.msgSend(icaAddress1.toString(), '10000');
expect(res1.code).toEqual(0);
Expand Down Expand Up @@ -230,7 +238,7 @@ describe('Neutron / Interchain TXs', () => {
const balance = res.balances.find(
(b) => b.denom === neutronChain.denom,
)?.amount;
expect(balance).toEqual('98000');
expect(balance).toEqual('96000');
});
});

Expand Down Expand Up @@ -304,7 +312,7 @@ describe('Neutron / Interchain TXs', () => {
(b) => b.denom === neutronChain.denom,
)?.amount;
// two interchain txs inside (2000 * 2 = 4000)
expect(balance).toEqual('94000');
expect(balance).toEqual('92000');
});
});

Expand Down Expand Up @@ -881,67 +889,37 @@ describe('Neutron / Interchain TXs', () => {

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
// 4 ack failures, 2 timeout failure, just as described in the tests above
expect(failures.failures).toEqual([
expect.objectContaining({
address:
'neutron1m0z0kk0qqug74n9u9ul23e28x5fszr628h20xwt6jywjpp64xn4qatgvm0',
id: '0',
packet: expect.objectContaining({
source_channel: 'channel-3',
sequence: '2',
}),
ack_type: 'ack',
}),
expect.objectContaining({
address:
'neutron1m0z0kk0qqug74n9u9ul23e28x5fszr628h20xwt6jywjpp64xn4qatgvm0',
id: '1',
packet: expect.objectContaining({
source_channel: 'channel-3',
sequence: '3',
}),
ack_type: 'ack',
}),
expect.objectContaining({
address:
'neutron1m0z0kk0qqug74n9u9ul23e28x5fszr628h20xwt6jywjpp64xn4qatgvm0',
id: '2',
packet: expect.objectContaining({
source_channel: 'channel-3',
sequence: '4',
}),
ack_type: 'ack',
}),
expect.objectContaining({
address:
'neutron1m0z0kk0qqug74n9u9ul23e28x5fszr628h20xwt6jywjpp64xn4qatgvm0',
id: '3',
packet: expect.objectContaining({
source_channel: 'channel-3',
sequence: '5',
}),
ack_type: 'ack',
}),
expect.objectContaining({
address:
'neutron1m0z0kk0qqug74n9u9ul23e28x5fszr628h20xwt6jywjpp64xn4qatgvm0',
id: '4',
packet: expect.objectContaining({
source_channel: 'channel-3',
sequence: '6',
}),
ack_type: 'timeout',
}),
expect.objectContaining({
address:
'neutron1m0z0kk0qqug74n9u9ul23e28x5fszr628h20xwt6jywjpp64xn4qatgvm0',
id: '5',
packet: expect.objectContaining({
source_channel: 'channel-2',
sequence: '3',
}),
ack_type: 'timeout',
}),
]);

Expand Down Expand Up @@ -1028,7 +1006,10 @@ describe('Neutron / Interchain TXs', () => {
// 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);
expect(acks[0].sequence_id).toEqual(
+JSON.parse(Buffer.from(failure.sudo_payload, 'base64').toString())
.response.request.sequence,
);
});
});
});
Expand Down