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: update transaction filter tests #38

Merged
merged 3 commits into from
Nov 19, 2022
Merged
Changes from 1 commit
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
64 changes: 60 additions & 4 deletions src/testcases/interchain_tx_query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
queryTransfersNumber,
waitForTransfersAmount,
} from '../helpers/icq';
import { max } from 'lodash';
import { CosmosSDK } from '@cosmos-client/core/cjs/sdk';

describe('Neutron / Interchain TX Query', () => {
Expand Down Expand Up @@ -62,7 +61,7 @@ describe('Neutron / Interchain TX Query', () => {
const amountToAddr2_1 = 5000;
const watchedAddr1: string = addr1;
const query1UpdatePeriod = 4;
describe('utilise single transfers query', () => {
describe('utilize single transfers query', () => {
test('register transfers query', async () => {
// Top up contract address before running query
await cm.msgSend(contractAddress, '1000000');
Expand Down Expand Up @@ -184,7 +183,7 @@ describe('Neutron / Interchain TX Query', () => {

const watchedAddr2 = addr2;
const query2UpdatePeriod = 3;
describe('utilise multiple transfers queries', () => {
describe('utilize multiple transfers queries', () => {
test('register the second transfers query', async () => {
// Top up contract address before running query
await cm.msgSend(contractAddress, '1000000');
Expand Down Expand Up @@ -400,7 +399,7 @@ describe('Neutron / Interchain TX Query', () => {
cm,
contractAddress,
expectedIncomingTransfers,
max([query1UpdatePeriod, query2UpdatePeriod]) * 2,
Math.max(...[query1UpdatePeriod, query2UpdatePeriod]) * 2,
);
let deposits = await queryRecipientTxs(cm, contractAddress, watchedAddr1);
expect(deposits.transfers).toEqual([
Expand Down Expand Up @@ -631,6 +630,63 @@ describe('Neutron / Interchain TX Query', () => {
);
});
});

describe('update recipient and check', () => {
const newWatchedAddr5 = 'cosmos1jy7lsk5pk38zjfnn6nt6qlaphy9uejn4hu65xa';
it('should update recipient', async () => {
const res = await cm.executeContract(
contractAddress,
JSON.stringify({
update_interchain_query: {
query_id: 3,
new_update_period: 5,
sotnikov-s marked this conversation as resolved.
Show resolved Hide resolved
new_recipient: newWatchedAddr5,
},
}),
);
expect(res.code).toEqual(0);
});
it('seems registered transfers query is updated', async () => {
await waitBlocks(cm.sdk, 10);
sotnikov-s marked this conversation as resolved.
Show resolved Hide resolved
const query = await getRegisteredQuery(cm, contractAddress, 3);
expect(query.registered_query.id).toEqual(3);
expect(query.registered_query.owner).toEqual(contractAddress);
expect(query.registered_query.keys.length).toEqual(0);
expect(query.registered_query.query_type).toEqual('tx');
expect(query.registered_query.update_period).toEqual(5);
expect(query.registered_query.transactions_filter).toEqual(
'[{"field":"transfer.recipient","op":"Eq","value":"' +
newWatchedAddr5 +
'"}]',
);
expect(query.registered_query.connection_id).toEqual(connectionId);
});

it('should handle callback on a sending to the new address', async () => {
const res = await cm2.msgSend(newWatchedAddr5, '10000');
expect(res.code).toEqual(0);
expectedIncomingTransfers++;
await waitForTransfersAmount(
cm,
contractAddress,
expectedIncomingTransfers,
query1UpdatePeriod * 5,
sotnikov-s marked this conversation as resolved.
Show resolved Hide resolved
);
const deposits = await queryRecipientTxs(
cm,
contractAddress,
newWatchedAddr5,
);
expect(deposits.transfers).toEqual([
{
recipient: watchedAddr1,
sender: cm2.wallet.address.toString(),
denom: cm2.denom,
amount: addr1ExpectedBalance.toString(),
sotnikov-s marked this conversation as resolved.
Show resolved Hide resolved
},
]);
});
});
});

/**
Expand Down