|
@@ -1,9 +1,9 @@
|
|
|
use rstd::marker::PhantomData;
|
|
|
|
|
|
-use proposals_engine::VotersParameters;
|
|
|
use common::origin_validator::ActorOriginValidator;
|
|
|
+use proposals_engine::VotersParameters;
|
|
|
|
|
|
-use super::{MembershipOriginValidator, MemberId};
|
|
|
+use super::{MemberId, MembershipOriginValidator};
|
|
|
|
|
|
/// Handles work with the council.
|
|
|
/// Provides implementations for ActorOriginValidator and VotersParameters.
|
|
@@ -40,25 +40,36 @@ impl<T: governance::council::Trait> VotersParameters for CouncilManager<T> {
|
|
|
|
|
|
#[cfg(test)]
|
|
|
mod tests {
|
|
|
- use crate::tests::mock::{initial_test_ext, Test};
|
|
|
use super::CouncilManager;
|
|
|
- use proposals_engine::VotersParameters;
|
|
|
+ use crate::Runtime;
|
|
|
use common::origin_validator::ActorOriginValidator;
|
|
|
use membership::members::UserInfo;
|
|
|
+ use proposals_engine::VotersParameters;
|
|
|
+ use sr_primitives::AccountId32;
|
|
|
use system::RawOrigin;
|
|
|
|
|
|
- type Membership = membership::members::Module<Test>;
|
|
|
- type Council = governance::council::Module<Test>;
|
|
|
+ type Council = governance::council::Module<Runtime>;
|
|
|
+
|
|
|
+ fn initial_test_ext() -> runtime_io::TestExternalities {
|
|
|
+ let t = system::GenesisConfig::default()
|
|
|
+ .build_storage::<Runtime>()
|
|
|
+ .unwrap();
|
|
|
+
|
|
|
+ t.into()
|
|
|
+ }
|
|
|
+
|
|
|
+ type Membership = membership::members::Module<Runtime>;
|
|
|
+ type ProposalsEngine = proposals_engine::Module<Runtime>;
|
|
|
|
|
|
#[test]
|
|
|
fn council_origin_validator_fails_with_unregistered_member() {
|
|
|
initial_test_ext().execute_with(|| {
|
|
|
- let origin = RawOrigin::Signed(1);
|
|
|
+ let origin = RawOrigin::Signed(AccountId32::default());
|
|
|
let member_id = 1;
|
|
|
let error = "Membership validation failed: cannot find a profile for a member";
|
|
|
|
|
|
let validation_result =
|
|
|
- CouncilManager::<Test>::ensure_actor_origin(origin.into(), member_id);
|
|
|
+ CouncilManager::<Runtime>::ensure_actor_origin(origin.into(), member_id);
|
|
|
|
|
|
assert_eq!(validation_result, Err(error));
|
|
|
});
|
|
@@ -67,17 +78,28 @@ mod tests {
|
|
|
#[test]
|
|
|
fn council_origin_validator_succeeds() {
|
|
|
initial_test_ext().execute_with(|| {
|
|
|
- assert!(Council::set_council(system::RawOrigin::Root.into(), vec![1, 2, 3]).is_ok());
|
|
|
+ let councilor1 = AccountId32::default();
|
|
|
+ let councilor2: [u8; 32] = [2; 32];
|
|
|
+ let councilor3: [u8; 32] = [3; 32];
|
|
|
|
|
|
- let account_id = 1;
|
|
|
- let origin = RawOrigin::Signed(account_id);
|
|
|
- let authority_account_id = 10;
|
|
|
- Membership::set_screening_authority(RawOrigin::Root.into(), authority_account_id)
|
|
|
- .unwrap();
|
|
|
+ assert!(Council::set_council(
|
|
|
+ system::RawOrigin::Root.into(),
|
|
|
+ vec![councilor1, councilor2.into(), councilor3.into()]
|
|
|
+ )
|
|
|
+ .is_ok());
|
|
|
+
|
|
|
+ let account_id = AccountId32::default();
|
|
|
+ let origin = RawOrigin::Signed(account_id.clone());
|
|
|
+ let authority_account_id = AccountId32::default();
|
|
|
+ Membership::set_screening_authority(
|
|
|
+ RawOrigin::Root.into(),
|
|
|
+ authority_account_id.clone(),
|
|
|
+ )
|
|
|
+ .unwrap();
|
|
|
|
|
|
Membership::add_screened_member(
|
|
|
RawOrigin::Signed(authority_account_id).into(),
|
|
|
- account_id,
|
|
|
+ account_id.clone(),
|
|
|
UserInfo {
|
|
|
handle: Some(b"handle".to_vec()),
|
|
|
avatar_uri: None,
|
|
@@ -88,7 +110,7 @@ mod tests {
|
|
|
let member_id = 0; // newly created member_id
|
|
|
|
|
|
let validation_result =
|
|
|
- CouncilManager::<Test>::ensure_actor_origin(origin.into(), member_id);
|
|
|
+ CouncilManager::<Runtime>::ensure_actor_origin(origin.into(), member_id);
|
|
|
|
|
|
assert_eq!(validation_result, Ok(account_id));
|
|
|
});
|
|
@@ -97,16 +119,19 @@ mod tests {
|
|
|
#[test]
|
|
|
fn council_origin_validator_fails_with_incompatible_account_id_and_member_id() {
|
|
|
initial_test_ext().execute_with(|| {
|
|
|
- let account_id = 1;
|
|
|
+ let account_id = AccountId32::default();
|
|
|
let error =
|
|
|
"Membership validation failed: given account doesn't match with profile accounts";
|
|
|
- let authority_account_id = 10;
|
|
|
- Membership::set_screening_authority(RawOrigin::Root.into(), authority_account_id)
|
|
|
- .unwrap();
|
|
|
+ let authority_account_id = AccountId32::default();
|
|
|
+ Membership::set_screening_authority(
|
|
|
+ RawOrigin::Root.into(),
|
|
|
+ authority_account_id.clone(),
|
|
|
+ )
|
|
|
+ .unwrap();
|
|
|
|
|
|
Membership::add_screened_member(
|
|
|
RawOrigin::Signed(authority_account_id).into(),
|
|
|
- account_id,
|
|
|
+ account_id.clone(),
|
|
|
UserInfo {
|
|
|
handle: Some(b"handle".to_vec()),
|
|
|
avatar_uri: None,
|
|
@@ -116,9 +141,9 @@ mod tests {
|
|
|
.unwrap();
|
|
|
let member_id = 0; // newly created member_id
|
|
|
|
|
|
- let invalid_account_id = 2;
|
|
|
- let validation_result = CouncilManager::<Test>::ensure_actor_origin(
|
|
|
- RawOrigin::Signed(invalid_account_id).into(),
|
|
|
+ let invalid_account_id: [u8; 32] = [2; 32];
|
|
|
+ let validation_result = CouncilManager::<Runtime>::ensure_actor_origin(
|
|
|
+ RawOrigin::Signed(invalid_account_id.into()).into(),
|
|
|
member_id,
|
|
|
);
|
|
|
|
|
@@ -129,12 +154,15 @@ mod tests {
|
|
|
#[test]
|
|
|
fn council_origin_validator_fails_with_not_council_account_id() {
|
|
|
initial_test_ext().execute_with(|| {
|
|
|
- let account_id = 1;
|
|
|
- let origin = RawOrigin::Signed(account_id);
|
|
|
+ let account_id = AccountId32::default();
|
|
|
+ let origin = RawOrigin::Signed(account_id.clone());
|
|
|
let error = "Council validation failed: account id doesn't belong to a council member";
|
|
|
- let authority_account_id = 10;
|
|
|
- Membership::set_screening_authority(RawOrigin::Root.into(), authority_account_id)
|
|
|
- .unwrap();
|
|
|
+ let authority_account_id = AccountId32::default();
|
|
|
+ Membership::set_screening_authority(
|
|
|
+ RawOrigin::Root.into(),
|
|
|
+ authority_account_id.clone(),
|
|
|
+ )
|
|
|
+ .unwrap();
|
|
|
|
|
|
Membership::add_screened_member(
|
|
|
RawOrigin::Signed(authority_account_id).into(),
|
|
@@ -149,7 +177,7 @@ mod tests {
|
|
|
let member_id = 0; // newly created member_id
|
|
|
|
|
|
let validation_result =
|
|
|
- CouncilManager::<Test>::ensure_actor_origin(origin.into(), member_id);
|
|
|
+ CouncilManager::<Runtime>::ensure_actor_origin(origin.into(), member_id);
|
|
|
|
|
|
assert_eq!(validation_result, Err(error));
|
|
|
});
|
|
@@ -158,9 +186,22 @@ mod tests {
|
|
|
#[test]
|
|
|
fn council_size_calculation_aka_total_voters_count_succeeds() {
|
|
|
initial_test_ext().execute_with(|| {
|
|
|
- assert!(Council::set_council(system::RawOrigin::Root.into(), vec![1, 2, 3, 7]).is_ok());
|
|
|
+ let councilor1 = AccountId32::default();
|
|
|
+ let councilor2: [u8; 32] = [2; 32];
|
|
|
+ let councilor3: [u8; 32] = [3; 32];
|
|
|
+ let councilor4: [u8; 32] = [4; 32];
|
|
|
+ assert!(Council::set_council(
|
|
|
+ system::RawOrigin::Root.into(),
|
|
|
+ vec![
|
|
|
+ councilor1,
|
|
|
+ councilor2.into(),
|
|
|
+ councilor3.into(),
|
|
|
+ councilor4.into()
|
|
|
+ ]
|
|
|
+ )
|
|
|
+ .is_ok());
|
|
|
|
|
|
- assert_eq!(CouncilManager::<Test>::total_voters_count(), 4)
|
|
|
+ assert_eq!(CouncilManager::<Runtime>::total_voters_count(), 4)
|
|
|
});
|
|
|
}
|
|
|
}
|