From 5951c4f13dbce6aafcf42f2077ca4890e11b01a7 Mon Sep 17 00:00:00 2001 From: Cameron Fairchild Date: Fri, 7 Feb 2025 14:00:30 -0500 Subject: [PATCH 1/4] fix tests --- pallets/collective/src/tests.rs | 40 ++++++++++++++++----------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/pallets/collective/src/tests.rs b/pallets/collective/src/tests.rs index 4cc5f1bad9..8b471f4673 100644 --- a/pallets/collective/src/tests.rs +++ b/pallets/collective/src/tests.rs @@ -299,7 +299,7 @@ fn close_works() { System::set_block_number(3); assert_noop!( Collective::close( - RuntimeOrigin::signed(4), + RuntimeOrigin::root(), hash, 0, proposal_weight, @@ -310,7 +310,7 @@ fn close_works() { System::set_block_number(4); assert_ok!(Collective::close( - RuntimeOrigin::signed(4), + RuntimeOrigin::root(), hash, 0, proposal_weight, @@ -370,7 +370,7 @@ fn proposal_weight_limit_works_on_approve() { System::set_block_number(4); assert_noop!( Collective::close( - RuntimeOrigin::signed(4), + RuntimeOrigin::root(), hash, 0, proposal_weight - Weight::from_parts(100, 0), @@ -379,7 +379,7 @@ fn proposal_weight_limit_works_on_approve() { Error::::ProposalWeightLessThanDispatchCallWeight ); assert_ok!(Collective::close( - RuntimeOrigin::signed(4), + RuntimeOrigin::root(), hash, 0, proposal_weight, @@ -409,7 +409,7 @@ fn proposal_weight_limit_ignored_on_disapprove() { // No votes, this proposal wont pass System::set_block_number(4); assert_ok!(Collective::close( - RuntimeOrigin::signed(4), + RuntimeOrigin::root(), hash, 0, proposal_weight - Weight::from_parts(100, 0), @@ -442,7 +442,7 @@ fn close_with_prime_works() { System::set_block_number(4); assert_ok!(Collective::close( - RuntimeOrigin::signed(4), + RuntimeOrigin::root(), hash, 0, proposal_weight, @@ -502,7 +502,7 @@ fn close_with_voting_prime_works() { System::set_block_number(4); assert_ok!(Collective::close( - RuntimeOrigin::signed(4), + RuntimeOrigin::root(), hash, 0, proposal_weight, @@ -583,7 +583,7 @@ fn close_with_no_prime_but_majority_works() { System::set_block_number(4); assert_ok!(CollectiveMajority::close( - RuntimeOrigin::signed(4), + RuntimeOrigin::root(), hash, 0, proposal_weight, @@ -1109,7 +1109,7 @@ fn motions_all_first_vote_free_works() { let proposal_weight = proposal.get_dispatch_info().weight; let close_rval: DispatchResultWithPostInfo = Collective::close( - RuntimeOrigin::signed(2), + RuntimeOrigin::root(), hash, 0, proposal_weight, @@ -1120,7 +1120,7 @@ fn motions_all_first_vote_free_works() { // Trying to close the proposal, which is already closed // Error: "ProposalNotExists" with Pays::Yes. let close_rval: DispatchResultWithPostInfo = Collective::close( - RuntimeOrigin::signed(2), + RuntimeOrigin::root(), hash, 0, proposal_weight, @@ -1148,7 +1148,7 @@ fn motions_reproposing_disapproved_works() { assert_ok!(Collective::vote(RuntimeOrigin::signed(2), hash, 0, false)); assert_ok!(Collective::close( - RuntimeOrigin::signed(2), + RuntimeOrigin::root(), hash, 0, proposal_weight, @@ -1186,7 +1186,7 @@ fn motions_approval_with_enough_votes_and_lower_voting_threshold_works() { assert_ok!(Collective::vote(RuntimeOrigin::signed(1), hash, 0, true)); assert_ok!(Collective::vote(RuntimeOrigin::signed(2), hash, 0, true)); assert_ok!(Collective::close( - RuntimeOrigin::signed(2), + RuntimeOrigin::root(), hash, 0, proposal_weight, @@ -1243,7 +1243,7 @@ fn motions_approval_with_enough_votes_and_lower_voting_threshold_works() { assert_ok!(Collective::vote(RuntimeOrigin::signed(2), hash, 1, true)); assert_ok!(Collective::vote(RuntimeOrigin::signed(3), hash, 1, true)); assert_ok!(Collective::close( - RuntimeOrigin::signed(2), + RuntimeOrigin::root(), hash, 1, proposal_weight, @@ -1315,7 +1315,7 @@ fn motions_disapproval_works() { assert_ok!(Collective::vote(RuntimeOrigin::signed(1), hash, 0, false)); assert_ok!(Collective::vote(RuntimeOrigin::signed(2), hash, 0, false)); assert_ok!(Collective::close( - RuntimeOrigin::signed(2), + RuntimeOrigin::root(), hash, 0, proposal_weight, @@ -1374,7 +1374,7 @@ fn motions_approval_works() { assert_ok!(Collective::vote(RuntimeOrigin::signed(1), hash, 0, true)); assert_ok!(Collective::vote(RuntimeOrigin::signed(2), hash, 0, true)); assert_ok!(Collective::close( - RuntimeOrigin::signed(2), + RuntimeOrigin::root(), hash, 0, proposal_weight, @@ -1448,7 +1448,7 @@ fn motion_with_no_votes_closes_with_disapproval() { // an approving or disapproving simple majority due to the lack of votes. assert_noop!( Collective::close( - RuntimeOrigin::signed(2), + RuntimeOrigin::root(), hash, 0, proposal_weight, @@ -1462,7 +1462,7 @@ fn motion_with_no_votes_closes_with_disapproval() { System::set_block_number(closing_block); // we can successfully close the motion. assert_ok!(Collective::close( - RuntimeOrigin::signed(2), + RuntimeOrigin::root(), hash, 0, proposal_weight, @@ -1507,12 +1507,12 @@ fn close_disapprove_does_not_care_about_weight_or_len() { assert_ok!(Collective::vote(RuntimeOrigin::signed(2), hash, 0, true)); // It will not close with bad weight/len information assert_noop!( - Collective::close(RuntimeOrigin::signed(2), hash, 0, Weight::zero(), 0), + Collective::close(RuntimeOrigin::root(), hash, 0, Weight::zero(), 0), Error::::ProposalLengthBoundLessThanProposalLength, ); assert_noop!( Collective::close( - RuntimeOrigin::signed(2), + RuntimeOrigin::root(), hash, 0, Weight::zero(), @@ -1525,7 +1525,7 @@ fn close_disapprove_does_not_care_about_weight_or_len() { assert_ok!(Collective::vote(RuntimeOrigin::signed(2), hash, 0, false)); // It can close even if the weight/len information is bad assert_ok!(Collective::close( - RuntimeOrigin::signed(2), + RuntimeOrigin::root(), hash, 0, Weight::zero(), From 73967f898e1b8a7ae0223fe9547810b39f45b3c0 Mon Sep 17 00:00:00 2001 From: Cameron Fairchild Date: Fri, 7 Feb 2025 14:00:37 -0500 Subject: [PATCH 2/4] fmt --- pallets/collective/src/tests.rs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/pallets/collective/src/tests.rs b/pallets/collective/src/tests.rs index 8b471f4673..afe9a69e5b 100644 --- a/pallets/collective/src/tests.rs +++ b/pallets/collective/src/tests.rs @@ -1511,13 +1511,7 @@ fn close_disapprove_does_not_care_about_weight_or_len() { Error::::ProposalLengthBoundLessThanProposalLength, ); assert_noop!( - Collective::close( - RuntimeOrigin::root(), - hash, - 0, - Weight::zero(), - proposal_len - ), + Collective::close(RuntimeOrigin::root(), hash, 0, Weight::zero(), proposal_len), Error::::ProposalWeightLessThanDispatchCallWeight, ); // Now we make the proposal fail From 2d615e61046ca79fbecb22e7d78089fe239103aa Mon Sep 17 00:00:00 2001 From: Cameron Fairchild Date: Fri, 7 Feb 2025 14:07:20 -0500 Subject: [PATCH 3/4] fix benchmarks too --- pallets/collective/src/benchmarking.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pallets/collective/src/benchmarking.rs b/pallets/collective/src/benchmarking.rs index 380a783950..e99925759a 100644 --- a/pallets/collective/src/benchmarking.rs +++ b/pallets/collective/src/benchmarking.rs @@ -315,7 +315,7 @@ benchmarks_instance_pallet! { // Whitelist voter account from further DB operations. let voter_key = frame_system::Account::::hashed_key_for(&voter); frame_benchmarking::benchmarking::add_to_whitelist(voter_key.into()); - }: close(SystemOrigin::Signed(voter), last_hash, index, Weight::MAX, bytes_in_storage) + }: close(SystemOrigin::Root.into(), last_hash, index, Weight::MAX, bytes_in_storage) verify { // The last proposal is removed. assert_eq!(Collective::::proposals().len(), (p - 1) as usize); @@ -393,7 +393,7 @@ benchmarks_instance_pallet! { index, approve, )?; - }: close(SystemOrigin::Signed(caller), last_hash, index, Weight::MAX, bytes_in_storage) + }: close(SystemOrigin::Root.into(), last_hash, index, Weight::MAX, bytes_in_storage) verify { // The last proposal is removed. assert_eq!(Collective::::proposals().len(), (p - 1) as usize); @@ -473,7 +473,7 @@ benchmarks_instance_pallet! { assert_eq!(Collective::::proposals().len(), p as usize); // Prime nay will close it as disapproved - }: close(SystemOrigin::Signed(caller), last_hash, index, Weight::MAX, bytes_in_storage) + }: close(SystemOrigin::Root.into(), last_hash, index, Weight::MAX, bytes_in_storage) verify { assert_eq!(Collective::::proposals().len(), (p - 1) as usize); assert_last_event::(Event::Disapproved { proposal_hash: last_hash }.into()); @@ -542,7 +542,7 @@ benchmarks_instance_pallet! { assert_eq!(Collective::::proposals().len(), p as usize); // Prime aye will close it as approved - }: close(SystemOrigin::Signed(caller), last_hash, p - 1, Weight::MAX, bytes_in_storage) + }: close(SystemOrigin::Root.into(), last_hash, p - 1, Weight::MAX, bytes_in_storage) verify { assert_eq!(Collective::::proposals().len(), (p - 1) as usize); assert_last_event::(Event::Executed { proposal_hash: last_hash, result: Ok(()) }.into()); From 264dae23e3fdffa58aeffe1490232b5818c653c8 Mon Sep 17 00:00:00 2001 From: Cameron Fairchild Date: Fri, 7 Feb 2025 14:18:11 -0500 Subject: [PATCH 4/4] follow CI suggestion --- pallets/collective/src/benchmarking.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pallets/collective/src/benchmarking.rs b/pallets/collective/src/benchmarking.rs index e99925759a..683369060f 100644 --- a/pallets/collective/src/benchmarking.rs +++ b/pallets/collective/src/benchmarking.rs @@ -315,7 +315,7 @@ benchmarks_instance_pallet! { // Whitelist voter account from further DB operations. let voter_key = frame_system::Account::::hashed_key_for(&voter); frame_benchmarking::benchmarking::add_to_whitelist(voter_key.into()); - }: close(SystemOrigin::Root.into(), last_hash, index, Weight::MAX, bytes_in_storage) + }: close( as Into>::into(SystemOrigin::Root), last_hash, index, Weight::MAX, bytes_in_storage) verify { // The last proposal is removed. assert_eq!(Collective::::proposals().len(), (p - 1) as usize); @@ -393,7 +393,7 @@ benchmarks_instance_pallet! { index, approve, )?; - }: close(SystemOrigin::Root.into(), last_hash, index, Weight::MAX, bytes_in_storage) + }: close( as Into>::into(SystemOrigin::Root), last_hash, index, Weight::MAX, bytes_in_storage) verify { // The last proposal is removed. assert_eq!(Collective::::proposals().len(), (p - 1) as usize); @@ -473,7 +473,7 @@ benchmarks_instance_pallet! { assert_eq!(Collective::::proposals().len(), p as usize); // Prime nay will close it as disapproved - }: close(SystemOrigin::Root.into(), last_hash, index, Weight::MAX, bytes_in_storage) + }: close( as Into>::into(SystemOrigin::Root), last_hash, index, Weight::MAX, bytes_in_storage) verify { assert_eq!(Collective::::proposals().len(), (p - 1) as usize); assert_last_event::(Event::Disapproved { proposal_hash: last_hash }.into()); @@ -542,7 +542,7 @@ benchmarks_instance_pallet! { assert_eq!(Collective::::proposals().len(), p as usize); // Prime aye will close it as approved - }: close(SystemOrigin::Root.into(), last_hash, p - 1, Weight::MAX, bytes_in_storage) + }: close( as Into>::into(SystemOrigin::Root), last_hash, p - 1, Weight::MAX, bytes_in_storage) verify { assert_eq!(Collective::::proposals().len(), (p - 1) as usize); assert_last_event::(Event::Executed { proposal_hash: last_hash, result: Ok(()) }.into());