mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 09:51:02 +00:00
Alliance pallet: add force_set_members instead of init_members function (#11997)
* Alliance pallet: add force_set_members instead of init_members function * benchmark with witness data * remove invalid limit for clear * Apply suggestions from code review Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com> * Revert "remove invalid limit for clear" This reverts commit dba54e3071b63bfea908087aef213f4640e3ccbf. * compile constructor only for test * Update comments for force_set_members Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com> * ".git/.scripts/bench-bot.sh" pallet dev pallet_alliance * benchmark - founders count range * Revert "benchmark - founders count range" This reverts commit aad16796f8dfed48079fb7f587b8f5b59382cda6. * witness members count instead votable members count * update the doc * use decode_len for witness data checks * change witness data member count to voting member count; update clear limits * ".git/.scripts/bench-bot.sh" pallet dev pallet_alliance * merge master * fixes after merge master * revert to cb3e63 * disband alliance and return deposits * revert debug changes * weights * update docs * update test comments * Apply Joe suggestions from code review Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com> * rename event from AllianceDisband to AllianceDisbanded * ".git/.scripts/bench-bot.sh" pallet dev pallet_alliance Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com> Co-authored-by: command-bot <>
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
//! Test utilities
|
||||
|
||||
pub use sp_core::H256;
|
||||
use sp_runtime::traits::Hash;
|
||||
pub use sp_runtime::{
|
||||
testing::Header,
|
||||
traits::{BlakeTwo256, IdentityLookup},
|
||||
@@ -196,6 +197,14 @@ impl ProposalProvider<u64, H256, Call> for AllianceProposalProvider {
|
||||
fn proposal_of(proposal_hash: H256) -> Option<Call> {
|
||||
AllianceMotion::proposal_of(proposal_hash)
|
||||
}
|
||||
|
||||
fn proposals() -> Vec<H256> {
|
||||
AllianceMotion::proposals().into_inner()
|
||||
}
|
||||
|
||||
fn proposals_count() -> u32 {
|
||||
pallet_collective::Proposals::<Test, AllianceCollective>::decode_len().unwrap_or(0) as u32
|
||||
}
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
@@ -254,7 +263,17 @@ pub fn new_test_ext() -> sp_io::TestExternalities {
|
||||
let mut t = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();
|
||||
|
||||
pallet_balances::GenesisConfig::<Test> {
|
||||
balances: vec![(1, 50), (2, 50), (3, 50), (4, 50), (5, 30), (6, 50), (7, 50)],
|
||||
balances: vec![
|
||||
(1, 50),
|
||||
(2, 50),
|
||||
(3, 50),
|
||||
(4, 50),
|
||||
(5, 30),
|
||||
(6, 50),
|
||||
(7, 50),
|
||||
(8, 50),
|
||||
(9, 50),
|
||||
],
|
||||
}
|
||||
.assimilate_storage(&mut t)
|
||||
.unwrap();
|
||||
@@ -296,6 +315,10 @@ pub fn new_test_ext() -> sp_io::TestExternalities {
|
||||
assert_ok!(Identity::set_identity(Origin::signed(5), Box::new(info.clone())));
|
||||
assert_ok!(Identity::provide_judgement(Origin::signed(1), 0, 5, Judgement::KnownGood));
|
||||
assert_ok!(Identity::set_identity(Origin::signed(6), Box::new(info.clone())));
|
||||
assert_ok!(Identity::set_identity(Origin::signed(8), Box::new(info.clone())));
|
||||
assert_ok!(Identity::provide_judgement(Origin::signed(1), 0, 8, Judgement::KnownGood));
|
||||
assert_ok!(Identity::set_identity(Origin::signed(9), Box::new(info.clone())));
|
||||
assert_ok!(Identity::provide_judgement(Origin::signed(1), 0, 9, Judgement::KnownGood));
|
||||
|
||||
// Joining before init should fail.
|
||||
assert_noop!(
|
||||
@@ -303,7 +326,13 @@ pub fn new_test_ext() -> sp_io::TestExternalities {
|
||||
Error::<Test, ()>::AllianceNotYetInitialized
|
||||
);
|
||||
|
||||
assert_ok!(Alliance::init_members(Origin::root(), vec![1, 2], vec![3], vec![]));
|
||||
assert_ok!(Alliance::force_set_members(
|
||||
Origin::root(),
|
||||
vec![1, 2],
|
||||
vec![3],
|
||||
vec![],
|
||||
Default::default()
|
||||
));
|
||||
|
||||
System::set_block_number(1);
|
||||
});
|
||||
@@ -323,10 +352,25 @@ pub fn test_cid() -> Cid {
|
||||
Cid::new_v0(&*result)
|
||||
}
|
||||
|
||||
pub fn make_proposal(value: u64) -> Call {
|
||||
Call::System(frame_system::Call::remark { remark: value.encode() })
|
||||
pub fn make_remark_proposal(value: u64) -> (Call, u32, H256) {
|
||||
make_proposal(Call::System(frame_system::Call::remark { remark: value.encode() }))
|
||||
}
|
||||
|
||||
pub fn make_set_rule_proposal(rule: Cid) -> Call {
|
||||
Call::Alliance(pallet_alliance::Call::set_rule { rule })
|
||||
pub fn make_set_rule_proposal(rule: Cid) -> (Call, u32, H256) {
|
||||
make_proposal(Call::Alliance(pallet_alliance::Call::set_rule { rule }))
|
||||
}
|
||||
|
||||
pub fn make_kick_member_proposal(who: u64) -> (Call, u32, H256) {
|
||||
make_proposal(Call::Alliance(pallet_alliance::Call::kick_member { who }))
|
||||
}
|
||||
|
||||
pub fn make_proposal(proposal: Call) -> (Call, u32, H256) {
|
||||
let len: u32 = proposal.using_encoded(|p| p.len() as u32);
|
||||
let hash = BlakeTwo256::hash_of(&proposal);
|
||||
(proposal, len, hash)
|
||||
}
|
||||
|
||||
pub fn assert_prev_event(event: Event) {
|
||||
let events = System::events();
|
||||
assert_eq!(events.get(events.len() - 2).expect("events expected").event, event);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user