From 10b18690ad8b9b5301ec15c6bb4db28e6eae797d Mon Sep 17 00:00:00 2001 From: quasisamurai Date: Thu, 26 Sep 2024 12:42:36 -0300 Subject: [PATCH] lint & more explicit namings & small ref --- package.json | 2 +- src/helpers/constants.ts | 2 +- ...e_limit.test.ts => ibc_rate_limit.test.ts} | 34 +++++++++++-------- 3 files changed, 21 insertions(+), 17 deletions(-) rename src/testcases/run_in_band/{rate_limit.test.ts => ibc_rate_limit.test.ts} (96%) diff --git a/package.json b/package.json index 19b4ea6c..48ecbe49 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "test:dex_bindings": "NO_WAIT_CHANNEL1=1 NO_WAIT_HTTP2=1 NO_WAIT_CHANNEL2=1 NO_WAIT_DELAY=1 vitest --run src/testcases/run_in_band/dex_bindings --bail 1", "test:chain_manager": "vitest --run src/testcases/run_in_band/chain_manager --bail 1", "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", - "test:rate_limit": "vitest --run src/testcases/run_in_band/rate_limit --bail 1", + "test:ibc_rate_limit": "vitest --run src/testcases/run_in_band/ibc_rate_limit --bail 1", "lint": "eslint ./src", "fmt": "eslint ./src --fix", "build:neutronjsplus": "[ -d './node_modules/@neutron-org/neutronjsplus/dist' ] || tsc -p ./node_modules/@neutron-org/neutronjsplus/tsconfig.json", diff --git a/src/helpers/constants.ts b/src/helpers/constants.ts index 0cc1972e..d0e64649 100644 --- a/src/helpers/constants.ts +++ b/src/helpers/constants.ts @@ -74,7 +74,7 @@ export const CONTRACTS = { LOCKDROP_VAULT_CL: 'lockdrop_vault_for_cl_pools.wasm', MARKETMAP: 'marketmap.wasm', ORACLE: 'oracle.wasm', - RATE_LIMITER: 'rate_limiter.wasm', + IBC_RATE_LIMITER: 'rate_limiter.wasm', }; export const NEUTRON_PREFIX = process.env.NEUTRON_ADDRESS_PREFIX || 'neutron'; diff --git a/src/testcases/run_in_band/rate_limit.test.ts b/src/testcases/run_in_band/ibc_rate_limit.test.ts similarity index 96% rename from src/testcases/run_in_band/rate_limit.test.ts rename to src/testcases/run_in_band/ibc_rate_limit.test.ts index 2b327051..1694ca30 100644 --- a/src/testcases/run_in_band/rate_limit.test.ts +++ b/src/testcases/run_in_band/ibc_rate_limit.test.ts @@ -56,6 +56,8 @@ describe('Neutron / IBC transfer', () => { let neutronQuerier: NeutronQuerier; let ibcQuerier: IbcQueryClient; + let amount: string; + beforeAll(async (suite: RunnerTestSuite) => { testState = await LocalState.create(config, inject('mnemonics'), suite); @@ -112,7 +114,7 @@ describe('Neutron / IBC transfer', () => { 1, 1, ); - rlContract = await neutronClient.create(CONTRACTS.RATE_LIMITER, { + rlContract = await neutronClient.create(CONTRACTS.IBC_RATE_LIMITER, { gov_module: neutronWallet.address, ibc_module: ADMIN_MODULE_ADDRESS, paths: [quota], @@ -160,13 +162,13 @@ describe('Neutron / IBC transfer', () => { expect(res.code).toEqual(0); }); - describe('Rate limit params proposal', () => { + describe('IBC rate limit params proposal', () => { const proposalId = 1; test('create proposal', async () => { await daoMember1.submitUpdateParamsRateLimitProposal( chainManagerAddress, 'Proposal #1', - 'Param change proposal. Setup rate limit contract', + 'Param change proposal. Setup IBC rate limit contract', { contract_address: rlContract, }, @@ -185,7 +187,7 @@ describe('Neutron / IBC transfer', () => { }); }); - describe('Rate limits', () => { + describe('IBC Rate limits', () => { describe('setup ibc contract', () => { test('transfer to contract', async () => { const res = await neutronClient.sendTokens( @@ -273,14 +275,16 @@ describe('Neutron / IBC transfer', () => { }); test('IBC send via contract(s) should be limited as well', async () => { - await expect(neutronClient.execute(ibcContract, { - send: { - channel: TRANSFER_CHANNEL, - to: gaiaWallet.address, - denom: NEUTRON_DENOM, - amount: '1000001', - }, - })).rejects.toThrow(/IBC Rate Limit exceeded for channel-0/); + await expect( + neutronClient.execute(ibcContract, { + send: { + channel: TRANSFER_CHANNEL, + to: gaiaWallet.address, + denom: NEUTRON_DENOM, + amount: '1000001', + }, + }), + ).rejects.toThrow(/IBC Rate Limit exceeded for channel-0/); }); test('IBC transfer from a different wallet to ensure that limiting is working for different address (non-contract)', async () => { @@ -398,12 +402,12 @@ describe('Neutron / IBC transfer', () => { }); }); - test('IBC transfer to limit (hits the limit)', async () => { + test('IBC transfer exceeds the limit', async () => { const uatomibcSupply = await bankQuerier.supplyOf({ denom: UATOM_IBC_TO_NEUTRON_DENOM, }); - const amount = ( + amount = ( BigInt(uatomibcSupply.amount.amount) / BigInt(100) + BigInt(1) ).toString(); @@ -468,7 +472,7 @@ describe('Neutron / IBC transfer', () => { value: NeutronMsgTransfer.fromPartial({ sourcePort: 'transfer', sourceChannel: TRANSFER_CHANNEL, - token: { denom: UATOM_IBC_TO_NEUTRON_DENOM, amount: '10' }, + token: { denom: UATOM_IBC_TO_NEUTRON_DENOM, amount: amount }, sender: neutronWallet.address, receiver: gaiaWallet.address, timeoutHeight: {