0

In the tests of a pallet, I would like to use the council as the origin.

I did the following:

  1. Imported the collective pallet
  2. Implemented pallet_collective::Config for Test:
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 = ();
}
  1. Set the GenesisConfig:
    pallet_collective::GenesisConfig::<Test, Instance1> {
        members: vec![1, 2, 3],
        phantom: Default::default(),
    }
    .assimilate_storage(&mut t)
    .unwrap();
  1. 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.

1
  • Did you checked what events are being present?
    – bkchr
    Oct 19, 2022 at 19:19

1 Answer 1

2

If you want to execute something using the council origin, you can construct it on your own:

Pallet::run_whatever(pallet_collective::RawOrigin::Members(5, 5).into(), args);
1
  • Yeah, this is a much simpler approach, thanks!
    – Szegoo
    Oct 19, 2022 at 19:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.