|
@@ -2,19 +2,22 @@
|
|
|
|
|
|
#![cfg(test)]
|
|
|
|
|
|
-use crate::{BlockNumber, ProposalCancellationFee, Runtime};
|
|
|
+use crate::{BlockNumber, ElectionParameters, ProposalCancellationFee, Runtime};
|
|
|
use codec::Encode;
|
|
|
use governance::election::CouncilElected;
|
|
|
use membership::members;
|
|
|
+use membership::role_types::Role;
|
|
|
use proposals_engine::{
|
|
|
ActiveStake, ApprovedProposalStatus, BalanceOf, Error, FinalizationData, Proposal,
|
|
|
ProposalDecisionStatus, ProposalParameters, ProposalStatus, VoteKind, VotersParameters,
|
|
|
VotingResults,
|
|
|
};
|
|
|
+use roles::actors::RoleParameters;
|
|
|
+
|
|
|
use sr_primitives::traits::{DispatchResult, OnFinalize, OnInitialize};
|
|
|
use sr_primitives::AccountId32;
|
|
|
use srml_support::traits::Currency;
|
|
|
-use srml_support::StorageLinkedMap;
|
|
|
+use srml_support::{StorageLinkedMap, StorageMap, StorageValue};
|
|
|
use system::RawOrigin;
|
|
|
|
|
|
use crate::CouncilManager;
|
|
@@ -32,7 +35,9 @@ type System = system::Module<Runtime>;
|
|
|
type Membership = membership::members::Module<Runtime>;
|
|
|
type ProposalsEngine = proposals_engine::Module<Runtime>;
|
|
|
type Council = governance::council::Module<Runtime>;
|
|
|
+type Election = governance::election::Module<Runtime>;
|
|
|
type ProposalCodex = proposals_codex::Module<Runtime>;
|
|
|
+type Mint = minting::Module<Runtime>;
|
|
|
|
|
|
fn setup_members(count: u8) {
|
|
|
let authority_account_id = <Runtime as system::Trait>::AccountId::default();
|
|
@@ -396,6 +401,7 @@ where
|
|
|
SuccessfulCall: Fn() -> DispatchResult<proposals_codex::Error>,
|
|
|
{
|
|
|
successful_call: SuccessfulCall,
|
|
|
+ member_id: u64,
|
|
|
}
|
|
|
|
|
|
impl<SuccessfulCall> CodexProposalTestFixture<SuccessfulCall>
|
|
@@ -406,8 +412,7 @@ where
|
|
|
setup_members(15);
|
|
|
setup_council();
|
|
|
|
|
|
- let member_id = 10;
|
|
|
- let account_id: [u8; 32] = [member_id; 32];
|
|
|
+ let account_id: [u8; 32] = [self.member_id as u8; 32];
|
|
|
increase_total_balance_issuance_using_account_id(account_id.clone().into(), 500000);
|
|
|
|
|
|
assert_eq!((self.successful_call)(), Ok(()));
|
|
@@ -450,6 +455,7 @@ fn text_proposal_execution_succeeds() {
|
|
|
let account_id: [u8; 32] = [member_id; 32];
|
|
|
|
|
|
let codex_extrinsic_test_fixture = CodexProposalTestFixture {
|
|
|
+ member_id: member_id as u64,
|
|
|
successful_call: || {
|
|
|
ProposalCodex::create_text_proposal(
|
|
|
RawOrigin::Signed(account_id.into()).into(),
|
|
@@ -473,6 +479,7 @@ fn set_lead_proposal_execution_succeeds() {
|
|
|
let account_id: [u8; 32] = [member_id; 32];
|
|
|
|
|
|
let codex_extrinsic_test_fixture = CodexProposalTestFixture {
|
|
|
+ member_id: member_id as u64,
|
|
|
successful_call: || {
|
|
|
ProposalCodex::create_set_lead_proposal(
|
|
|
RawOrigin::Signed(account_id.clone().into()).into(),
|
|
@@ -505,6 +512,7 @@ fn spending_proposal_execution_succeeds() {
|
|
|
assert!(Council::set_council_mint_capacity(RawOrigin::Root.into(), new_balance).is_ok());
|
|
|
|
|
|
let codex_extrinsic_test_fixture = CodexProposalTestFixture {
|
|
|
+ member_id: member_id as u64,
|
|
|
successful_call: || {
|
|
|
ProposalCodex::create_spending_proposal(
|
|
|
RawOrigin::Signed(account_id.clone().into()).into(),
|
|
@@ -531,3 +539,191 @@ fn spending_proposal_execution_succeeds() {
|
|
|
);
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
+#[test]
|
|
|
+fn set_content_working_group_mint_capacity_execution_succeeds() {
|
|
|
+ initial_test_ext().execute_with(|| {
|
|
|
+ let member_id = 1;
|
|
|
+ let account_id: [u8; 32] = [member_id; 32];
|
|
|
+ let new_balance = <BalanceOf<Runtime>>::from(55u32);
|
|
|
+
|
|
|
+ let mint_id =
|
|
|
+ Mint::add_mint(0, None).expect("Failed to create a mint for the content working group");
|
|
|
+ <content_working_group::Mint<Runtime>>::put(mint_id);
|
|
|
+
|
|
|
+ assert_eq!(Mint::get_mint_capacity(mint_id), Ok(0));
|
|
|
+
|
|
|
+ let codex_extrinsic_test_fixture = CodexProposalTestFixture {
|
|
|
+ member_id: member_id as u64,
|
|
|
+ successful_call: || {
|
|
|
+ ProposalCodex::create_set_content_working_group_mint_capacity_proposal(
|
|
|
+ RawOrigin::Signed(account_id.clone().into()).into(),
|
|
|
+ member_id as u64,
|
|
|
+ b"title".to_vec(),
|
|
|
+ b"body".to_vec(),
|
|
|
+ Some(<BalanceOf<Runtime>>::from(1250u32)),
|
|
|
+ new_balance,
|
|
|
+ )
|
|
|
+ },
|
|
|
+ };
|
|
|
+
|
|
|
+ codex_extrinsic_test_fixture.call_extrinsic_and_assert();
|
|
|
+
|
|
|
+ assert_eq!(Mint::get_mint_capacity(mint_id), Ok(new_balance));
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+#[test]
|
|
|
+fn set_election_parameters_proposal_execution_succeeds() {
|
|
|
+ initial_test_ext().execute_with(|| {
|
|
|
+ let member_id = 1;
|
|
|
+ let account_id: [u8; 32] = [member_id; 32];
|
|
|
+
|
|
|
+ let election_parameters = ElectionParameters {
|
|
|
+ announcing_period: 14400,
|
|
|
+ voting_period: 14400,
|
|
|
+ revealing_period: 14400,
|
|
|
+ council_size: 4,
|
|
|
+ candidacy_limit: 25,
|
|
|
+ new_term_duration: 14400,
|
|
|
+ min_council_stake: 1,
|
|
|
+ min_voting_stake: 1,
|
|
|
+ };
|
|
|
+ assert_eq!(Election::announcing_period(), 0);
|
|
|
+
|
|
|
+ let codex_extrinsic_test_fixture = CodexProposalTestFixture {
|
|
|
+ member_id: member_id as u64,
|
|
|
+ successful_call: || {
|
|
|
+ ProposalCodex::create_set_election_parameters_proposal(
|
|
|
+ RawOrigin::Signed(account_id.clone().into()).into(),
|
|
|
+ member_id as u64,
|
|
|
+ b"title".to_vec(),
|
|
|
+ b"body".to_vec(),
|
|
|
+ Some(<BalanceOf<Runtime>>::from(3750u32)),
|
|
|
+ election_parameters,
|
|
|
+ )
|
|
|
+ },
|
|
|
+ };
|
|
|
+ codex_extrinsic_test_fixture.call_extrinsic_and_assert();
|
|
|
+
|
|
|
+ assert_eq!(Election::announcing_period(), 14400);
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+#[test]
|
|
|
+fn evict_storage_provider_proposal_execution_succeeds() {
|
|
|
+ initial_test_ext().execute_with(|| {
|
|
|
+ let member_id = 1;
|
|
|
+ let account_id: [u8; 32] = [member_id; 32];
|
|
|
+
|
|
|
+ let target_member_id = 3;
|
|
|
+ let target_account: [u8; 32] = [target_member_id; 32];
|
|
|
+ let target_account_id: AccountId32 = target_account.into();
|
|
|
+
|
|
|
+ <roles::actors::Parameters<Runtime>>::insert(
|
|
|
+ Role::StorageProvider,
|
|
|
+ roles::actors::RoleParameters::default(),
|
|
|
+ );
|
|
|
+
|
|
|
+ <roles::actors::AccountIdsByRole<Runtime>>::insert(
|
|
|
+ Role::StorageProvider,
|
|
|
+ vec![target_account_id.clone()],
|
|
|
+ );
|
|
|
+
|
|
|
+ <roles::actors::ActorByAccountId<Runtime>>::insert(
|
|
|
+ target_account_id.clone(),
|
|
|
+ roles::actors::Actor {
|
|
|
+ member_id: target_member_id as u64,
|
|
|
+ role: Role::StorageProvider,
|
|
|
+ account: target_account_id,
|
|
|
+ joined_at: 1,
|
|
|
+ },
|
|
|
+ );
|
|
|
+
|
|
|
+ let codex_extrinsic_test_fixture = CodexProposalTestFixture {
|
|
|
+ member_id: member_id as u64,
|
|
|
+ successful_call: || {
|
|
|
+ ProposalCodex::create_evict_storage_provider_proposal(
|
|
|
+ RawOrigin::Signed(account_id.clone().into()).into(),
|
|
|
+ member_id as u64,
|
|
|
+ b"title".to_vec(),
|
|
|
+ b"body".to_vec(),
|
|
|
+ Some(<BalanceOf<Runtime>>::from(500u32)),
|
|
|
+ target_account.into(),
|
|
|
+ )
|
|
|
+ },
|
|
|
+ };
|
|
|
+ codex_extrinsic_test_fixture.call_extrinsic_and_assert();
|
|
|
+
|
|
|
+ assert_eq!(
|
|
|
+ <roles::actors::AccountIdsByRole<Runtime>>::get(Role::StorageProvider),
|
|
|
+ Vec::new()
|
|
|
+ );
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+#[test]
|
|
|
+fn set_storage_role_parameters_proposal_execution_succeeds() {
|
|
|
+ initial_test_ext().execute_with(|| {
|
|
|
+ let member_id = 1;
|
|
|
+ let account_id: [u8; 32] = [member_id; 32];
|
|
|
+
|
|
|
+ <roles::actors::Parameters<Runtime>>::insert(
|
|
|
+ Role::StorageProvider,
|
|
|
+ RoleParameters::default(),
|
|
|
+ );
|
|
|
+
|
|
|
+ let target_role_parameters = RoleParameters {
|
|
|
+ startup_grace_period: 700,
|
|
|
+ ..RoleParameters::default()
|
|
|
+ };
|
|
|
+
|
|
|
+ let codex_extrinsic_test_fixture = CodexProposalTestFixture {
|
|
|
+ member_id: member_id as u64,
|
|
|
+ successful_call: || {
|
|
|
+ ProposalCodex::create_set_storage_role_parameters_proposal(
|
|
|
+ RawOrigin::Signed(account_id.clone().into()).into(),
|
|
|
+ member_id as u64,
|
|
|
+ b"title".to_vec(),
|
|
|
+ b"body".to_vec(),
|
|
|
+ Some(<BalanceOf<Runtime>>::from(1250u32)),
|
|
|
+ target_role_parameters.clone(),
|
|
|
+ )
|
|
|
+ },
|
|
|
+ };
|
|
|
+ codex_extrinsic_test_fixture.call_extrinsic_and_assert();
|
|
|
+
|
|
|
+ assert_eq!(
|
|
|
+ <roles::actors::Parameters<Runtime>>::get(Role::StorageProvider),
|
|
|
+ Some(target_role_parameters)
|
|
|
+ );
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+#[test]
|
|
|
+fn set_validator_count_proposal_execution_succeeds() {
|
|
|
+ initial_test_ext().execute_with(|| {
|
|
|
+ let member_id = 1;
|
|
|
+ let account_id: [u8; 32] = [member_id; 32];
|
|
|
+
|
|
|
+ let new_validator_count = 8;
|
|
|
+ assert_eq!(<staking::ValidatorCount>::get(), 0);
|
|
|
+
|
|
|
+ let codex_extrinsic_test_fixture = CodexProposalTestFixture {
|
|
|
+ member_id: member_id as u64,
|
|
|
+ successful_call: || {
|
|
|
+ ProposalCodex::create_set_validator_count_proposal(
|
|
|
+ RawOrigin::Signed(account_id.clone().into()).into(),
|
|
|
+ member_id as u64,
|
|
|
+ b"title".to_vec(),
|
|
|
+ b"body".to_vec(),
|
|
|
+ Some(<BalanceOf<Runtime>>::from(1250u32)),
|
|
|
+ new_validator_count,
|
|
|
+ )
|
|
|
+ },
|
|
|
+ };
|
|
|
+ codex_extrinsic_test_fixture.call_extrinsic_and_assert();
|
|
|
+
|
|
|
+ assert_eq!(<staking::ValidatorCount>::get(), new_validator_count);
|
|
|
+ });
|
|
|
+}
|