diff --git a/package.json b/package.json index d5898c53..f6703fd2 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "@cosmjs/stargate": "0.32.4", "@cosmjs/tendermint-rpc": "^0.32.4", "@neutron-org/neutronjs": "4.2.0", - "@neutron-org/neutronjsplus": "0.5.0", + "@neutron-org/neutronjsplus": "https://github.com/neutron-org/neutronjsplus.git#84114edce716e9673596b392cae080eb84133605", "@types/lodash": "^4.14.182", "axios": "1.6.0", "commander": "^10.0.0", diff --git a/src/testcases/run_in_band/chain_manager.test.ts b/src/testcases/run_in_band/chain_manager.test.ts index a836bd29..3f7c8dc4 100644 --- a/src/testcases/run_in_band/chain_manager.test.ts +++ b/src/testcases/run_in_band/chain_manager.test.ts @@ -8,12 +8,14 @@ import { } from '@neutron-org/neutronjsplus/dist/dao'; import { waitSeconds } from '@neutron-org/neutronjsplus/dist/wait'; import { + addCronScheduleProposal, + removeCronScheduleProposal, updateCronParamsProposal, updateDexParamsProposal, 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'; @@ -22,6 +24,7 @@ import { QueryClientImpl as TokenfactoryQueryClient } from '@neutron-org/neutron import { QueryClientImpl as DexQueryClient } from '@neutron-org/neutronjs/neutron/dex/query.rpc.Query'; import { SigningNeutronClient } from '../../helpers/signing_neutron_client'; import config from '../../config.json'; +import { chainManagerWrapper } from '@neutron-org/neutronjsplus/src/proposal'; describe('Neutron / Chain Manager', () => { let testState: LocalState; @@ -36,7 +39,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( @@ -182,6 +185,12 @@ describe('Neutron / Chain Manager', () => { limit: true, }, }, + { + cron_permission: { + add_schedule: true, + remove_schedule: true, + }, + }, { update_tokenfactory_params_permission: { denom_creation_fee: true, @@ -356,4 +365,101 @@ describe('Neutron / Chain Manager', () => { expect(dexParams.params.goodTilPurgeAllowance).toEqual(50000n); }); }); + + describe('ALLOW_ONLY: CRON add schedule / remove schedule', () => { + let proposalId: number; + const scheduleName = 'schedule1'; + + test('create addSchedule proposal', async () => { + const info = { + name: 'schedule1', + period: 100, + msgs: [ + { + contract: 'whatever', + msg: JSON.stringify({}), + }, + ], + execution_stage: 0, + }; + proposalId = await subdaoMember1.submitSingleChoiceProposal( + 'Add schedule', + 'cron add schedule proposal. Will pass', + [ + chainManagerWrapper( + chainManagerAddress, + addCronScheduleProposal(info), + ), + ], + '1000', + ); + + const timelockedProp = await subdaoMember1.supportAndExecuteProposal( + proposalId, + ); + + expect(timelockedProp.id).toEqual(proposalId); + expect(timelockedProp.status).toEqual('timelocked'); + expect(timelockedProp.msgs).toHaveLength(1); + }); + + test('execute timelocked addSchedule: success', async () => { + await waitSeconds(10); + + await subdaoMember1.executeTimelockedProposal(proposalId); + const timelockedProp = await subDao.getTimelockedProposal(proposalId); + expect(timelockedProp.id).toEqual(proposalId); + expect(timelockedProp.status).toEqual('executed'); + expect(timelockedProp.msgs).toHaveLength(1); + + const res = await cronQuerier.schedule({ name: scheduleName }); + expect(res.schedule.name).toEqual(scheduleName); + expect(res.schedule.msgs.length).toEqual(1); + expect(res.schedule.period).toEqual(100n); + }); + + test('create removeSchedule proposal', async () => { + const info = { + name: 'schedule1', + }; + proposalId = await subdaoMember1.submitSingleChoiceProposal( + 'Add schedule', + 'cron add schedule proposal. Will pass', + [ + chainManagerWrapper( + chainManagerAddress, + removeCronScheduleProposal(info), + ), + ], + '1000', + ); + + const timelockedProp = await subdaoMember1.supportAndExecuteProposal( + proposalId, + ); + + expect(timelockedProp.id).toEqual(proposalId); + expect(timelockedProp.status).toEqual('timelocked'); + expect(timelockedProp.msgs).toHaveLength(1); + }); + + test('execute timelocked removeSchedule: success', async () => { + await waitSeconds(10); + + await subdaoMember1.executeTimelockedProposal(proposalId); + const timelockedProp = await subDao.getTimelockedProposal(proposalId); + expect(timelockedProp.id).toEqual(proposalId); + expect(timelockedProp.status).toEqual('executed'); + expect(timelockedProp.msgs).toHaveLength(1); + + let exceptionThrown = false; + try { + await cronQuerier.schedule({ name: scheduleName }); + } catch (error) { + expect(error.message).toMatch(/schedule not found: key not found/); + exceptionThrown = true; + } + expect(exceptionThrown).toBeTruthy(); + }); + }); }); diff --git a/yarn.lock b/yarn.lock index 862ec492..91c85330 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1312,10 +1312,9 @@ resolved "https://registry.yarnpkg.com/@neutron-org/neutronjs/-/neutronjs-4.2.0.tgz#7d98d4bc1568f22c015736d6fbe768ddfba14798" integrity sha512-l3ILkT8H6bO522RoNb37NMQkqlp8qvKNm7v6QlzORtClqbM7VbRv2/INgy8wn8USV5AmcnCdl9M4KfvvGw5k9w== -"@neutron-org/neutronjsplus@0.5.0": +"@neutron-org/neutronjsplus@https://github.com/neutron-org/neutronjsplus.git#84114edce716e9673596b392cae080eb84133605": version "0.5.0" - resolved "https://registry.yarnpkg.com/@neutron-org/neutronjsplus/-/neutronjsplus-0.5.0.tgz#d68afb8142ee0bd2d3eee21916901507503360a3" - integrity sha512-dzWL9hTVorMskWzW/ZEUK3Cruw0AkOlC8fk6pFIyli4XkNooJKL/H7V8PSxiwIyx3k+EpIZ0I5FpzCL9EitNMg== + resolved "https://github.com/neutron-org/neutronjsplus.git#84114edce716e9673596b392cae080eb84133605" dependencies: "@cosmjs/cosmwasm-stargate" "^0.32.4" "@cosmjs/proto-signing" "^0.32.4"