Skip to content

Commit

Permalink
Merge pull request #178 from neutron-org/test-double-ack
Browse files Browse the repository at this point in the history
test double ack
  • Loading branch information
pr0n00gler authored Aug 4, 2023
2 parents 4c2c82e + a0219ce commit 1e5afd7
Showing 1 changed file with 77 additions and 2 deletions.
79 changes: 77 additions & 2 deletions src/testcases/run_in_band/interchaintx.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ describe('Neutron / Interchain TXs', () => {
validator: (
testState.wallets.cosmos.val1.address as cosmosclient.ValAddress
).toString(),
amount: '2000',
amount: '1000',
denom: gaiaChain.denom,
},
}),
Expand Down Expand Up @@ -208,6 +208,79 @@ describe('Neutron / Interchain TXs', () => {
async (delegations) =>
delegations.data.delegation_responses?.length == 1,
);
expect(res1.data.delegation_responses).toEqual([
{
balance: { amount: '1000', denom: gaiaChain.denom },
delegation: {
delegator_address: icaAddress1,
shares: '1000.000000000000000000',
validator_address:
'cosmosvaloper18hl5c9xn5dze2g50uaw0l2mr02ew57zk0auktn',
},
},
]);
const res2 = await rest.staking.delegatorDelegations(
gaiaChain.sdk as CosmosSDK,
icaAddress2 as unknown as AccAddress,
);
expect(res2.data.delegation_responses).toEqual([]);
});
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');
});
});

describe('DOUBLE ACK - Send Interchain TX', () => {
test('delegate from first ICA', async () => {
// it will delegate two times of passed amount - first from contract call, and second from successful sudo IBC response
const res = await neutronAccount.executeContract(
contractAddress,
JSON.stringify({
delegate_double_ack: {
interchain_account_id: icaId1,
validator: (
testState.wallets.cosmos.val1.address as cosmosclient.ValAddress
).toString(),
amount: '500',
denom: gaiaChain.denom,
},
}),
);
expect(res.code).toEqual(0);
const sequenceId = getSequenceId(res.raw_log);

await waitForAck(neutronChain, contractAddress, icaId1, sequenceId);
const qres = await getAck(
neutronChain,
contractAddress,
icaId1,
sequenceId,
);
expect(qres).toMatchObject<AcknowledgementResult>({
success: ['/cosmos.staking.v1beta1.MsgDelegate'],
});

const ackSequenceId = sequenceId + 1;
await waitForAck(neutronChain, contractAddress, icaId1, ackSequenceId);
expect(qres).toMatchObject<AcknowledgementResult>({
success: ['/cosmos.staking.v1beta1.MsgDelegate'],
});
});
test('check validator state', async () => {
const res1 = await getWithAttempts(
gaiaChain.blockWaiter,
() =>
rest.staking.delegatorDelegations(
gaiaChain.sdk as CosmosSDK,
icaAddress1 as unknown as AccAddress,
),
async (delegations) =>
delegations.data.delegation_responses?.length === 1,
);
expect(res1.data.delegation_responses).toEqual([
{
balance: { amount: '2000', denom: gaiaChain.denom },
Expand All @@ -230,9 +303,11 @@ describe('Neutron / Interchain TXs', () => {
const balance = res.balances.find(
(b) => b.denom === neutronChain.denom,
)?.amount;
expect(balance).toEqual('98000');
// two interchain txs inside (2000 * 2 = 4000)
expect(balance).toEqual('94000');
});
});

describe('Error cases', () => {
test('delegate for unknown validator from second ICA', async () => {
const res = await neutronAccount.executeContract(
Expand Down

0 comments on commit 1e5afd7

Please sign in to comment.