Skip to content

Commit

Permalink
Merge pull request #332 from neutron-org/feat/icq-params-gov-gated
Browse files Browse the repository at this point in the history
feat: icq MaxKvQueryKeysCount and MaxTransactionsFilters gov gated #NTRN-364
  • Loading branch information
pr0n00gler authored Sep 2, 2024
2 parents 37d28b5 + c67fcba commit 35477b2
Show file tree
Hide file tree
Showing 8 changed files with 259 additions and 27 deletions.
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
"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",
Expand All @@ -41,8 +43,8 @@
"@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/neutronjsplus": "https://github.com/neutron-org/neutronjsplus.git#88b4e5391a8b80c90a7c7e25b8f6948b7cdd2e7c",
"@neutron-org/neutronjs": "https://github.com/neutron-org/neutronjs.git#f5334307decfa549283d03e626cd45582667c13f",
"@neutron-org/neutronjsplus": "https://github.com/neutron-org/neutronjsplus.git#1e4527ef6971f4dc2c202cb3cc2a50b0a4491f54",
"@types/lodash": "^4.14.182",
"axios": "1.6.0",
"commander": "^10.0.0",
Expand Down Expand Up @@ -85,4 +87,4 @@
"engines": {
"node": ">=20.0"
}
}
}
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
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
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ describe('Neutron / Interchain TX Query Resubmit', () => {
contractAddress,
connectionId,
query1UpdatePeriod,
watchedAddr1,
[watchedAddr1],
);
});

Expand Down
103 changes: 98 additions & 5 deletions src/testcases/run_in_band/interchain_kv_query.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import {
acceptInterchainqueriesParamsChangeProposal,
executeUpdateInterchainQueriesParams,
filterIBCDenoms,
} from '../../helpers/interchainqueries';
import '@neutron-org/neutronjsplus';
import { QueryClientImpl as AdminQueryClient } from '@neutron-org/neutronjs/cosmos/adminmodule/adminmodule/query.rpc.Query';
import { getEventAttribute } from '@neutron-org/neutronjsplus/dist/cosmos';
import { inject } from 'vitest';
import {
Expand Down Expand Up @@ -66,6 +68,7 @@ describe('Neutron / Interchain KV Query', () => {
3: 4,
4: 3,
5: 4,
6: 11,
};
let testState: LocalState;
let neutronClient: SigningNeutronClient;
Expand All @@ -80,6 +83,9 @@ describe('Neutron / Interchain KV Query', () => {
let bankQuerierGaia: BankQuerier;
let slashingQuerier: SlashingQuerier;
let contractAddress: string;
let daoMember: DaoMember;
let mainDao: Dao;
let chainManagerAddress: string;

beforeAll(async () => {
testState = await LocalState.create(config, inject('mnemonics'));
Expand Down Expand Up @@ -114,9 +120,9 @@ describe('Neutron / Interchain KV Query', () => {
neutronRpcClient,
);
const daoContracts = await getDaoContracts(neutronClient, daoCoreAddress);
const dao = new Dao(neutronClient, daoContracts);
const daoMember = new DaoMember(
dao,
mainDao = new Dao(neutronClient, daoContracts);
daoMember = new DaoMember(
mainDao,
neutronClient.client,
neutronWallet.address,
NEUTRON_DENOM,
Expand All @@ -126,6 +132,10 @@ describe('Neutron / Interchain KV Query', () => {
bankQuerier = new BankQuerier(neutronRpcClient);
bankQuerierGaia = new BankQuerier(await testState.gaiaRpcClient());
slashingQuerier = new SlashingQuerier(await testState.gaiaRpcClient());

const adminQuery = new AdminQueryClient(neutronRpcClient);
const admins = await adminQuery.admins();
chainManagerAddress = admins.admins[0];
});

describe('Instantiate interchain queries contract', () => {
Expand Down Expand Up @@ -223,6 +233,45 @@ describe('Neutron / Interchain KV Query', () => {

expect(balances.balances.length).toEqual(0);
});

test('should throw exception because of too many keys', async () => {
await neutronClient.sendTokens(
contractAddress,
[{ denom: NEUTRON_DENOM, amount: '1000000' }],
{
gas: '200000',
amount: [{ denom: NEUTRON_DENOM, amount: '1000' }],
},
);
await expect(
neutronClient.execute(contractAddress, {
register_balances_query: {
connection_id: connectionId,
denoms: Array.from(Array(33).keys()).map((v) => 'denom' + v),
addr: gaiaWallet.address,
update_period: 10,
},
}),
).rejects.toThrowError(/keys count cannot be more than 32/);
await executeUpdateInterchainQueriesParams(
chainManagerAddress,
interchainqQuerier,
mainDao,
daoMember,
10,
undefined,
);
await expect(
neutronClient.execute(contractAddress, {
register_balances_query: {
connection_id: connectionId,
denoms: Array.from(Array(11).keys()).map((v) => 'denom' + v),
addr: gaiaWallet.address,
update_period: 10,
},
}),
).rejects.toThrowError(/keys count cannot be more than 10/);
});
});

describe('Successfully', () => {
Expand Down Expand Up @@ -281,6 +330,25 @@ describe('Neutron / Interchain KV Query', () => {
testState.wallets.cosmos.val1.address,
);
});

test('register icq #6: 100 keys', async () => {
await executeUpdateInterchainQueriesParams(
chainManagerAddress,
interchainqQuerier,
mainDao,
daoMember,
100,
undefined,
);
await registerBalancesQuery(
neutronClient,
contractAddress,
connectionId,
updatePeriods[6],
Array.from(Array(100).keys()).map((v) => 'denom' + v),
testState.wallets.cosmos.val1.address,
);
});
});
});

Expand Down Expand Up @@ -367,8 +435,33 @@ describe('Neutron / Interchain KV Query', () => {
);
});

test("registered icq #6 doesn't exist", async () => {
test('get registered icq #6: 100 keys', async () => {
const queryId = 6;
const queryResult = await getRegisteredQuery(
neutronClient,
contractAddress,
queryId,
);
expect(queryResult.registered_query.id).toEqual(queryId);
expect(queryResult.registered_query.owner).toEqual(contractAddress);
expect(queryResult.registered_query.keys.length).toEqual(100);
for (let i = 0; i < queryResult.registered_query.keys.length; i++) {
expect(queryResult.registered_query.keys[i].path).toEqual('bank');
expect(queryResult.registered_query.keys[i].key.length).toBeGreaterThan(
0,
);
}

expect(queryResult.registered_query.query_type).toEqual('kv');
expect(queryResult.registered_query.transactions_filter).toEqual('');
expect(queryResult.registered_query.connection_id).toEqual(connectionId);
expect(queryResult.registered_query.update_period).toEqual(
updatePeriods[queryId],
);
});

test("registered icq #7 doesn't exist", async () => {
const queryId = 7;
await expect(
getRegisteredQuery(neutronClient, contractAddress, queryId),
).rejects.toThrow();
Expand Down Expand Up @@ -575,7 +668,7 @@ describe('Neutron / Interchain KV Query', () => {
address: contractAddress,
});

expect(balances.balances[0].amount).toEqual('1000000');
expect(balances.balances[0].amount).toEqual('2000000');
});

test('should fail to remove icq #2 from non owner address before timeout expiration', async () => {
Expand Down
Loading

0 comments on commit 35477b2

Please sign in to comment.