difftreelog
test democracy can elect a sudo account
in: master
1 file changed
js-packages/tests/sub/governance/electsudo.test.tsdiffbeforeafterboth1import type {IKeyringPair} from '@polkadot/types/types';2import {usingPlaygrounds, itSub, expect, Pallets, requirePalletsOrSkip, describeGov} from '../../util/index.js';3import {Event} from '@unique/playgrounds/unique.dev.js';4import {initCouncil, democracyLaunchPeriod, democracyVotingPeriod, democracyEnactmentPeriod, clearCouncil, clearTechComm, initTechComm, ITechComms} from './util.js';5import type {ICounselors} from './util.js';67describeGov('Governance: Elect Sudo', () => {8 let sudoer: IKeyringPair;9 let donor: IKeyringPair;10 let counselors: ICounselors;11 let techComm: ITechComms;1213 const moreThanHalfCouncilThreshold = 3;1415 before(async function() {16 await usingPlaygrounds(async (helper, privateKey) => {17 requirePalletsOrSkip(this, helper, [Pallets.Council]);1819 sudoer = await privateKey('//Alice');20 donor = await privateKey({url: import.meta.url});21 counselors = await initCouncil(donor, sudoer);22 techComm = await initTechComm(donor, sudoer);23 });24 });2526 after(async () => {27 await clearCouncil(sudoer);28 await clearTechComm(sudoer);29 });3031 itSub('Democracy can elect a sudo account', async ({helper}) => {32 const [newAccount] = await helper.arrange.createAccounts([1000n], donor);33 const newSudoKey = newAccount.address;3435 const democracyProposal = helper.constructApiCall('api.tx.utility.dispatchAs', [36 {37 system: {38 Signed: sudoer.address,39 },40 },41 helper.constructApiCall('api.tx.sudo.setKey', [newSudoKey]),42 ]);4344 const councilProposal = await helper.democracy.externalProposeDefaultCall(democracyProposal);4546 const proposeResult = await helper.council.collective.propose(47 counselors.filip,48 councilProposal,49 moreThanHalfCouncilThreshold,50 );5152 const councilProposedEvent = Event.Council.Proposed.expect(proposeResult);53 const proposalIndex = councilProposedEvent.proposalIndex;54 const proposalHash = councilProposedEvent.proposalHash;5556 await helper.council.collective.vote(counselors.alex, proposalHash, proposalIndex, true);57 await helper.council.collective.vote(counselors.charu, proposalHash, proposalIndex, true);58 await helper.council.collective.vote(counselors.filip, proposalHash, proposalIndex, true);5960 await helper.council.collective.close(counselors.filip, proposalHash, proposalIndex);6162 const democracyStartedEvent = await helper.wait.expectEvent(democracyLaunchPeriod, Event.Democracy.Started);63 const democracyReferendumIndex = democracyStartedEvent.referendumIndex;64 const democracyThreshold = democracyStartedEvent.threshold;6566 expect(democracyThreshold).to.be.equal('SuperMajorityAgainst');6768 await helper.democracy.vote(newAccount, democracyReferendumIndex, {69 Standard: {70 vote: {71 aye: true,72 conviction: 1,73 },74 balance: 800n,75 },76 });7778 const passedReferendumEvent = await helper.wait.expectEvent(democracyVotingPeriod, Event.Democracy.Passed);79 expect(passedReferendumEvent.referendumIndex).to.be.equal(democracyReferendumIndex);8081 await helper.wait.expectEvent(democracyEnactmentPeriod, Event.Scheduler.Dispatched);82 const currentSudoKey = await helper.callRpc('api.query.sudo.key', [])83 .then(k => k.toString());84 expect(currentSudoKey).to.be.equal(newSudoKey);8586 await helper.executeExtrinsic(newAccount, 'api.tx.sudo.setKey', [sudoer.address]);87 });88});