Skip to content

Commit

Permalink
add allow_only for cron addschedule removeschedule messages to chain …
Browse files Browse the repository at this point in the history
…manager test
  • Loading branch information
NeverHappened committed Aug 28, 2024
1 parent fa3b969 commit a7087ff
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
110 changes: 108 additions & 2 deletions src/testcases/run_in_band/chain_manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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;
Expand All @@ -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(
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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();
});
});
});
5 changes: 2 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit a7087ff

Please sign in to comment.