Skip to content

Commit

Permalink
Merge pull request #337 from neutron-org/feat/unordered-ica
Browse files Browse the repository at this point in the history
feat: add possibility for unordered ica channels #ntrn-376
  • Loading branch information
pr0n00gler authored Sep 3, 2024
2 parents 35477b2 + e791bd3 commit bfa5f59
Show file tree
Hide file tree
Showing 21 changed files with 766 additions and 96 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"license": "Apache-2.0",
"dependencies": {
"@babel/plugin-transform-modules-commonjs": "^7.18.6",
"@confio/relayer": "^0.12.0",
"@cosmjs/cosmwasm-stargate": "^0.32.4",
"@cosmjs/stargate": "0.32.4",
"@cosmjs/tendermint-rpc": "^0.32.4",
Expand All @@ -55,6 +56,7 @@
"lodash": "^4.17.21",
"long": "^5.2.1",
"merkletreejs": "^0.3.9",
"sinon": "^18.0.0",
"yesno": "^0.4.0"
},
"devDependencies": {
Expand Down
12 changes: 8 additions & 4 deletions src/global_setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import ch from 'child_process';
import {
COSMOS_DENOM,
COSMOS_PREFIX,
GAIA_RPC,
NEUTRON_DENOM,
NEUTRON_PREFIX,
NEUTRON_RPC,
} from './helpers/constants';

import config from './config.json';
Expand All @@ -31,11 +33,9 @@ export default async function ({ provide }: GlobalSetupContext) {
mnemonics.push(generateMnemonic());
}

const rpcNeutron = process.env.NODE1_RPC || 'http://localhost:26657';
const rpcGaia = process.env.NODE2_RPC || 'http://localhost:16657';
// fund a lot or preallocated wallets for testing purposes
await fundWallets(mnemonics, rpcNeutron, NEUTRON_PREFIX, NEUTRON_DENOM);
await fundWallets(mnemonics, rpcGaia, COSMOS_PREFIX, COSMOS_DENOM);
await fundWallets(mnemonics, NEUTRON_RPC, NEUTRON_PREFIX, NEUTRON_DENOM);
await fundWallets(mnemonics, GAIA_RPC, COSMOS_PREFIX, COSMOS_DENOM);

provide('mnemonics', mnemonics);

Expand Down Expand Up @@ -118,3 +118,7 @@ declare module 'vitest' {
mnemonics: string[];
}
}

(BigInt.prototype as any).toJSON = function () {
return this.toString();
};
6 changes: 6 additions & 0 deletions src/helpers/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,9 @@ export const CONTRACTS = {

export const NEUTRON_PREFIX = process.env.NEUTRON_ADDRESS_PREFIX || 'neutron';
export const COSMOS_PREFIX = process.env.COSMOS_ADDRESS_PREFIX || 'cosmos';
export const NEUTRON_RPC = process.env.NODE1_RPC || 'http://localhost:26657';
export const GAIA_RPC = process.env.NODE2_RPC || 'http://localhost:16657';
export const NEUTRON_REST = process.env.NODE1_URL || 'http://localhost:1317';
export const GAIA_REST = process.env.NODE2_URL || 'http://localhost:1316';
export const IBC_WEB_HOST = process.env.ICQ_WEB_HOST || 'http://localhost:9999';
export const GAIA_CONNECTION = 'connection-0';
17 changes: 17 additions & 0 deletions src/helpers/interchaintxs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { SigningNeutronClient } from './signing_neutron_client';
import { JsonObject } from '@cosmjs/cosmwasm-stargate';
import { Link } from '@confio/relayer/build';
import { PacketWithMetadata } from '@confio/relayer/build/lib/endpoint';

export type AcknowledgementResult =
| { success: string[] }
Expand Down Expand Up @@ -56,3 +58,18 @@ export const getAcks = (
client.queryContractSmart(contractAddress, {
acknowledgement_results: {},
});

// relays given packet from A side, and it's acknowledgement
// note that it does not relay the timeout if it happens
export async function relayPacketFromA(link: Link, packet: PacketWithMetadata) {
await link.relayPackets('A', [packet]);
const [acksA, acksB] = await Promise.all([
link.getPendingAcks('A'),
link.getPendingAcks('B'),
]);
const [acksResA, acksResB] = await Promise.all([
link.relayAcks('A', acksA),
link.relayAcks('B', acksB),
]);
return { acksResA, acksResB };
}
66 changes: 56 additions & 10 deletions src/helpers/local_state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,21 @@ import {
QueryClient,
} from '@cosmjs/stargate';
import { DirectSecp256k1HdWallet } from '@cosmjs/proto-signing';
import { Suite } from 'vitest';
import { RunnerTestSuite } from 'vitest';
import { connectComet } from '@cosmjs/tendermint-rpc';
import { COSMOS_PREFIX, NEUTRON_PREFIX } from './constants';
import {
COSMOS_PREFIX,
GAIA_CONNECTION,
GAIA_REST,
GAIA_RPC,
IBC_WEB_HOST,
NEUTRON_PREFIX,
NEUTRON_REST,
NEUTRON_RPC,
} from './constants';
import { Wallet } from './wallet';
import { IbcClient, Link } from '@confio/relayer';
import { GasPrice } from '@cosmjs/stargate/build/fee';

// limit of wallets precreated for one test
const WALLETS_PER_TEST_FILE = 20;
Expand All @@ -35,7 +46,7 @@ export class LocalState {
static async create(
config: any,
mnemonics: string[],
suite?: Suite,
suite?: RunnerTestSuite,
): Promise<LocalState> {
const res = new LocalState(config, mnemonics, suite);
await res.init();
Expand All @@ -45,15 +56,15 @@ export class LocalState {
protected constructor(
private config: any,
private mnemonics: string[],
private suite?: Suite | undefined,
private suite?: RunnerTestSuite | undefined,
) {
this.rpcNeutron = process.env.NODE1_RPC || 'http://localhost:26657';
this.rpcGaia = process.env.NODE2_RPC || 'http://localhost:16657';
this.rpcNeutron = NEUTRON_RPC;
this.rpcGaia = GAIA_RPC;

this.restNeutron = process.env.NODE1_URL || 'http://localhost:1317';
this.restGaia = process.env.NODE2_URL || 'http://localhost:1316';
this.restNeutron = NEUTRON_REST;
this.restGaia = GAIA_REST;

this.icqWebHost = process.env.ICQ_WEB_HOST || 'http://localhost:9999';
this.icqWebHost = IBC_WEB_HOST;

this.walletIndexes = { neutron: 0, cosmos: 0 };
}
Expand Down Expand Up @@ -114,6 +125,41 @@ export class LocalState {
throw new Error('rpcClient() called non existent network: ' + network);
}
}

// Creates an IBC relayer between neutron and gaia
// This relayer can be used to manually relay packets
// since hermes don't have manual relay.
async relayerLink(): Promise<Link> {
const neutronWallet = await this.nextWallet('neutron');
const gaiaWallet = await this.nextWallet('cosmos');
const neutronIbcClient = await IbcClient.connectWithSigner(
this.rpcNeutron,
neutronWallet.directwallet,
neutronWallet.address,
{
gasPrice: GasPrice.fromString('0.05untrn'),
estimatedBlockTime: 3,
estimatedIndexerTime: 100,
},
);
const gaiaIbcClient = await IbcClient.connectWithSigner(
this.rpcGaia,
gaiaWallet.directwallet,
gaiaWallet.address,
{
gasPrice: GasPrice.fromString('0.05uatom'),
estimatedBlockTime: 3,
estimatedIndexerTime: 100,
},
);

return await Link.createWithExistingConnections(
neutronIbcClient,
gaiaIbcClient,
GAIA_CONNECTION,
GAIA_CONNECTION,
);
}
}

export const mnemonicToWallet = async (
Expand All @@ -134,7 +180,7 @@ export const mnemonicToWallet = async (
return new Wallet(addrPrefix, directwallet, account, accountValoper);
};

async function testFilePosition(s: Suite): Promise<number> {
async function testFilePosition(s: RunnerTestSuite): Promise<number> {
const filepath = s.file.filepath.trim();
const splitted = filepath.split('/');
const filename = splitted.pop().trim();
Expand Down
4 changes: 2 additions & 2 deletions src/testcases/parallel/dao_assert.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { inject, Suite } from 'vitest';
import { RunnerTestSuite, inject } from 'vitest';
import { getContractsHashes } from '../../helpers/setup';
import '@neutron-org/neutronjsplus';
import { LocalState } from '../../helpers/local_state';
Expand Down Expand Up @@ -32,7 +32,7 @@ describe('Neutron / DAO check', () => {
let feeburnerQuery: FeeburnerQueryClient;
let wasmQuery: WasmQueryClient;

beforeAll(async (suite: Suite) => {
beforeAll(async (suite: RunnerTestSuite) => {
testState = await LocalState.create(config, inject('mnemonics'), suite);

const neutronWallet = await testState.nextWallet('neutron');
Expand Down
4 changes: 2 additions & 2 deletions src/testcases/parallel/governance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
getNeutronDAOCore,
} from '@neutron-org/neutronjsplus/dist/dao';
import { updateInterchaintxsParamsProposal } from '@neutron-org/neutronjsplus/dist/proposal';
import { Suite, inject } from 'vitest';
import { RunnerTestSuite, inject } from 'vitest';
import { NEUTRON_DENOM } from '../../helpers/constants';
import { ParameterChangeProposal } from '@neutron-org/neutronjs/cosmos/params/v1beta1/params';
import { MsgSubmitProposalLegacy } from '@neutron-org/neutronjs/cosmos/adminmodule/adminmodule/tx';
Expand Down Expand Up @@ -48,7 +48,7 @@ describe('Neutron / Governance', () => {
let interchaintxQuery: InterchainTxQueryClient;
let interchainAccountsQuerier: InterchainAccountsQueryClient;

beforeAll(async (suite: Suite) => {
beforeAll(async (suite: RunnerTestSuite) => {
testState = await LocalState.create(config, inject('mnemonics'), suite);
neutronWallet = await testState.nextWallet('neutron');
neutronClient = await SigningNeutronClient.connectWithSigner(
Expand Down
4 changes: 2 additions & 2 deletions src/testcases/parallel/grpc_queries.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getEventAttribute } from '@neutron-org/neutronjsplus/dist/cosmos';
import { LocalState } from '../../helpers/local_state';
import { Wallet } from '../../helpers/wallet';
import { CONTRACTS } from '../../helpers/constants';
import { Suite, inject } from 'vitest';
import { RunnerTestSuite, inject } from 'vitest';
import { SigningNeutronClient } from '../../helpers/signing_neutron_client';
import { defaultRegistryTypes, SigningStargateClient } from '@cosmjs/stargate';
import { Registry } from '@cosmjs/proto-signing';
Expand All @@ -23,7 +23,7 @@ describe('Neutron / Grpc Queries', () => {

let newTokenDenom: string;

beforeAll(async (suite: Suite) => {
beforeAll(async (suite: RunnerTestSuite) => {
testState = await LocalState.create(config, inject('mnemonics'), suite);

neutronWallet = await testState.nextWallet('neutron');
Expand Down
4 changes: 2 additions & 2 deletions src/testcases/parallel/ibc_transfer.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Registry } from '@cosmjs/proto-signing';
import { Suite, inject } from 'vitest';
import { RunnerTestSuite, inject } from 'vitest';
import { LocalState } from '../../helpers/local_state';
import { SigningNeutronClient } from '../../helpers/signing_neutron_client';
import { MsgTransfer as GaiaMsgTransfer } from 'cosmjs-types/ibc/applications/transfer/v1/tx';
Expand Down Expand Up @@ -45,7 +45,7 @@ describe('Neutron / IBC transfer', () => {
let bankQuerier: BankQueryClient;
let ibcQuerier: IbcQueryClient;

beforeAll(async (suite: Suite) => {
beforeAll(async (suite: RunnerTestSuite) => {
testState = await LocalState.create(config, inject('mnemonics'), suite);

neutronWallet = await testState.nextWallet('neutron');
Expand Down
4 changes: 2 additions & 2 deletions src/testcases/parallel/interchain_tx_query_resubmit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
registerTransfersQuery,
waitForTransfersAmount,
} from '../../helpers/interchainqueries';
import { Suite, inject } from 'vitest';
import { RunnerTestSuite, inject } from 'vitest';
import { SigningNeutronClient } from '../../helpers/signing_neutron_client';
import {
CONTRACTS,
Expand All @@ -29,7 +29,7 @@ describe('Neutron / Interchain TX Query Resubmit', () => {
let contractAddress: string;
const connectionId = 'connection-0';

beforeAll(async (suite: Suite) => {
beforeAll(async (suite: RunnerTestSuite) => {
testState = await LocalState.create(config, inject('mnemonics'), suite);

neutronWallet = await testState.nextWallet('neutron');
Expand Down
4 changes: 2 additions & 2 deletions src/testcases/parallel/overrule.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import '@neutron-org/neutronjsplus';
import { NEUTRON_DENOM } from '@neutron-org/neutronjsplus/dist/constants';
import { LocalState } from '../../helpers/local_state';
import { Dao, DaoMember } from '@neutron-org/neutronjsplus/dist/dao';
import { Suite, inject } from 'vitest';
import { RunnerTestSuite, inject } from 'vitest';
import {
addSubdaoToDao,
deployNeutronDao,
Expand All @@ -25,7 +25,7 @@ describe('Neutron / Subdao Overrule', () => {
let neutronClient1: SigningNeutronClient;
let neutronClient2: SigningNeutronClient;

beforeAll(async (suite: Suite) => {
beforeAll(async (suite: RunnerTestSuite) => {
const mnemonics = inject('mnemonics');
testState = await LocalState.create(config, mnemonics, suite);
neutronWallet1 = await testState.nextWallet('neutron');
Expand Down
4 changes: 2 additions & 2 deletions src/testcases/parallel/subdao.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Suite, inject } from 'vitest';
import { RunnerTestSuite, inject } from 'vitest';
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import '@neutron-org/neutronjsplus';
import { createBankSendMessage } from '@neutron-org/neutronjsplus/dist/cosmos';
Expand Down Expand Up @@ -37,7 +37,7 @@ describe('Neutron / Subdao', () => {
let adminQuery: AdminQueryClient;
let chainManagerAddress;

beforeAll(async (suite: Suite) => {
beforeAll(async (suite: RunnerTestSuite) => {
testState = await LocalState.create(config, inject('mnemonics'), suite);
neutronWallet1 = await testState.nextWallet('neutron');
securityDaoWallet = await testState.nextWallet('neutron');
Expand Down
4 changes: 2 additions & 2 deletions src/testcases/parallel/voting_registry.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { LocalState } from '../../helpers/local_state';
import { Suite, inject } from 'vitest';
import { RunnerTestSuite, inject } from 'vitest';
import { waitBlocks } from '@neutron-org/neutronjsplus/dist/wait';
import { SigningNeutronClient } from '../../helpers/signing_neutron_client';
import { NEUTRON_DENOM } from '@neutron-org/neutronjsplus/dist/constants';
Expand Down Expand Up @@ -38,7 +38,7 @@ describe('Neutron / Voting Registry', () => {
// bonding to an additional vault
const vault3Bonding = 5_000_000;

beforeAll(async (suite: Suite) => {
beforeAll(async (suite: RunnerTestSuite) => {
const mnemonics = inject('mnemonics');
testState = await LocalState.create(config, mnemonics, suite);
neutronWallet = await testState.nextWallet('neutron');
Expand Down
4 changes: 2 additions & 2 deletions src/testcases/run_in_band/chain_manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
updateTokenfactoryParamsProposal,
} from '@neutron-org/neutronjsplus/dist/proposal';
import { LocalState } from '../../helpers/local_state';
import { Suite, inject } from 'vitest';
import { RunnerTestSuite, inject } from 'vitest';
import { NEUTRON_DENOM } from '@neutron-org/neutronjsplus/dist/constants';
import { setupSubDaoTimelockSet } from '../../helpers/dao';
import { QueryClientImpl as CronQueryClient } from '@neutron-org/neutronjs/neutron/cron/query.rpc.Query';
Expand All @@ -36,7 +36,7 @@ describe('Neutron / Chain Manager', () => {
let dexQuerier: DexQueryClient;
let chainManagerAddress: string;

beforeAll(async (suite: Suite) => {
beforeAll(async (suite: RunnerTestSuite) => {
testState = await LocalState.create(config, inject('mnemonics'), suite);
const neutronWallet = await testState.nextWallet('neutron');
neutronClient = await SigningNeutronClient.connectWithSigner(
Expand Down
4 changes: 2 additions & 2 deletions src/testcases/run_in_band/dex_grpc.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { inject, Suite } from 'vitest';
import { RunnerTestSuite, inject } from 'vitest';
import { LocalState } from '../../helpers/local_state';
import { NEUTRON_DENOM } from '@neutron-org/neutronjsplus/dist/constants';
import config from '../../config.json';
Expand All @@ -16,7 +16,7 @@ describe('Neutron / dex module (grpc contract)', () => {
let activeTrancheKey: string;
let inactiveTrancheKey: string;

beforeAll(async (suite: Suite) => {
beforeAll(async (suite: RunnerTestSuite) => {
testState = await LocalState.create(config, inject('mnemonics'), suite);
neutronWallet = testState.wallets.neutron.demo1;
neutronClient = await SigningNeutronClient.connectWithSigner(
Expand Down
4 changes: 2 additions & 2 deletions src/testcases/run_in_band/feemarket.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from '@neutron-org/neutronjsplus/dist/dao';
import { DynamicFeesParams } from '@neutron-org/neutronjsplus/dist/proposal';
import { LocalState } from '../../helpers/local_state';
import { Suite, inject } from 'vitest';
import { RunnerTestSuite, inject } from 'vitest';

import { QueryClientImpl as FeemarketQueryClient } from '@neutron-org/neutronjs/feemarket/feemarket/v1/query.rpc.Query';
import { QueryClientImpl as AdminQueryClient } from '@neutron-org/neutronjs/cosmos/adminmodule/adminmodule/query.rpc.Query';
Expand All @@ -27,7 +27,7 @@ describe('Neutron / Fee Market', () => {
let feemarketQuerier: FeemarketQueryClient;
let chainManagerAddress: string;

beforeAll(async (suite: Suite) => {
beforeAll(async (suite: RunnerTestSuite) => {
testState = await LocalState.create(config, inject('mnemonics'), suite);
const neutronRpcClient = await testState.neutronRpcClient();

Expand Down
4 changes: 2 additions & 2 deletions src/testcases/run_in_band/ibc_hooks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
NEUTRON_DENOM,
} from '../../helpers/constants';
import { LocalState } from '../../helpers/local_state';
import { inject, Suite } from 'vitest';
import { RunnerTestSuite, inject } from 'vitest';
import { SigningNeutronClient } from '../../helpers/signing_neutron_client';
import { defaultRegistryTypes, SigningStargateClient } from '@cosmjs/stargate';
import { Registry } from '@cosmjs/proto-signing';
Expand All @@ -26,7 +26,7 @@ describe('Neutron / IBC hooks', () => {
const transferDenom =
'ibc/4E41ED8F3DCAEA15F4D6ADC6EDD7C04A676160735C9710B904B7BF53525B56D6';

beforeAll(async (suite: Suite) => {
beforeAll(async (suite: RunnerTestSuite) => {
testState = await LocalState.create(config, inject('mnemonics'), suite);

neutronWallet = await testState.nextWallet('neutron');
Expand Down
Loading

0 comments on commit bfa5f59

Please sign in to comment.