mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 07:31:08 +00:00
Try-state for Collective pallet (#13645)
* write the try_state_ function * update tests * update check * fix benchmarking * fix nonsense * Update frame/collective/src/lib.rs Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Update frame/collective/src/lib.rs Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * unique proposal index * prime must be a member of the collective * oops * Add new checks * use ensure * fix --------- Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
This commit is contained in:
@@ -155,23 +155,40 @@ impl Config for Test {
|
||||
type SetMembersOrigin = EnsureRoot<Self::AccountId>;
|
||||
}
|
||||
|
||||
pub fn new_test_ext() -> sp_io::TestExternalities {
|
||||
let mut ext: sp_io::TestExternalities = GenesisConfig {
|
||||
collective: pallet_collective::GenesisConfig {
|
||||
members: vec![1, 2, 3],
|
||||
phantom: Default::default(),
|
||||
},
|
||||
collective_majority: pallet_collective::GenesisConfig {
|
||||
members: vec![1, 2, 3, 4, 5],
|
||||
phantom: Default::default(),
|
||||
},
|
||||
default_collective: Default::default(),
|
||||
pub struct ExtBuilder {}
|
||||
|
||||
impl Default for ExtBuilder {
|
||||
fn default() -> Self {
|
||||
Self {}
|
||||
}
|
||||
}
|
||||
|
||||
impl ExtBuilder {
|
||||
pub fn build(self) -> sp_io::TestExternalities {
|
||||
let mut ext: sp_io::TestExternalities = GenesisConfig {
|
||||
collective: pallet_collective::GenesisConfig {
|
||||
members: vec![1, 2, 3],
|
||||
phantom: Default::default(),
|
||||
},
|
||||
collective_majority: pallet_collective::GenesisConfig {
|
||||
members: vec![1, 2, 3, 4, 5],
|
||||
phantom: Default::default(),
|
||||
},
|
||||
default_collective: Default::default(),
|
||||
}
|
||||
.build_storage()
|
||||
.unwrap()
|
||||
.into();
|
||||
ext.execute_with(|| System::set_block_number(1));
|
||||
ext
|
||||
}
|
||||
|
||||
pub fn build_and_execute(self, test: impl FnOnce() -> ()) {
|
||||
self.build().execute_with(|| {
|
||||
test();
|
||||
Collective::do_try_state().unwrap();
|
||||
})
|
||||
}
|
||||
.build_storage()
|
||||
.unwrap()
|
||||
.into();
|
||||
ext.execute_with(|| System::set_block_number(1));
|
||||
ext
|
||||
}
|
||||
|
||||
fn make_proposal(value: u64) -> RuntimeCall {
|
||||
@@ -186,7 +203,7 @@ fn record(event: RuntimeEvent) -> EventRecord<RuntimeEvent, H256> {
|
||||
|
||||
#[test]
|
||||
fn motions_basic_environment_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
assert_eq!(Collective::members(), vec![1, 2, 3]);
|
||||
assert_eq!(*Collective::proposals(), Vec::<H256>::new());
|
||||
});
|
||||
@@ -194,7 +211,7 @@ fn motions_basic_environment_works() {
|
||||
|
||||
#[test]
|
||||
fn close_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
let proposal = make_proposal(42);
|
||||
let proposal_len: u32 = proposal.using_encoded(|p| p.len() as u32);
|
||||
let proposal_weight = proposal.get_dispatch_info().weight;
|
||||
@@ -262,7 +279,7 @@ fn close_works() {
|
||||
|
||||
#[test]
|
||||
fn proposal_weight_limit_works_on_approve() {
|
||||
new_test_ext().execute_with(|| {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
let proposal = RuntimeCall::Collective(crate::Call::set_members {
|
||||
new_members: vec![1, 2, 3],
|
||||
prime: None,
|
||||
@@ -304,7 +321,7 @@ fn proposal_weight_limit_works_on_approve() {
|
||||
|
||||
#[test]
|
||||
fn proposal_weight_limit_ignored_on_disapprove() {
|
||||
new_test_ext().execute_with(|| {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
let proposal = RuntimeCall::Collective(crate::Call::set_members {
|
||||
new_members: vec![1, 2, 3],
|
||||
prime: None,
|
||||
@@ -334,7 +351,7 @@ fn proposal_weight_limit_ignored_on_disapprove() {
|
||||
|
||||
#[test]
|
||||
fn close_with_prime_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
let proposal = make_proposal(42);
|
||||
let proposal_len: u32 = proposal.using_encoded(|p| p.len() as u32);
|
||||
let proposal_weight = proposal.get_dispatch_info().weight;
|
||||
@@ -402,7 +419,7 @@ fn close_with_prime_works() {
|
||||
|
||||
#[test]
|
||||
fn close_with_voting_prime_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
let proposal = make_proposal(42);
|
||||
let proposal_len: u32 = proposal.using_encoded(|p| p.len() as u32);
|
||||
let proposal_weight = proposal.get_dispatch_info().weight;
|
||||
@@ -472,7 +489,7 @@ fn close_with_voting_prime_works() {
|
||||
|
||||
#[test]
|
||||
fn close_with_no_prime_but_majority_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
let proposal = make_proposal(42);
|
||||
let proposal_len: u32 = proposal.using_encoded(|p| p.len() as u32);
|
||||
let proposal_weight = proposal.get_dispatch_info().weight;
|
||||
@@ -552,7 +569,7 @@ fn close_with_no_prime_but_majority_works() {
|
||||
|
||||
#[test]
|
||||
fn removal_of_old_voters_votes_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
let proposal = make_proposal(42);
|
||||
let proposal_len: u32 = proposal.using_encoded(|p| p.len() as u32);
|
||||
let hash = BlakeTwo256::hash_of(&proposal);
|
||||
@@ -600,7 +617,7 @@ fn removal_of_old_voters_votes_works() {
|
||||
|
||||
#[test]
|
||||
fn removal_of_old_voters_votes_works_with_set_members() {
|
||||
new_test_ext().execute_with(|| {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
let proposal = make_proposal(42);
|
||||
let proposal_len: u32 = proposal.using_encoded(|p| p.len() as u32);
|
||||
let hash = BlakeTwo256::hash_of(&proposal);
|
||||
@@ -658,7 +675,7 @@ fn removal_of_old_voters_votes_works_with_set_members() {
|
||||
|
||||
#[test]
|
||||
fn propose_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
let proposal = make_proposal(42);
|
||||
let proposal_len: u32 = proposal.using_encoded(|p| p.len() as u32);
|
||||
let hash = proposal.blake2_256().into();
|
||||
@@ -690,7 +707,7 @@ fn propose_works() {
|
||||
|
||||
#[test]
|
||||
fn limit_active_proposals() {
|
||||
new_test_ext().execute_with(|| {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
for i in 0..MaxProposals::get() {
|
||||
let proposal = make_proposal(i as u64);
|
||||
let proposal_len: u32 = proposal.using_encoded(|p| p.len() as u32);
|
||||
@@ -717,7 +734,7 @@ fn limit_active_proposals() {
|
||||
|
||||
#[test]
|
||||
fn correct_validate_and_get_proposal() {
|
||||
new_test_ext().execute_with(|| {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
let proposal = RuntimeCall::Collective(crate::Call::set_members {
|
||||
new_members: vec![1, 2, 3],
|
||||
prime: None,
|
||||
@@ -763,7 +780,7 @@ fn correct_validate_and_get_proposal() {
|
||||
|
||||
#[test]
|
||||
fn motions_ignoring_non_collective_proposals_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
let proposal = make_proposal(42);
|
||||
let proposal_len: u32 = proposal.using_encoded(|p| p.len() as u32);
|
||||
assert_noop!(
|
||||
@@ -780,7 +797,7 @@ fn motions_ignoring_non_collective_proposals_works() {
|
||||
|
||||
#[test]
|
||||
fn motions_ignoring_non_collective_votes_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
let proposal = make_proposal(42);
|
||||
let proposal_len: u32 = proposal.using_encoded(|p| p.len() as u32);
|
||||
let hash: H256 = proposal.blake2_256().into();
|
||||
@@ -799,7 +816,7 @@ fn motions_ignoring_non_collective_votes_works() {
|
||||
|
||||
#[test]
|
||||
fn motions_ignoring_bad_index_collective_vote_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
System::set_block_number(3);
|
||||
let proposal = make_proposal(42);
|
||||
let proposal_len: u32 = proposal.using_encoded(|p| p.len() as u32);
|
||||
@@ -819,7 +836,7 @@ fn motions_ignoring_bad_index_collective_vote_works() {
|
||||
|
||||
#[test]
|
||||
fn motions_vote_after_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
let proposal = make_proposal(42);
|
||||
let proposal_len: u32 = proposal.using_encoded(|p| p.len() as u32);
|
||||
let hash: H256 = proposal.blake2_256().into();
|
||||
@@ -888,7 +905,7 @@ fn motions_vote_after_works() {
|
||||
|
||||
#[test]
|
||||
fn motions_all_first_vote_free_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
let proposal = make_proposal(42);
|
||||
let proposal_len: u32 = proposal.using_encoded(|p| p.len() as u32);
|
||||
let hash: H256 = proposal.blake2_256().into();
|
||||
@@ -946,7 +963,7 @@ fn motions_all_first_vote_free_works() {
|
||||
|
||||
#[test]
|
||||
fn motions_reproposing_disapproved_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
let proposal = make_proposal(42);
|
||||
let proposal_len: u32 = proposal.using_encoded(|p| p.len() as u32);
|
||||
let proposal_weight = proposal.get_dispatch_info().weight;
|
||||
@@ -978,7 +995,7 @@ fn motions_reproposing_disapproved_works() {
|
||||
|
||||
#[test]
|
||||
fn motions_approval_with_enough_votes_and_lower_voting_threshold_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
let proposal = RuntimeCall::Democracy(mock_democracy::Call::external_propose_majority {});
|
||||
let proposal_len: u32 = proposal.using_encoded(|p| p.len() as u32);
|
||||
let proposal_weight = proposal.get_dispatch_info().weight;
|
||||
@@ -1108,7 +1125,7 @@ fn motions_approval_with_enough_votes_and_lower_voting_threshold_works() {
|
||||
|
||||
#[test]
|
||||
fn motions_disapproval_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
let proposal = make_proposal(42);
|
||||
let proposal_len: u32 = proposal.using_encoded(|p| p.len() as u32);
|
||||
let proposal_weight = proposal.get_dispatch_info().weight;
|
||||
@@ -1167,7 +1184,7 @@ fn motions_disapproval_works() {
|
||||
|
||||
#[test]
|
||||
fn motions_approval_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
let proposal = make_proposal(42);
|
||||
let proposal_len: u32 = proposal.using_encoded(|p| p.len() as u32);
|
||||
let proposal_weight = proposal.get_dispatch_info().weight;
|
||||
@@ -1228,7 +1245,7 @@ fn motions_approval_works() {
|
||||
|
||||
#[test]
|
||||
fn motion_with_no_votes_closes_with_disapproval() {
|
||||
new_test_ext().execute_with(|| {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
let proposal = make_proposal(42);
|
||||
let proposal_len: u32 = proposal.using_encoded(|p| p.len() as u32);
|
||||
let proposal_weight = proposal.get_dispatch_info().weight;
|
||||
@@ -1289,7 +1306,7 @@ fn close_disapprove_does_not_care_about_weight_or_len() {
|
||||
// This test confirms that if you close a proposal that would be disapproved,
|
||||
// we do not care about the proposal length or proposal weight since it will
|
||||
// not be read from storage or executed.
|
||||
new_test_ext().execute_with(|| {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
let proposal = make_proposal(42);
|
||||
let proposal_len: u32 = proposal.using_encoded(|p| p.len() as u32);
|
||||
let hash: H256 = proposal.blake2_256().into();
|
||||
@@ -1321,7 +1338,7 @@ fn close_disapprove_does_not_care_about_weight_or_len() {
|
||||
|
||||
#[test]
|
||||
fn disapprove_proposal_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
let proposal = make_proposal(42);
|
||||
let proposal_len: u32 = proposal.using_encoded(|p| p.len() as u32);
|
||||
let hash: H256 = proposal.blake2_256().into();
|
||||
@@ -1380,7 +1397,7 @@ fn genesis_build_panics_with_duplicate_members() {
|
||||
|
||||
#[test]
|
||||
fn migration_v4() {
|
||||
new_test_ext().execute_with(|| {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
use frame_support::traits::PalletInfoAccess;
|
||||
|
||||
let old_pallet = "OldCollective";
|
||||
|
||||
Reference in New Issue
Block a user