Skip to content

Commit

Permalink
add GeneralAdminOrRoot to SetMembersOrigin (#2195)
Browse files Browse the repository at this point in the history
* add `GeneralAdminOrRoot` to `SetMembersOrigin`

* repin polkadot

* repin polkadot..
  • Loading branch information
tgmichel authored Apr 4, 2023
1 parent 0fdab72 commit 3949289
Show file tree
Hide file tree
Showing 8 changed files with 655 additions and 271 deletions.
529 changes: 264 additions & 265 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions precompiles/collective/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ impl pallet_collective::Config<pallet_collective::Instance1> for Runtime {
type MaxMembers = ConstU32<100>;
type DefaultVote = pallet_collective::MoreThanMajorityThenPrimeDefaultVote;
type WeightInfo = pallet_collective::weights::SubstrateWeight<Runtime>;
type SetMembersOrigin = frame_system::EnsureRoot<AccountId>;
}

/// Build test externalities, prepopulated with data for testing democracy precompiles
Expand Down
4 changes: 4 additions & 0 deletions runtime/moonbase/src/governance/councils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ impl pallet_collective::Config<CouncilInstance> for Runtime {
type MaxMembers = ConstU32<100>;
type DefaultVote = pallet_collective::MoreThanMajorityThenPrimeDefaultVote;
type WeightInfo = pallet_collective::weights::SubstrateWeight<Runtime>;
type SetMembersOrigin = referenda::GeneralAdminOrRoot;
}

impl pallet_collective::Config<TechCommitteeInstance> for Runtime {
Expand All @@ -51,6 +52,7 @@ impl pallet_collective::Config<TechCommitteeInstance> for Runtime {
type MaxMembers = ConstU32<100>;
type DefaultVote = pallet_collective::MoreThanMajorityThenPrimeDefaultVote;
type WeightInfo = pallet_collective::weights::SubstrateWeight<Runtime>;
type SetMembersOrigin = referenda::GeneralAdminOrRoot;
}

impl pallet_collective::Config<TreasuryCouncilInstance> for Runtime {
Expand All @@ -66,6 +68,7 @@ impl pallet_collective::Config<TreasuryCouncilInstance> for Runtime {
type MaxMembers = ConstU32<9>;
type DefaultVote = pallet_collective::MoreThanMajorityThenPrimeDefaultVote;
type WeightInfo = pallet_collective::weights::SubstrateWeight<Runtime>;
type SetMembersOrigin = referenda::GeneralAdminOrRoot;
}

impl pallet_collective::Config<OpenTechCommitteeInstance> for Runtime {
Expand All @@ -81,4 +84,5 @@ impl pallet_collective::Config<OpenTechCommitteeInstance> for Runtime {
type MaxMembers = ConstU32<100>;
type DefaultVote = pallet_collective::MoreThanMajorityThenPrimeDefaultVote;
type WeightInfo = pallet_collective::weights::SubstrateWeight<Runtime>;
type SetMembersOrigin = referenda::GeneralAdminOrRoot;
}
163 changes: 160 additions & 3 deletions runtime/moonbase/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ use moonbase_runtime::{
asset_config::LocalAssetInstance,
get,
xcm_config::{AssetType, SelfReserve},
AccountId, AssetId, AssetManager, Assets, Balances, CrowdloanRewards, LocalAssets,
ParachainStaking, PolkadotXcm, Precompiles, Runtime, RuntimeBlockWeights, RuntimeCall,
RuntimeEvent, System, TransactionPayment, XTokens, XcmTransactor,
AccountId, AssetId, AssetManager, Assets, Balances, CouncilCollective, CrowdloanRewards,
LocalAssets, OpenTechCommitteeCollective, ParachainStaking, PolkadotXcm, Precompiles, Runtime,
RuntimeBlockWeights, RuntimeCall, RuntimeEvent, System, TechCommitteeCollective,
TransactionPayment, TreasuryCouncilCollective, XTokens, XcmTransactor,
FOREIGN_ASSET_PRECOMPILE_ADDRESS_PREFIX, LOCAL_ASSET_PRECOMPILE_ADDRESS_PREFIX,
};
use polkadot_parachain::primitives::Sibling;
Expand Down Expand Up @@ -314,6 +315,162 @@ fn test_collectives_storage_item_prefixes() {
}
}

#[test]
fn collective_set_members_root_origin_works() {
ExtBuilder::default().build().execute_with(|| {
// CouncilCollective
assert_ok!(CouncilCollective::set_members(
<Runtime as frame_system::Config>::RuntimeOrigin::root(),
vec![AccountId::from(ALICE), AccountId::from(BOB)],
Some(AccountId::from(ALICE)),
2
));
// TechCommitteeCollective
assert_ok!(TechCommitteeCollective::set_members(
<Runtime as frame_system::Config>::RuntimeOrigin::root(),
vec![AccountId::from(ALICE), AccountId::from(BOB)],
Some(AccountId::from(ALICE)),
2
));
// TreasuryCouncilCollective
assert_ok!(TreasuryCouncilCollective::set_members(
<Runtime as frame_system::Config>::RuntimeOrigin::root(),
vec![AccountId::from(ALICE), AccountId::from(BOB)],
Some(AccountId::from(ALICE)),
2
));
// OpenTechCommitteeCollective
assert_ok!(OpenTechCommitteeCollective::set_members(
<Runtime as frame_system::Config>::RuntimeOrigin::root(),
vec![AccountId::from(ALICE), AccountId::from(BOB)],
Some(AccountId::from(ALICE)),
2
));
});
}

#[test]
fn collective_set_members_general_admin_origin_works() {
use moonbase_runtime::{
governance::custom_origins::Origin as CustomOrigin, OriginCaller, Utility,
};

ExtBuilder::default().build().execute_with(|| {
let root_caller = <Runtime as frame_system::Config>::RuntimeOrigin::root();
let alice = AccountId::from(ALICE);

// CouncilCollective
let _ = Utility::dispatch_as(
root_caller.clone(),
Box::new(OriginCaller::Origins(CustomOrigin::GeneralAdmin)),
Box::new(
pallet_collective::Call::<Runtime, pallet_collective::Instance1>::set_members {
new_members: vec![alice, AccountId::from(BOB)],
prime: Some(alice),
old_count: 2,
}
.into(),
),
);
// TechCommitteeCollective
let _ = Utility::dispatch_as(
root_caller.clone(),
Box::new(OriginCaller::Origins(CustomOrigin::GeneralAdmin)),
Box::new(
pallet_collective::Call::<Runtime, pallet_collective::Instance2>::set_members {
new_members: vec![alice, AccountId::from(BOB)],
prime: Some(alice),
old_count: 2,
}
.into(),
),
);
// TreasuryCouncilCollective
let _ = Utility::dispatch_as(
root_caller.clone(),
Box::new(OriginCaller::Origins(CustomOrigin::GeneralAdmin)),
Box::new(
pallet_collective::Call::<Runtime, pallet_collective::Instance3>::set_members {
new_members: vec![alice, AccountId::from(BOB)],
prime: Some(alice),
old_count: 2,
}
.into(),
),
);
// OpenTechCommitteeCollective
let _ = Utility::dispatch_as(
root_caller,
Box::new(OriginCaller::Origins(CustomOrigin::GeneralAdmin)),
Box::new(
pallet_collective::Call::<Runtime, pallet_collective::Instance4>::set_members {
new_members: vec![alice, AccountId::from(BOB)],
prime: Some(alice),
old_count: 2,
}
.into(),
),
);

assert_eq!(
System::events()
.into_iter()
.filter_map(|r| {
match r.event {
RuntimeEvent::Utility(pallet_utility::Event::DispatchedAs { result })
if result.is_ok() =>
{
Some(true)
}
_ => None,
}
})
.collect::<Vec<_>>()
.len(),
4
)
});
}

#[test]
fn collective_set_members_signed_origin_does_not_work() {
let alice = AccountId::from(ALICE);
ExtBuilder::default().build().execute_with(|| {
// CouncilCollective
assert!(CouncilCollective::set_members(
<Runtime as frame_system::Config>::RuntimeOrigin::signed(alice),
vec![alice, AccountId::from(BOB)],
Some(alice),
2
)
.is_err());
// TechCommitteeCollective
assert!(TechCommitteeCollective::set_members(
<Runtime as frame_system::Config>::RuntimeOrigin::signed(alice),
vec![AccountId::from(ALICE), AccountId::from(BOB)],
Some(AccountId::from(ALICE)),
2
)
.is_err());
// TreasuryCouncilCollective
assert!(TreasuryCouncilCollective::set_members(
<Runtime as frame_system::Config>::RuntimeOrigin::signed(alice),
vec![AccountId::from(ALICE), AccountId::from(BOB)],
Some(AccountId::from(ALICE)),
2
)
.is_err());
// OpenTechCommitteeCollective
assert!(OpenTechCommitteeCollective::set_members(
<Runtime as frame_system::Config>::RuntimeOrigin::signed(alice),
vec![AccountId::from(ALICE), AccountId::from(BOB)],
Some(AccountId::from(ALICE)),
2
)
.is_err());
});
}

#[test]
fn verify_pallet_indices() {
fn is_pallet_index<P: 'static>(index: usize) {
Expand Down
3 changes: 3 additions & 0 deletions runtime/moonbeam/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,7 @@ impl pallet_collective::Config<CouncilInstance> for Runtime {
type MaxMembers = ConstU32<100>;
type DefaultVote = pallet_collective::MoreThanMajorityThenPrimeDefaultVote;
type WeightInfo = pallet_collective::weights::SubstrateWeight<Runtime>;
type SetMembersOrigin = EnsureRoot<AccountId>;
}

impl pallet_collective::Config<TechCommitteeInstance> for Runtime {
Expand All @@ -503,6 +504,7 @@ impl pallet_collective::Config<TechCommitteeInstance> for Runtime {
type MaxMembers = ConstU32<100>;
type DefaultVote = pallet_collective::MoreThanMajorityThenPrimeDefaultVote;
type WeightInfo = pallet_collective::weights::SubstrateWeight<Runtime>;
type SetMembersOrigin = EnsureRoot<AccountId>;
}

impl pallet_collective::Config<TreasuryCouncilInstance> for Runtime {
Expand All @@ -518,6 +520,7 @@ impl pallet_collective::Config<TreasuryCouncilInstance> for Runtime {
type MaxMembers = ConstU32<9>;
type DefaultVote = pallet_collective::MoreThanMajorityThenPrimeDefaultVote;
type WeightInfo = pallet_collective::weights::SubstrateWeight<Runtime>;
type SetMembersOrigin = EnsureRoot<AccountId>;
}

// The purpose of this offset is to ensure that a democratic proposal will not apply in the same
Expand Down
63 changes: 61 additions & 2 deletions runtime/moonbeam/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ use moonbeam_runtime::{
asset_config::LocalAssetInstance,
currency::GLMR,
xcm_config::{CurrencyId, SelfReserve, UnitWeightCost},
AccountId, Balances, CrowdloanRewards, ParachainStaking, PolkadotXcm, Precompiles, Runtime,
RuntimeBlockWeights, RuntimeCall, RuntimeEvent, System, XTokens, XcmTransactor,
AccountId, Balances, CouncilCollective, CrowdloanRewards, ParachainStaking, PolkadotXcm,
Precompiles, Runtime, RuntimeBlockWeights, RuntimeCall, RuntimeEvent, System,
TechCommitteeCollective, TreasuryCouncilCollective, XTokens, XcmTransactor,
FOREIGN_ASSET_PRECOMPILE_ADDRESS_PREFIX, LOCAL_ASSET_PRECOMPILE_ADDRESS_PREFIX,
};
use nimbus_primitives::NimbusId;
Expand Down Expand Up @@ -253,6 +254,64 @@ fn test_collectives_storage_item_prefixes() {
}
}

#[test]
fn collective_set_members_root_origin_works() {
ExtBuilder::default().build().execute_with(|| {
// CouncilCollective
assert_ok!(CouncilCollective::set_members(
<Runtime as frame_system::Config>::RuntimeOrigin::root(),
vec![AccountId::from(ALICE), AccountId::from(BOB)],
Some(AccountId::from(ALICE)),
2
));
// TechCommitteeCollective
assert_ok!(TechCommitteeCollective::set_members(
<Runtime as frame_system::Config>::RuntimeOrigin::root(),
vec![AccountId::from(ALICE), AccountId::from(BOB)],
Some(AccountId::from(ALICE)),
2
));
// TreasuryCouncilCollective
assert_ok!(TreasuryCouncilCollective::set_members(
<Runtime as frame_system::Config>::RuntimeOrigin::root(),
vec![AccountId::from(ALICE), AccountId::from(BOB)],
Some(AccountId::from(ALICE)),
2
));
});
}

#[test]
fn collective_set_members_signed_origin_does_not_work() {
let alice = AccountId::from(ALICE);
ExtBuilder::default().build().execute_with(|| {
// CouncilCollective
assert!(CouncilCollective::set_members(
<Runtime as frame_system::Config>::RuntimeOrigin::signed(alice),
vec![alice, AccountId::from(BOB)],
Some(alice),
2
)
.is_err());
// TechCommitteeCollective
assert!(TechCommitteeCollective::set_members(
<Runtime as frame_system::Config>::RuntimeOrigin::signed(alice),
vec![AccountId::from(ALICE), AccountId::from(BOB)],
Some(AccountId::from(ALICE)),
2
)
.is_err());
// TreasuryCouncilCollective
assert!(TreasuryCouncilCollective::set_members(
<Runtime as frame_system::Config>::RuntimeOrigin::signed(alice),
vec![AccountId::from(ALICE), AccountId::from(BOB)],
Some(AccountId::from(ALICE)),
2
)
.is_err());
});
}

#[test]
fn verify_pallet_indices() {
fn is_pallet_index<P: 'static>(index: usize) {
Expand Down
4 changes: 4 additions & 0 deletions runtime/moonriver/src/governance/councils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ impl pallet_collective::Config<CouncilInstance> for Runtime {
type MaxMembers = ConstU32<100>;
type DefaultVote = pallet_collective::MoreThanMajorityThenPrimeDefaultVote;
type WeightInfo = pallet_collective::weights::SubstrateWeight<Runtime>;
type SetMembersOrigin = referenda::GeneralAdminOrRoot;
}

impl pallet_collective::Config<TechCommitteeInstance> for Runtime {
Expand All @@ -51,6 +52,7 @@ impl pallet_collective::Config<TechCommitteeInstance> for Runtime {
type MaxMembers = ConstU32<100>;
type DefaultVote = pallet_collective::MoreThanMajorityThenPrimeDefaultVote;
type WeightInfo = pallet_collective::weights::SubstrateWeight<Runtime>;
type SetMembersOrigin = referenda::GeneralAdminOrRoot;
}

impl pallet_collective::Config<TreasuryCouncilInstance> for Runtime {
Expand All @@ -66,6 +68,7 @@ impl pallet_collective::Config<TreasuryCouncilInstance> for Runtime {
type MaxMembers = ConstU32<9>;
type DefaultVote = pallet_collective::MoreThanMajorityThenPrimeDefaultVote;
type WeightInfo = pallet_collective::weights::SubstrateWeight<Runtime>;
type SetMembersOrigin = referenda::GeneralAdminOrRoot;
}

impl pallet_collective::Config<OpenTechCommitteeInstance> for Runtime {
Expand All @@ -81,4 +84,5 @@ impl pallet_collective::Config<OpenTechCommitteeInstance> for Runtime {
type MaxMembers = ConstU32<100>;
type DefaultVote = pallet_collective::MoreThanMajorityThenPrimeDefaultVote;
type WeightInfo = pallet_collective::weights::SubstrateWeight<Runtime>;
type SetMembersOrigin = referenda::GeneralAdminOrRoot;
}
Loading

0 comments on commit 3949289

Please sign in to comment.