Skip to content

Commit

Permalink
Merge branch 'main' into feat/add-cron-integration-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joldie777 committed Sep 5, 2024
2 parents 754bead + 9a4e55e commit 8b93b8a
Show file tree
Hide file tree
Showing 26 changed files with 1,325 additions and 349 deletions.
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,19 @@
"test:feemarket": "NO_WAIT_CHANNEL1=1 NO_WAIT_HTTP2=1 NO_WAIT_CHANNEL2=1 NO_WAIT_DELAY=1 vitest --run src/testcases/run_in_band/feemarket --bail 1",
"lint": "eslint ./src",
"fmt": "eslint ./src --fix",
"postinstall": "[ -d './node_modules/@neutron-org/neutronjsplus/dist' ] || tsc -p ./node_modules/@neutron-org/neutronjsplus/tsconfig.json"
"build:neutronjsplus": "[ -d './node_modules/@neutron-org/neutronjsplus/dist' ] || tsc -p ./node_modules/@neutron-org/neutronjsplus/tsconfig.json",
"build:neutronjs": "[ -d './node_modules/@neutron-org/neutronjs/dist' ] || { tsc -p ./node_modules/@neutron-org/neutronjs/tsconfig.json && cp -R ./node_modules/@neutron-org/neutronjs/build/* ./node_modules/@neutron-org/neutronjs/ ; }",
"postinstall": "yarn build:neutronjs && yarn build:neutronjsplus"
},
"author": "Neutron",
"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",
"@neutron-org/neutronjs": "4.2.0",
"@neutron-org/neutronjs": "https://github.com/neutron-org/neutronjs.git#1e70c1f68e997857f42bab7647227c8ca9dc8aa1",
"@neutron-org/neutronjsplus": "https://github.com/neutron-org/neutronjsplus.git#90419a2508b4a62e646c9449c983a4640643ad83",
"@types/lodash": "^4.14.182",
"axios": "1.6.0",
Expand All @@ -54,6 +57,7 @@
"lodash": "^4.17.21",
"long": "^5.2.1",
"merkletreejs": "^0.3.9",
"sinon": "^18.0.0",
"yesno": "^0.4.0"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion setup/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
APP_DIR ?= ../..
COMPOSE ?= docker-compose
COMPOSE ?= docker compose

build-gaia:
@docker buildx build --load --build-context app=$(APP_DIR)/gaia --build-context setup=$(APP_DIR)/neutron/network -t gaia-node -f dockerbuilds/Dockerfile.gaia --build-arg BINARY=gaiad .
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 @@ -79,3 +79,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';
45 changes: 43 additions & 2 deletions src/helpers/interchainqueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
getNeutronDAOCore,
} from '@neutron-org/neutronjsplus/dist/dao';
import { QueryClientImpl as AdminQueryClient } from '@neutron-org/neutronjs/cosmos/adminmodule/adminmodule/query.rpc.Query';
import { QueryClientImpl as InterchainqQuerier } from '@neutron-org/neutronjs/neutron/interchainqueries/query.rpc.Query';
import { paramChangeProposal } from '@neutron-org/neutronjsplus/dist/proposal';
import {
CosmWasmClient,
Expand All @@ -21,6 +22,46 @@ import { Coin } from '@neutron-org/neutronjs/cosmos/base/v1beta1/coin';
import { QueryClientImpl as BankQuerier } from 'cosmjs-types/cosmos/bank/v1beta1/query';
import { MsgRemoveInterchainQueryRequest } from '@neutron-org/neutronjs/neutron/interchainqueries/tx';

export const executeUpdateInterchainQueriesParams = async (
chainManagerAddress: string,
interchainQueriesQuerier: InterchainqQuerier,
mainDao: Dao,
daoMember: DaoMember,
maxKvQueryKeysCount?: number,
maxTransactionsFilters?: number,
) => {
const params = (await interchainQueriesQuerier.params()).params;
if (maxKvQueryKeysCount != undefined) {
params.maxKvQueryKeysCount = BigInt(maxKvQueryKeysCount);
}

if (maxTransactionsFilters != undefined) {
params.maxTransactionsFilters = BigInt(maxTransactionsFilters);
}

const proposalId =
await daoMember.submitUpdateParamsInterchainqueriesProposal(
chainManagerAddress,
'Change Proposal - InterchainQueriesParams',
'Param change proposal. It will change enabled params of interchainquries module.',
{
query_submit_timeout: Number(params.querySubmitTimeout),
query_deposit: params.queryDeposit,
tx_query_removal_limit: Number(params.txQueryRemovalLimit),
max_kv_query_keys_count: Number(params.maxKvQueryKeysCount),
max_transactions_filters: Number(params.maxTransactionsFilters),
},
'1000',
);

await daoMember.voteYes(proposalId, 'single', {
gas: '4000000',
amount: [{ denom: NEUTRON_DENOM, amount: '100000' }],
});
await mainDao.checkPassedProposal(proposalId);
await daoMember.executeProposalWithAttempts(proposalId);
};

export const getKvCallbackStatus = async (
client: SigningNeutronClient,
contractAddress: string,
Expand Down Expand Up @@ -594,13 +635,13 @@ export const registerTransfersQuery = async (
contractAddress: string,
connectionId: string,
updatePeriod: number,
recipient: string,
recipients: string[],
) => {
const res = await client.execute(contractAddress, {
register_transfers_query: {
connection_id: connectionId,
update_period: updatePeriod,
recipient: recipient,
recipients: recipients,
},
});

Expand Down
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
6 changes: 3 additions & 3 deletions src/testcases/parallel/grpc_queries.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ 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';
import { MsgTransfer } from 'cosmjs-types/ibc/applications/transfer/v1/tx';
import { MsgTransfer } from '@neutron-org/neutronjs/ibc/applications/transfer/v1/tx';
import { MsgCreateDenom } from '@neutron-org/neutronjs/osmosis/tokenfactory/v1beta1/tx';
import { COSMOS_DENOM, NEUTRON_DENOM } from '../../helpers/constants';
import config from '../../config.json';
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
Loading

0 comments on commit 8b93b8a

Please sign in to comment.