In the tests of a pallet, I would like to use the council as the origin.
I did the following:
- Imported the collective pallet
- Implemented
pallet_collective::Config
forTest
:
type CouncilCollective = pallet_collective::Instance1;
impl pallet_collective::Config<CouncilCollective> for Test {
type RuntimeOrigin = RuntimeOrigin;
type Proposal = RuntimeCall;
type RuntimeEvent = RuntimeEvent;
type MotionDuration = MotionDuration;
type MaxProposals = MaxProposals;
type MaxMembers = MaxMembers;
type DefaultVote = pallet_collective::PrimeDefaultVote;
type WeightInfo = ();
}
- Set the
GenesisConfig
:
pallet_collective::GenesisConfig::<Test, Instance1> {
members: vec![1, 2, 3],
phantom: Default::default(),
}
.assimilate_storage(&mut t)
.unwrap();
- Wrote the test like this:
// this returns a RuntimeCall that can be called by council
let proposal = make_proposal()
let proposal_len: u32 = proposal.using_encoded(|p| p.len() as u32);
let proposal_weight = proposal.get_dispatch_info().weight;
let hash = BlakeTwo256::hash_of(&proposal);
assert_ok!(Council::propose(
RuntimeOrigin::signed(1),
3,
Box::new(proposal.clone()),
proposal_len
));
assert_ok!(Council::vote(RuntimeOrigin::signed(1), hash, 0, true));
assert_ok!(Council::vote(RuntimeOrigin::signed(2), hash, 0, true));
assert_ok!(Council::vote(RuntimeOrigin::signed(3), hash, 0, true));
System::set_block_number(4);
assert_ok!(Council::close(
RuntimeOrigin::signed(4),
hash,
0,
proposal_weight,
proposal_len
));
// The test fails at this assertion, the result is not Ok
System::assert_last_event(RuntimeEvent::Council(pallet_collective::Event::Executed {
proposal_hash: hash,
result: Ok(()),
}));
I am not sure what I am doing wrong here.