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: icq MaxKvQueryKeysCount and MaxTransactionsFilters gov gated #NTRN-364 #332

Merged
merged 10 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
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
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
"@cosmjs/cosmwasm-stargate": "^0.32.4",
"@cosmjs/stargate": "0.32.4",
"@cosmjs/tendermint-rpc": "^0.32.4",
"@neutron-org/neutronjs": "0.1.0-rc4",
"@neutron-org/neutronjsplus": "https://github.com/neutron-org/neutronjsplus.git#6c4fb9db879d7cf29074ddc9fafc0d06f77acb7b",
"@neutron-org/neutronjs": "0.1.0-rc5",
"@neutron-org/neutronjsplus": "https://github.com/neutron-org/neutronjsplus.git#cf53a61bd7d4aa1e9204c41b2c2ea36cb024ae7d",
"@types/lodash": "^4.14.182",
"axios": "1.6.0",
"commander": "^10.0.0",
Expand Down Expand Up @@ -85,4 +85,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
Loading