|
@@ -0,0 +1,733 @@
|
|
|
+#![cfg(test)]
|
|
|
+
|
|
|
+pub(crate) use crate::Module as Utilities;
|
|
|
+use crate::*;
|
|
|
+use common::working_group::{WorkingGroup, WorkingGroupBudgetHandler};
|
|
|
+use frame_support::dispatch::DispatchError;
|
|
|
+use frame_support::traits::{LockIdentifier, OnFinalize, OnInitialize};
|
|
|
+use frame_support::{impl_outer_event, impl_outer_origin, parameter_types};
|
|
|
+use frame_system::RawOrigin;
|
|
|
+use frame_system::{EnsureOneOf, EnsureRoot, EnsureSigned};
|
|
|
+use sp_core::H256;
|
|
|
+use sp_runtime::DispatchResult;
|
|
|
+use sp_runtime::{
|
|
|
+ testing::Header,
|
|
|
+ traits::{BlakeTwo256, IdentityLookup},
|
|
|
+ Perbill,
|
|
|
+};
|
|
|
+use staking_handler::{LockComparator, StakingManager};
|
|
|
+
|
|
|
+impl_outer_origin! {
|
|
|
+ pub enum Origin for Test {}
|
|
|
+}
|
|
|
+
|
|
|
+mod utilities {
|
|
|
+ pub use crate::Event;
|
|
|
+}
|
|
|
+
|
|
|
+impl_outer_event! {
|
|
|
+ pub enum TestEvent for Test {
|
|
|
+ utilities<T>,
|
|
|
+ frame_system<T>,
|
|
|
+ balances<T>,
|
|
|
+ council<T>,
|
|
|
+ membership<T>,
|
|
|
+ referendum Instance0 <T>,
|
|
|
+ working_group Instance0 <T>,
|
|
|
+ working_group Instance1 <T>,
|
|
|
+ working_group Instance2 <T>,
|
|
|
+ working_group Instance3 <T>,
|
|
|
+ working_group Instance4 <T>,
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+pub struct ReferendumWeightInfo;
|
|
|
+impl referendum::WeightInfo for ReferendumWeightInfo {
|
|
|
+ fn on_initialize_revealing(_: u32) -> Weight {
|
|
|
+ 0
|
|
|
+ }
|
|
|
+ fn on_initialize_voting() -> Weight {
|
|
|
+ 0
|
|
|
+ }
|
|
|
+ fn vote() -> Weight {
|
|
|
+ 0
|
|
|
+ }
|
|
|
+ fn reveal_vote_space_for_new_winner(_: u32) -> Weight {
|
|
|
+ 0
|
|
|
+ }
|
|
|
+ fn reveal_vote_space_not_in_winners(_: u32) -> Weight {
|
|
|
+ 0
|
|
|
+ }
|
|
|
+ fn reveal_vote_space_replace_last_winner(_: u32) -> Weight {
|
|
|
+ 0
|
|
|
+ }
|
|
|
+ fn reveal_vote_already_existing(_: u32) -> Weight {
|
|
|
+ 0
|
|
|
+ }
|
|
|
+ fn release_vote_stake() -> Weight {
|
|
|
+ 0
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+#[derive(Clone, PartialEq, Eq, Debug)]
|
|
|
+pub struct Test;
|
|
|
+
|
|
|
+parameter_types! {
|
|
|
+ pub const ExistentialDeposit: u32 = 0;
|
|
|
+}
|
|
|
+
|
|
|
+impl balances::Trait for Test {
|
|
|
+ type Balance = u64;
|
|
|
+ type DustRemoval = ();
|
|
|
+ type Event = TestEvent;
|
|
|
+ type ExistentialDeposit = ExistentialDeposit;
|
|
|
+ type AccountStore = System;
|
|
|
+ type WeightInfo = ();
|
|
|
+ type MaxLocks = ();
|
|
|
+}
|
|
|
+
|
|
|
+parameter_types! {
|
|
|
+ pub const BlockHashCount: u64 = 250;
|
|
|
+ pub const MaximumBlockWeight: u32 = 1024;
|
|
|
+ pub const MaximumBlockLength: u32 = 2 * 1024;
|
|
|
+ pub const AvailableBlockRatio: Perbill = Perbill::one();
|
|
|
+}
|
|
|
+
|
|
|
+macro_rules! call_wg {
|
|
|
+ ($working_group:ident<$T:ty>, $function:ident $(,$x:expr)*) => {{
|
|
|
+ match $working_group {
|
|
|
+ WorkingGroup::Content =>
|
|
|
+ <working_group::Module::<$T, ContentDirectoryWorkingGroupInstance> as WorkingGroupBudgetHandler<Test>>::$function($($x,)*),
|
|
|
+
|
|
|
+ WorkingGroup::Storage =>
|
|
|
+ <working_group::Module::<$T, StorageWorkingGroupInstance> as WorkingGroupBudgetHandler<Test>>::$function($($x,)*),
|
|
|
+
|
|
|
+ WorkingGroup::Forum =>
|
|
|
+ <working_group::Module::<$T, ForumWorkingGroupInstance> as WorkingGroupBudgetHandler<Test>>::$function($($x,)*),
|
|
|
+
|
|
|
+ WorkingGroup::Membership =>
|
|
|
+ <working_group::Module::<$T, MembershipWorkingGroupInstance> as WorkingGroupBudgetHandler<Test>>::$function($($x,)*),
|
|
|
+ }
|
|
|
+ }};
|
|
|
+}
|
|
|
+
|
|
|
+// The forum working group instance alias.
|
|
|
+pub type ForumWorkingGroupInstance = working_group::Instance1;
|
|
|
+
|
|
|
+// The storage working group instance alias.
|
|
|
+pub type StorageWorkingGroupInstance = working_group::Instance2;
|
|
|
+
|
|
|
+// The content directory working group instance alias.
|
|
|
+pub type ContentDirectoryWorkingGroupInstance = working_group::Instance3;
|
|
|
+
|
|
|
+// The membership working group instance alias.
|
|
|
+pub type MembershipWorkingGroupInstance = working_group::Instance4;
|
|
|
+
|
|
|
+impl frame_system::Trait for Test {
|
|
|
+ type BaseCallFilter = ();
|
|
|
+ type Origin = Origin;
|
|
|
+ type Call = ();
|
|
|
+ type Index = u64;
|
|
|
+ type BlockNumber = u64;
|
|
|
+ type Hash = H256;
|
|
|
+ type Hashing = BlakeTwo256;
|
|
|
+ type AccountId = u64;
|
|
|
+ type Lookup = IdentityLookup<Self::AccountId>;
|
|
|
+ type Header = Header;
|
|
|
+ type Event = TestEvent;
|
|
|
+ type BlockHashCount = BlockHashCount;
|
|
|
+ type MaximumBlockWeight = MaximumBlockWeight;
|
|
|
+ type DbWeight = ();
|
|
|
+ type BlockExecutionWeight = ();
|
|
|
+ type ExtrinsicBaseWeight = ();
|
|
|
+ type MaximumExtrinsicWeight = ();
|
|
|
+ type MaximumBlockLength = MaximumBlockLength;
|
|
|
+ type AvailableBlockRatio = AvailableBlockRatio;
|
|
|
+ type Version = ();
|
|
|
+ type AccountData = balances::AccountData<u64>;
|
|
|
+ type OnNewAccount = ();
|
|
|
+ type OnKilledAccount = ();
|
|
|
+ type PalletInfo = ();
|
|
|
+ type SystemWeightInfo = ();
|
|
|
+}
|
|
|
+
|
|
|
+impl Trait for Test {
|
|
|
+ type Event = TestEvent;
|
|
|
+
|
|
|
+ type WeightInfo = ();
|
|
|
+
|
|
|
+ fn get_working_group_budget(working_group: WorkingGroup) -> BalanceOf<Test> {
|
|
|
+ call_wg!(working_group<Test>, get_budget)
|
|
|
+ }
|
|
|
+
|
|
|
+ fn set_working_group_budget(working_group: WorkingGroup, budget: BalanceOf<Test>) {
|
|
|
+ call_wg!(working_group<Test>, set_budget, budget)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+impl WeightInfo for () {
|
|
|
+ fn execute_signal_proposal(_: u32) -> Weight {
|
|
|
+ 0
|
|
|
+ }
|
|
|
+ fn update_working_group_budget_positive_forum() -> Weight {
|
|
|
+ 0
|
|
|
+ }
|
|
|
+ fn update_working_group_budget_negative_forum() -> Weight {
|
|
|
+ 0
|
|
|
+ }
|
|
|
+ fn update_working_group_budget_positive_storage() -> Weight {
|
|
|
+ 0
|
|
|
+ }
|
|
|
+ fn update_working_group_budget_negative_storage() -> Weight {
|
|
|
+ 0
|
|
|
+ }
|
|
|
+ fn update_working_group_budget_positive_content() -> Weight {
|
|
|
+ 0
|
|
|
+ }
|
|
|
+ fn update_working_group_budget_negative_content() -> Weight {
|
|
|
+ 0
|
|
|
+ }
|
|
|
+ fn update_working_group_budget_positive_membership() -> Weight {
|
|
|
+ 0
|
|
|
+ }
|
|
|
+ fn update_working_group_budget_negative_membership() -> Weight {
|
|
|
+ 0
|
|
|
+ }
|
|
|
+ fn burn_account_tokens() -> Weight {
|
|
|
+ 0
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+parameter_types! {
|
|
|
+ pub const MinimumPeriod: u64 = 5;
|
|
|
+}
|
|
|
+
|
|
|
+impl pallet_timestamp::Trait for Test {
|
|
|
+ type Moment = u64;
|
|
|
+ type OnTimestampSet = ();
|
|
|
+ type MinimumPeriod = MinimumPeriod;
|
|
|
+ type WeightInfo = ();
|
|
|
+}
|
|
|
+
|
|
|
+parameter_types! {
|
|
|
+ pub const DefaultMembershipPrice: u64 = 100;
|
|
|
+ pub const InvitedMemberLockId: [u8; 8] = [2; 8];
|
|
|
+}
|
|
|
+
|
|
|
+impl membership::Trait for Test {
|
|
|
+ type Event = TestEvent;
|
|
|
+ type DefaultMembershipPrice = DefaultMembershipPrice;
|
|
|
+ type WorkingGroup = ();
|
|
|
+ type WeightInfo = Weights;
|
|
|
+ type DefaultInitialInvitationBalance = ();
|
|
|
+ type InvitedMemberStakingHandler = staking_handler::StakingManager<Self, InvitedMemberLockId>;
|
|
|
+}
|
|
|
+
|
|
|
+impl common::working_group::WorkingGroupBudgetHandler<Test> for () {
|
|
|
+ fn get_budget() -> u64 {
|
|
|
+ unimplemented!()
|
|
|
+ }
|
|
|
+
|
|
|
+ fn set_budget(_new_value: u64) {
|
|
|
+ unimplemented!()
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+impl common::working_group::WorkingGroupAuthenticator<Test> for () {
|
|
|
+ fn ensure_worker_origin(
|
|
|
+ _origin: <Test as frame_system::Trait>::Origin,
|
|
|
+ _worker_id: &<Test as common::Trait>::ActorId,
|
|
|
+ ) -> DispatchResult {
|
|
|
+ unimplemented!();
|
|
|
+ }
|
|
|
+
|
|
|
+ fn ensure_leader_origin(_origin: <Test as frame_system::Trait>::Origin) -> DispatchResult {
|
|
|
+ unimplemented!()
|
|
|
+ }
|
|
|
+
|
|
|
+ fn get_leader_member_id() -> Option<<Test as common::Trait>::MemberId> {
|
|
|
+ unimplemented!();
|
|
|
+ }
|
|
|
+
|
|
|
+ fn is_leader_account_id(_account_id: &<Test as frame_system::Trait>::AccountId) -> bool {
|
|
|
+ unimplemented!()
|
|
|
+ }
|
|
|
+
|
|
|
+ fn is_worker_account_id(
|
|
|
+ _account_id: &<Test as frame_system::Trait>::AccountId,
|
|
|
+ _worker_id: &<Test as common::Trait>::ActorId,
|
|
|
+ ) -> bool {
|
|
|
+ unimplemented!()
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+pub struct Weights;
|
|
|
+impl membership::WeightInfo for Weights {
|
|
|
+ fn buy_membership_without_referrer(_: u32, _: u32, _: u32, _: u32) -> Weight {
|
|
|
+ unimplemented!()
|
|
|
+ }
|
|
|
+ fn buy_membership_with_referrer(_: u32, _: u32, _: u32, _: u32) -> Weight {
|
|
|
+ unimplemented!()
|
|
|
+ }
|
|
|
+ fn update_profile(_: u32) -> Weight {
|
|
|
+ unimplemented!()
|
|
|
+ }
|
|
|
+ fn update_accounts_none() -> Weight {
|
|
|
+ unimplemented!()
|
|
|
+ }
|
|
|
+ fn update_accounts_root() -> Weight {
|
|
|
+ unimplemented!()
|
|
|
+ }
|
|
|
+ fn update_accounts_controller() -> Weight {
|
|
|
+ unimplemented!()
|
|
|
+ }
|
|
|
+ fn update_accounts_both() -> Weight {
|
|
|
+ unimplemented!()
|
|
|
+ }
|
|
|
+ fn set_referral_cut() -> Weight {
|
|
|
+ unimplemented!()
|
|
|
+ }
|
|
|
+ fn transfer_invites() -> Weight {
|
|
|
+ unimplemented!()
|
|
|
+ }
|
|
|
+ fn invite_member(_: u32, _: u32, _: u32, _: u32) -> Weight {
|
|
|
+ unimplemented!()
|
|
|
+ }
|
|
|
+ fn set_membership_price() -> Weight {
|
|
|
+ unimplemented!()
|
|
|
+ }
|
|
|
+ fn update_profile_verification() -> Weight {
|
|
|
+ unimplemented!()
|
|
|
+ }
|
|
|
+ fn set_leader_invitation_quota() -> Weight {
|
|
|
+ unimplemented!()
|
|
|
+ }
|
|
|
+ fn set_initial_invitation_balance() -> Weight {
|
|
|
+ unimplemented!()
|
|
|
+ }
|
|
|
+ fn set_initial_invitation_count() -> Weight {
|
|
|
+ unimplemented!()
|
|
|
+ }
|
|
|
+ fn add_staking_account_candidate() -> Weight {
|
|
|
+ unimplemented!()
|
|
|
+ }
|
|
|
+ fn confirm_staking_account() -> Weight {
|
|
|
+ unimplemented!()
|
|
|
+ }
|
|
|
+ fn remove_staking_account() -> Weight {
|
|
|
+ unimplemented!()
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+parameter_types! {
|
|
|
+ pub const MaxWorkerNumberLimit: u32 = 100;
|
|
|
+ pub const LockId1: [u8; 8] = [1; 8];
|
|
|
+ pub const LockId2: [u8; 8] = [2; 8];
|
|
|
+}
|
|
|
+
|
|
|
+pub struct WorkingGroupWeightInfo;
|
|
|
+impl working_group::Trait<ContentDirectoryWorkingGroupInstance> for Test {
|
|
|
+ type Event = TestEvent;
|
|
|
+ type MaxWorkerNumberLimit = MaxWorkerNumberLimit;
|
|
|
+ type StakingHandler = StakingManager<Self, LockId1>;
|
|
|
+ type StakingAccountValidator = membership::Module<Test>;
|
|
|
+ type MemberOriginValidator = ();
|
|
|
+ type MinUnstakingPeriodLimit = ();
|
|
|
+ type RewardPeriod = ();
|
|
|
+ type WeightInfo = WorkingGroupWeightInfo;
|
|
|
+}
|
|
|
+
|
|
|
+impl working_group::WeightInfo for WorkingGroupWeightInfo {
|
|
|
+ fn on_initialize_leaving(_: u32) -> Weight {
|
|
|
+ 0
|
|
|
+ }
|
|
|
+ fn on_initialize_rewarding_with_missing_reward(_: u32) -> Weight {
|
|
|
+ 0
|
|
|
+ }
|
|
|
+ fn on_initialize_rewarding_with_missing_reward_cant_pay(_: u32) -> Weight {
|
|
|
+ 0
|
|
|
+ }
|
|
|
+ fn on_initialize_rewarding_without_missing_reward(_: u32) -> Weight {
|
|
|
+ 0
|
|
|
+ }
|
|
|
+ fn apply_on_opening(_: u32) -> Weight {
|
|
|
+ 0
|
|
|
+ }
|
|
|
+ fn fill_opening_lead() -> Weight {
|
|
|
+ 0
|
|
|
+ }
|
|
|
+ fn fill_opening_worker(_: u32) -> Weight {
|
|
|
+ 0
|
|
|
+ }
|
|
|
+ fn update_role_account() -> Weight {
|
|
|
+ 0
|
|
|
+ }
|
|
|
+ fn cancel_opening() -> Weight {
|
|
|
+ 0
|
|
|
+ }
|
|
|
+ fn withdraw_application() -> Weight {
|
|
|
+ 0
|
|
|
+ }
|
|
|
+ fn slash_stake(_: u32) -> Weight {
|
|
|
+ 0
|
|
|
+ }
|
|
|
+ fn terminate_role_worker(_: u32) -> Weight {
|
|
|
+ 0
|
|
|
+ }
|
|
|
+ fn terminate_role_lead(_: u32) -> Weight {
|
|
|
+ 0
|
|
|
+ }
|
|
|
+ fn increase_stake() -> Weight {
|
|
|
+ 0
|
|
|
+ }
|
|
|
+ fn decrease_stake() -> Weight {
|
|
|
+ 0
|
|
|
+ }
|
|
|
+ fn spend_from_budget() -> Weight {
|
|
|
+ 0
|
|
|
+ }
|
|
|
+ fn update_reward_amount() -> Weight {
|
|
|
+ 0
|
|
|
+ }
|
|
|
+ fn set_status_text(_: u32) -> Weight {
|
|
|
+ 0
|
|
|
+ }
|
|
|
+ fn update_reward_account() -> Weight {
|
|
|
+ 0
|
|
|
+ }
|
|
|
+ fn set_budget() -> Weight {
|
|
|
+ 0
|
|
|
+ }
|
|
|
+ fn add_opening(_: u32) -> Weight {
|
|
|
+ 0
|
|
|
+ }
|
|
|
+ fn leave_role_immediatly() -> Weight {
|
|
|
+ 0
|
|
|
+ }
|
|
|
+ fn leave_role_later() -> Weight {
|
|
|
+ 0
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+impl working_group::Trait<StorageWorkingGroupInstance> for Test {
|
|
|
+ type Event = TestEvent;
|
|
|
+ type MaxWorkerNumberLimit = MaxWorkerNumberLimit;
|
|
|
+ type StakingHandler = StakingManager<Self, LockId2>;
|
|
|
+ type StakingAccountValidator = membership::Module<Test>;
|
|
|
+ type MemberOriginValidator = ();
|
|
|
+ type MinUnstakingPeriodLimit = ();
|
|
|
+ type RewardPeriod = ();
|
|
|
+ type WeightInfo = WorkingGroupWeightInfo;
|
|
|
+}
|
|
|
+
|
|
|
+impl working_group::Trait<ForumWorkingGroupInstance> for Test {
|
|
|
+ type Event = TestEvent;
|
|
|
+ type MaxWorkerNumberLimit = MaxWorkerNumberLimit;
|
|
|
+ type StakingHandler = staking_handler::StakingManager<Self, LockId2>;
|
|
|
+ type StakingAccountValidator = membership::Module<Test>;
|
|
|
+ type MemberOriginValidator = ();
|
|
|
+ type MinUnstakingPeriodLimit = ();
|
|
|
+ type RewardPeriod = ();
|
|
|
+ type WeightInfo = WorkingGroupWeightInfo;
|
|
|
+}
|
|
|
+
|
|
|
+impl working_group::Trait<MembershipWorkingGroupInstance> for Test {
|
|
|
+ type Event = TestEvent;
|
|
|
+ type MaxWorkerNumberLimit = MaxWorkerNumberLimit;
|
|
|
+ type StakingHandler = StakingManager<Self, LockId2>;
|
|
|
+ type StakingAccountValidator = membership::Module<Test>;
|
|
|
+ type MemberOriginValidator = ();
|
|
|
+ type MinUnstakingPeriodLimit = ();
|
|
|
+ type RewardPeriod = ();
|
|
|
+ type WeightInfo = WorkingGroupWeightInfo;
|
|
|
+}
|
|
|
+
|
|
|
+parameter_types! {
|
|
|
+ pub const MinNumberOfExtraCandidates: u64 = 1;
|
|
|
+ pub const AnnouncingPeriodDuration: u64 = 15;
|
|
|
+ pub const IdlePeriodDuration: u64 = 27;
|
|
|
+ pub const CouncilSize: u64 = 3;
|
|
|
+ pub const MinCandidateStake: u64 = 11000;
|
|
|
+ pub const CandidacyLockId: LockIdentifier = *b"council1";
|
|
|
+ pub const CouncilorLockId: LockIdentifier = *b"council2";
|
|
|
+ pub const ElectedMemberRewardPeriod: u64 = 10;
|
|
|
+ pub const BudgetRefillAmount: u64 = 1000;
|
|
|
+ // intentionally high number that prevents side-effecting tests other than budget refill tests
|
|
|
+ pub const BudgetRefillPeriod: u64 = 1000;
|
|
|
+}
|
|
|
+
|
|
|
+pub struct CouncilWeightInfo;
|
|
|
+impl council::WeightInfo for CouncilWeightInfo {
|
|
|
+ fn try_process_budget() -> Weight {
|
|
|
+ 0
|
|
|
+ }
|
|
|
+ fn try_progress_stage_idle() -> Weight {
|
|
|
+ 0
|
|
|
+ }
|
|
|
+ fn try_progress_stage_announcing_start_election(_: u32) -> Weight {
|
|
|
+ 0
|
|
|
+ }
|
|
|
+ fn try_progress_stage_announcing_restart() -> Weight {
|
|
|
+ 0
|
|
|
+ }
|
|
|
+ fn announce_candidacy() -> Weight {
|
|
|
+ 0
|
|
|
+ }
|
|
|
+ fn release_candidacy_stake() -> Weight {
|
|
|
+ 0
|
|
|
+ }
|
|
|
+ fn set_candidacy_note(_: u32) -> Weight {
|
|
|
+ 0
|
|
|
+ }
|
|
|
+ fn withdraw_candidacy() -> Weight {
|
|
|
+ 0
|
|
|
+ }
|
|
|
+ fn set_budget() -> Weight {
|
|
|
+ 0
|
|
|
+ }
|
|
|
+ fn plan_budget_refill() -> Weight {
|
|
|
+ 0
|
|
|
+ }
|
|
|
+ fn set_budget_increment() -> Weight {
|
|
|
+ 0
|
|
|
+ }
|
|
|
+ fn set_councilor_reward() -> Weight {
|
|
|
+ 0
|
|
|
+ }
|
|
|
+ fn funding_request(_: u32) -> Weight {
|
|
|
+ 0
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+pub type ReferendumInstance = referendum::Instance0;
|
|
|
+
|
|
|
+parameter_types! {
|
|
|
+ pub const VoteStageDuration: u64 = 19;
|
|
|
+ pub const RevealStageDuration: u64 = 23;
|
|
|
+ pub const MinimumVotingStake: u64 = 10000;
|
|
|
+ pub const MaxSaltLength: u64 = 32; // use some multiple of 8 for ez testing
|
|
|
+ pub const VotingLockId: LockIdentifier = *b"referend";
|
|
|
+ pub const MaxWinnerTargetCount: u64 = 10;
|
|
|
+}
|
|
|
+
|
|
|
+impl referendum::Trait<ReferendumInstance> for Test {
|
|
|
+ type Event = TestEvent;
|
|
|
+
|
|
|
+ type MaxSaltLength = MaxSaltLength;
|
|
|
+
|
|
|
+ type StakingHandler = staking_handler::StakingManager<Self, VotingLockId>;
|
|
|
+ type ManagerOrigin =
|
|
|
+ EnsureOneOf<Self::AccountId, EnsureSigned<Self::AccountId>, EnsureRoot<Self::AccountId>>;
|
|
|
+
|
|
|
+ type VotePower = u64;
|
|
|
+
|
|
|
+ type VoteStageDuration = VoteStageDuration;
|
|
|
+ type RevealStageDuration = RevealStageDuration;
|
|
|
+
|
|
|
+ type MinimumStake = MinimumVotingStake;
|
|
|
+
|
|
|
+ type WeightInfo = ReferendumWeightInfo;
|
|
|
+
|
|
|
+ type MaxWinnerTargetCount = MaxWinnerTargetCount;
|
|
|
+
|
|
|
+ fn calculate_vote_power(
|
|
|
+ _: &<Self as frame_system::Trait>::AccountId,
|
|
|
+ _: &Self::Balance,
|
|
|
+ ) -> Self::VotePower {
|
|
|
+ 1
|
|
|
+ }
|
|
|
+
|
|
|
+ fn can_unlock_vote_stake(
|
|
|
+ _: &referendum::CastVote<Self::Hash, Self::Balance, Self::MemberId>,
|
|
|
+ ) -> bool {
|
|
|
+ true
|
|
|
+ }
|
|
|
+
|
|
|
+ fn process_results(winners: &[referendum::OptionResult<Self::MemberId, Self::VotePower>]) {
|
|
|
+ let tmp_winners: Vec<referendum::OptionResult<Self::MemberId, Self::VotePower>> = winners
|
|
|
+ .iter()
|
|
|
+ .map(|item| referendum::OptionResult {
|
|
|
+ option_id: item.option_id,
|
|
|
+ vote_power: item.vote_power.into(),
|
|
|
+ })
|
|
|
+ .collect();
|
|
|
+ <council::Module<Test> as council::ReferendumConnection<Test>>::recieve_referendum_results(
|
|
|
+ tmp_winners.as_slice(),
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ fn is_valid_option_id(option_index: &u64) -> bool {
|
|
|
+ <council::Module<Test> as council::ReferendumConnection<Test>>::is_valid_candidate_id(
|
|
|
+ option_index,
|
|
|
+ )
|
|
|
+ }
|
|
|
+
|
|
|
+ fn get_option_power(option_id: &u64) -> Self::VotePower {
|
|
|
+ <council::Module<Test> as council::ReferendumConnection<Test>>::get_option_power(option_id)
|
|
|
+ }
|
|
|
+
|
|
|
+ fn increase_option_power(option_id: &u64, amount: &Self::VotePower) {
|
|
|
+ <council::Module<Test> as council::ReferendumConnection<Test>>::increase_option_power(
|
|
|
+ option_id, amount,
|
|
|
+ );
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+pub struct BurnTokensFixture {
|
|
|
+ account_id: u64,
|
|
|
+ account_initial_balance: u64,
|
|
|
+ burn_balance: u64,
|
|
|
+}
|
|
|
+
|
|
|
+impl Default for BurnTokensFixture {
|
|
|
+ fn default() -> Self {
|
|
|
+ BurnTokensFixture {
|
|
|
+ account_id: 0,
|
|
|
+ account_initial_balance: 1_000,
|
|
|
+ burn_balance: 100,
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+impl BurnTokensFixture {
|
|
|
+ pub fn with_account_initial_balance(mut self, balance: u64) -> Self {
|
|
|
+ self.account_initial_balance = balance;
|
|
|
+ self
|
|
|
+ }
|
|
|
+
|
|
|
+ pub fn with_burn_balance(mut self, balance: u64) -> Self {
|
|
|
+ self.burn_balance = balance;
|
|
|
+ self
|
|
|
+ }
|
|
|
+
|
|
|
+ pub fn execute_and_assert(&self, result: DispatchResult) {
|
|
|
+ let initial_balance: u64 = Balances::<Test>::total_issuance();
|
|
|
+
|
|
|
+ let _ = Balances::<Test>::deposit_creating(&self.account_id, self.account_initial_balance);
|
|
|
+ assert_eq!(
|
|
|
+ Balances::<Test>::total_issuance(),
|
|
|
+ initial_balance + self.account_initial_balance
|
|
|
+ );
|
|
|
+ assert_eq!(
|
|
|
+ Balances::<Test>::usable_balance(&self.account_id),
|
|
|
+ self.account_initial_balance
|
|
|
+ );
|
|
|
+ assert_eq!(
|
|
|
+ Utilities::<Test>::burn_account_tokens(
|
|
|
+ RawOrigin::Signed(self.account_id).into(),
|
|
|
+ self.burn_balance
|
|
|
+ ),
|
|
|
+ result
|
|
|
+ );
|
|
|
+ if result.is_ok() {
|
|
|
+ assert_eq!(
|
|
|
+ Balances::<Test>::usable_balance(&self.account_id),
|
|
|
+ self.account_initial_balance - self.burn_balance
|
|
|
+ );
|
|
|
+ assert_eq!(
|
|
|
+ Balances::<Test>::total_issuance(),
|
|
|
+ initial_balance + self.account_initial_balance - self.burn_balance
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+ assert_eq!(
|
|
|
+ Balances::<Test>::usable_balance(&self.account_id),
|
|
|
+ self.account_initial_balance
|
|
|
+ );
|
|
|
+ assert_eq!(
|
|
|
+ Balances::<Test>::total_issuance(),
|
|
|
+ initial_balance + self.account_initial_balance
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+impl council::Trait for Test {
|
|
|
+ type Event = TestEvent;
|
|
|
+
|
|
|
+ type Referendum = referendum::Module<Test, ReferendumInstance>;
|
|
|
+
|
|
|
+ type MinNumberOfExtraCandidates = MinNumberOfExtraCandidates;
|
|
|
+ type CouncilSize = CouncilSize;
|
|
|
+ type AnnouncingPeriodDuration = AnnouncingPeriodDuration;
|
|
|
+ type IdlePeriodDuration = IdlePeriodDuration;
|
|
|
+ type MinCandidateStake = MinCandidateStake;
|
|
|
+
|
|
|
+ type CandidacyLock = StakingManager<Self, CandidacyLockId>;
|
|
|
+ type CouncilorLock = StakingManager<Self, CouncilorLockId>;
|
|
|
+
|
|
|
+ type ElectedMemberRewardPeriod = ElectedMemberRewardPeriod;
|
|
|
+
|
|
|
+ type BudgetRefillPeriod = BudgetRefillPeriod;
|
|
|
+
|
|
|
+ type StakingAccountValidator = ();
|
|
|
+ type WeightInfo = CouncilWeightInfo;
|
|
|
+
|
|
|
+ fn new_council_elected(_: &[council::CouncilMemberOf<Self>]) {}
|
|
|
+
|
|
|
+ type MemberOriginValidator = ();
|
|
|
+}
|
|
|
+
|
|
|
+impl common::StakingAccountValidator<Test> for () {
|
|
|
+ fn is_member_staking_account(_: &u64, _: &u64) -> bool {
|
|
|
+ true
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+impl common::origin::MemberOriginValidator<Origin, u64, u64> for () {
|
|
|
+ fn ensure_member_controller_account_origin(
|
|
|
+ origin: Origin,
|
|
|
+ _: u64,
|
|
|
+ ) -> Result<u64, DispatchError> {
|
|
|
+ let account_id = frame_system::ensure_signed(origin)?;
|
|
|
+
|
|
|
+ Ok(account_id)
|
|
|
+ }
|
|
|
+
|
|
|
+ fn is_member_controller_account(member_id: &u64, account_id: &u64) -> bool {
|
|
|
+ member_id == account_id
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+impl common::origin::CouncilOriginValidator<Origin, u64, u64> for () {
|
|
|
+ fn ensure_member_consulate(origin: Origin, _: u64) -> DispatchResult {
|
|
|
+ frame_system::ensure_signed(origin)?;
|
|
|
+
|
|
|
+ Ok(())
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+impl common::Trait for Test {
|
|
|
+ type MemberId = u64;
|
|
|
+ type ActorId = u64;
|
|
|
+}
|
|
|
+
|
|
|
+impl LockComparator<<Test as balances::Trait>::Balance> for Test {
|
|
|
+ fn are_locks_conflicting(
|
|
|
+ _new_lock: &LockIdentifier,
|
|
|
+ _existing_locks: &[LockIdentifier],
|
|
|
+ ) -> bool {
|
|
|
+ false
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+pub fn initial_test_ext() -> sp_io::TestExternalities {
|
|
|
+ let t = frame_system::GenesisConfig::default()
|
|
|
+ .build_storage::<Test>()
|
|
|
+ .unwrap();
|
|
|
+
|
|
|
+ let mut result = Into::<sp_io::TestExternalities>::into(t.clone());
|
|
|
+
|
|
|
+ // Make sure we are not in block 1 where no events are emitted
|
|
|
+ // see https://substrate.dev/recipes/2-appetizers/4-events.html#emitting-events
|
|
|
+ result.execute_with(|| {
|
|
|
+ let mut block_number = frame_system::Module::<Test>::block_number();
|
|
|
+ <System as OnFinalize<u64>>::on_finalize(block_number);
|
|
|
+ block_number = block_number + 1;
|
|
|
+ System::set_block_number(block_number);
|
|
|
+ <System as OnInitialize<u64>>::on_initialize(block_number);
|
|
|
+ });
|
|
|
+
|
|
|
+ result
|
|
|
+}
|
|
|
+
|
|
|
+pub type System = frame_system::Module<Test>;
|