Skip to content

Commit

Permalink
Fix conviction MaxVotes (#2401)
Browse files Browse the repository at this point in the history
* Reduce the ConvictionVoting MaxVotes from 512 to 30

* Set MaxVote to 20
  • Loading branch information
crystalin authored and fgamundi committed Aug 6, 2023
1 parent 2698cd2 commit 1ca8710
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 4 deletions.
2 changes: 1 addition & 1 deletion runtime/moonbase/src/governance/referenda.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl pallet_conviction_voting::Config for Runtime {
type Polls = Referenda;
type MaxTurnout = frame_support::traits::TotalIssuanceOf<Balances, Self::AccountId>;
// Maximum number of concurrent votes an account may have
type MaxVotes = ConstU32<512>;
type MaxVotes = ConstU32<20>;
// Minimum period of vote locking
type VoteLockingPeriod = VoteLockingPeriod;
}
Expand Down
2 changes: 1 addition & 1 deletion runtime/moonbeam/src/governance/referenda.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl pallet_conviction_voting::Config for Runtime {
type Polls = Referenda;
type MaxTurnout = frame_support::traits::TotalIssuanceOf<Balances, Self::AccountId>;
// Maximum number of concurrent votes an account may have
type MaxVotes = ConstU32<512>;
type MaxVotes = ConstU32<20>;
// Minimum period of vote locking
type VoteLockingPeriod = VoteLockingPeriod;
}
Expand Down
2 changes: 1 addition & 1 deletion runtime/moonriver/src/governance/referenda.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl pallet_conviction_voting::Config for Runtime {
type Polls = Referenda;
type MaxTurnout = frame_support::traits::TotalIssuanceOf<Balances, Self::AccountId>;
// Maximum number of concurrent votes an account may have
type MaxVotes = ConstU32<512>;
type MaxVotes = ConstU32<20>;
// Minimum period of vote locking
type VoteLockingPeriod = VoteLockingPeriod;
}
Expand Down
12 changes: 11 additions & 1 deletion test/helpers/expect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,17 @@ export function expectSubstrateEvent<
event = foundEvents[0];
}
}
expect(event).to.not.be.undefined;
expect(
event,
`Event ${section.toString()}.${method.toString()} not found:\n${(Array.isArray(block.result)
? block.result.map((r) => r.events).flat()
: block.result
? block.result.events
: []
)
.map(({ event }) => ` - ${event.section.toString()}.${event.method.toString()}\n`)
.join("")}`
).to.not.be.undefined;
return event!.event as any;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import "@moonbeam-network/api-augment";
import { beforeAll, describeSuite, expect, proposeReferendaAndDeposit } from "@moonwall/cli";
import { ALITH_ADDRESS, GLMR, alith, baltathar, faith } from "@moonwall/util";
import { expectSubstrateEvent } from "../../../helpers/expect.js";

describeSuite({
id: "D2600",
title: "Conviction Voting - Delegation",
foundationMethods: "dev",
testCases: ({ context, it }) => {
let refIndex: number;
let proposalHash: string;
beforeAll(async () => {
// The proposal itself
const proposal = context.polkadotJs().tx.identity.setIdentity({ display: { raw: "Me" } });
[refIndex, proposalHash] = await proposeReferendaAndDeposit(context, alith, proposal, {
System: "root",
});
});

it({
id: "T01",
title: "Alith should be able to delegate to Baltathar",
test: async function () {
const rootTrack = context
.polkadotJs()
.consts.referenda.tracks.find(([, track]) => track.name.eq("root"))!;

const blockResult = await context.createBlock(
context
.polkadotJs()
.tx.convictionVoting.delegate(rootTrack[0], baltathar.address, "Locked1x", 100n * GLMR)
);

expectSubstrateEvent(blockResult, "convictionVoting", "Delegated");
const votingFor = await context
.polkadotJs()
.query.convictionVoting.votingFor(ALITH_ADDRESS, rootTrack[0]);
expect(votingFor.isDelegating).toBe(true);
expect(votingFor.asDelegating.target.toString()).toBe(baltathar.address);
expect(votingFor.asDelegating.balance.toBigInt()).toBe(100n * GLMR);
},
});

it({
id: "T02",
title: "Alith should not be able to delegate to the same track twice",
test: async function () {
const rootTrack = context
.polkadotJs()
.consts.referenda.tracks.find(([, track]) => track.name.eq("root"))!;

const blockResult = await context.createBlock(
context
.polkadotJs()
.tx.convictionVoting.delegate(rootTrack[0], faith.address, "Locked1x", 100n * GLMR)
);

expectSubstrateEvent(blockResult, "system", "ExtrinsicFailed");
},
});

it({
id: "T03",
title: "Alith should be able to undelegate",
test: async function () {
const rootTrack = context
.polkadotJs()
.consts.referenda.tracks.find(([, track]) => track.name.eq("root"))!;

const blockResult = await context.createBlock(
await context.polkadotJs().tx.convictionVoting.undelegate(rootTrack[0])
);

expectSubstrateEvent(blockResult, "convictionVoting", "Undelegated");
},
});
},
});

0 comments on commit 1ca8710

Please sign in to comment.