mock.rs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980
  1. #![cfg(test)]
  2. use frame_support::traits::{LockIdentifier, OnFinalize, OnInitialize};
  3. use frame_support::{
  4. impl_outer_dispatch, impl_outer_event, impl_outer_origin, parameter_types, weights::Weight,
  5. };
  6. pub use frame_system;
  7. use frame_system::{EnsureOneOf, EnsureRoot, EnsureSigned};
  8. use sp_core::H256;
  9. use sp_runtime::curve::PiecewiseLinear;
  10. use sp_runtime::{
  11. testing::Header,
  12. traits::{BlakeTwo256, IdentityLookup},
  13. DispatchResult, Perbill,
  14. };
  15. use sp_staking::SessionIndex;
  16. use staking_handler::{LockComparator, StakingManager};
  17. use crate::BalanceOf;
  18. use crate::{ProposalDetailsOf, ProposalEncoder, ProposalParameters};
  19. use common::working_group::{WorkingGroup, WorkingGroupBudgetHandler};
  20. use frame_support::dispatch::DispatchError;
  21. use proposals_engine::VotersParameters;
  22. use sp_runtime::testing::TestXt;
  23. impl_outer_origin! {
  24. pub enum Origin for Test {}
  25. }
  26. // Workaround for https://github.com/rust-lang/rust/issues/26925 . Remove when sorted.
  27. #[derive(Clone, PartialEq, Eq, Debug)]
  28. pub struct Test;
  29. parameter_types! {
  30. pub const BlockHashCount: u64 = 250;
  31. pub const MaximumBlockWeight: u32 = 1024;
  32. pub const MaximumBlockLength: u32 = 2 * 1024;
  33. pub const AvailableBlockRatio: Perbill = Perbill::one();
  34. pub const MinimumPeriod: u64 = 5;
  35. pub const InvitedMemberLockId: [u8; 8] = [2; 8];
  36. }
  37. mod proposals_codex_mod {
  38. pub use crate::Event;
  39. }
  40. impl_outer_event! {
  41. pub enum TestEvent for Test {
  42. proposals_codex_mod<T>,
  43. frame_system<T>,
  44. balances<T>,
  45. staking<T>,
  46. council<T>,
  47. proposals_discussion<T>,
  48. proposals_engine<T>,
  49. referendum Instance0 <T>,
  50. membership<T>,
  51. working_group Instance0 <T>,
  52. working_group Instance1 <T>,
  53. working_group Instance2 <T>,
  54. working_group Instance3 <T>,
  55. working_group Instance4 <T>,
  56. }
  57. }
  58. impl_outer_dispatch! {
  59. pub enum Call for Test where origin: Origin {
  60. codex::ProposalCodex,
  61. proposals::ProposalsEngine,
  62. staking::Staking,
  63. frame_system::System,
  64. }
  65. }
  66. impl common::Trait for Test {
  67. type MemberId = u64;
  68. type ActorId = u64;
  69. }
  70. // Weights info stub
  71. pub struct Weights;
  72. impl membership::WeightInfo for Weights {
  73. fn buy_membership_without_referrer(_: u32, _: u32, _: u32, _: u32) -> Weight {
  74. unimplemented!()
  75. }
  76. fn buy_membership_with_referrer(_: u32, _: u32, _: u32, _: u32) -> Weight {
  77. unimplemented!()
  78. }
  79. fn update_profile(_: u32) -> Weight {
  80. unimplemented!()
  81. }
  82. fn update_accounts_none() -> Weight {
  83. unimplemented!()
  84. }
  85. fn update_accounts_root() -> Weight {
  86. unimplemented!()
  87. }
  88. fn update_accounts_controller() -> Weight {
  89. unimplemented!()
  90. }
  91. fn update_accounts_both() -> Weight {
  92. unimplemented!()
  93. }
  94. fn set_referral_cut() -> Weight {
  95. unimplemented!()
  96. }
  97. fn transfer_invites() -> Weight {
  98. unimplemented!()
  99. }
  100. fn invite_member(_: u32, _: u32, _: u32, _: u32) -> Weight {
  101. unimplemented!()
  102. }
  103. fn set_membership_price() -> Weight {
  104. unimplemented!()
  105. }
  106. fn update_profile_verification() -> Weight {
  107. unimplemented!()
  108. }
  109. fn set_leader_invitation_quota() -> Weight {
  110. unimplemented!()
  111. }
  112. fn set_initial_invitation_balance() -> Weight {
  113. unimplemented!()
  114. }
  115. fn set_initial_invitation_count() -> Weight {
  116. unimplemented!()
  117. }
  118. fn add_staking_account_candidate() -> Weight {
  119. unimplemented!()
  120. }
  121. fn confirm_staking_account() -> Weight {
  122. unimplemented!()
  123. }
  124. fn remove_staking_account() -> Weight {
  125. unimplemented!()
  126. }
  127. }
  128. impl membership::Trait for Test {
  129. type Event = TestEvent;
  130. type DefaultMembershipPrice = DefaultMembershipPrice;
  131. type WorkingGroup = ();
  132. type WeightInfo = Weights;
  133. type DefaultInitialInvitationBalance = ();
  134. type InvitedMemberStakingHandler = staking_handler::StakingManager<Self, InvitedMemberLockId>;
  135. }
  136. impl common::working_group::WorkingGroupBudgetHandler<Test> for () {
  137. fn get_budget() -> u64 {
  138. unimplemented!()
  139. }
  140. fn set_budget(_new_value: u64) {
  141. unimplemented!()
  142. }
  143. }
  144. impl common::working_group::WorkingGroupAuthenticator<Test> for () {
  145. fn ensure_worker_origin(
  146. _origin: <Test as frame_system::Trait>::Origin,
  147. _worker_id: &<Test as common::Trait>::ActorId,
  148. ) -> DispatchResult {
  149. unimplemented!();
  150. }
  151. fn ensure_leader_origin(_origin: <Test as frame_system::Trait>::Origin) -> DispatchResult {
  152. unimplemented!()
  153. }
  154. fn get_leader_member_id() -> Option<<Test as common::Trait>::MemberId> {
  155. unimplemented!();
  156. }
  157. fn is_leader_account_id(_account_id: &<Test as frame_system::Trait>::AccountId) -> bool {
  158. unimplemented!()
  159. }
  160. fn is_worker_account_id(
  161. _account_id: &<Test as frame_system::Trait>::AccountId,
  162. _worker_id: &<Test as common::Trait>::ActorId,
  163. ) -> bool {
  164. unimplemented!()
  165. }
  166. }
  167. parameter_types! {
  168. pub const DefaultMembershipPrice: u64 = 100;
  169. pub const ExistentialDeposit: u32 = 0;
  170. pub const DefaultInitialInvitationBalance: u64 = 100;
  171. }
  172. impl balances::Trait for Test {
  173. type Balance = u64;
  174. type DustRemoval = ();
  175. type Event = TestEvent;
  176. type ExistentialDeposit = ExistentialDeposit;
  177. type AccountStore = System;
  178. type WeightInfo = ();
  179. type MaxLocks = ();
  180. }
  181. parameter_types! {
  182. pub const CancellationFee: u64 = 5;
  183. pub const RejectionFee: u64 = 3;
  184. pub const TitleMaxLength: u32 = 100;
  185. pub const DescriptionMaxLength: u32 = 10000;
  186. pub const MaxActiveProposalLimit: u32 = 100;
  187. pub const LockId: LockIdentifier = [2; 8];
  188. }
  189. pub struct MockProposalsEngineWeight;
  190. impl proposals_engine::Trait for Test {
  191. type Event = TestEvent;
  192. type ProposerOriginValidator = ();
  193. type CouncilOriginValidator = ();
  194. type TotalVotersCounter = MockVotersParameters;
  195. type ProposalId = u32;
  196. type StakingHandler = StakingManager<Test, LockId>;
  197. type CancellationFee = CancellationFee;
  198. type RejectionFee = RejectionFee;
  199. type TitleMaxLength = TitleMaxLength;
  200. type DescriptionMaxLength = DescriptionMaxLength;
  201. type MaxActiveProposalLimit = MaxActiveProposalLimit;
  202. type DispatchableCallCode = crate::Call<Test>;
  203. type ProposalObserver = crate::Module<Test>;
  204. type WeightInfo = MockProposalsEngineWeight;
  205. }
  206. impl proposals_engine::WeightInfo for MockProposalsEngineWeight {
  207. fn vote(_: u32) -> Weight {
  208. 0
  209. }
  210. fn cancel_proposal() -> Weight {
  211. 0
  212. }
  213. fn veto_proposal() -> Weight {
  214. 0
  215. }
  216. fn on_initialize_immediate_execution_decode_fails(_: u32) -> Weight {
  217. 0
  218. }
  219. fn on_initialize_pending_execution_decode_fails(_: u32) -> Weight {
  220. 0
  221. }
  222. fn on_initialize_approved_pending_constitutionality(_: u32) -> Weight {
  223. 0
  224. }
  225. fn on_initialize_rejected(_: u32) -> Weight {
  226. 0
  227. }
  228. fn on_initialize_slashed(_: u32) -> Weight {
  229. 0
  230. }
  231. fn cancel_active_and_pending_proposals(_: u32) -> u64 {
  232. 0
  233. }
  234. }
  235. impl Default for crate::Call<Test> {
  236. fn default() -> Self {
  237. panic!("shouldn't call default for Call");
  238. }
  239. }
  240. impl common::origin::MemberOriginValidator<Origin, u64, u64> for () {
  241. fn ensure_member_controller_account_origin(
  242. origin: Origin,
  243. _: u64,
  244. ) -> Result<u64, DispatchError> {
  245. let account_id = frame_system::ensure_signed(origin)?;
  246. Ok(account_id)
  247. }
  248. fn is_member_controller_account(member_id: &u64, account_id: &u64) -> bool {
  249. member_id == account_id
  250. }
  251. }
  252. impl common::origin::CouncilOriginValidator<Origin, u64, u64> for () {
  253. fn ensure_member_consulate(origin: Origin, _: u64) -> DispatchResult {
  254. frame_system::ensure_signed(origin)?;
  255. Ok(())
  256. }
  257. }
  258. parameter_types! {
  259. pub const ThreadTitleLengthLimit: u32 = 200;
  260. pub const PostLengthLimit: u32 = 2000;
  261. pub const MaxWhiteListSize: u32 = 20;
  262. }
  263. pub struct MockProposalsDiscussionWeight;
  264. impl proposals_discussion::Trait for Test {
  265. type Event = TestEvent;
  266. type AuthorOriginValidator = ();
  267. type CouncilOriginValidator = ();
  268. type ThreadId = u64;
  269. type PostId = u64;
  270. type MaxWhiteListSize = MaxWhiteListSize;
  271. type WeightInfo = MockProposalsDiscussionWeight;
  272. }
  273. impl proposals_discussion::WeightInfo for MockProposalsDiscussionWeight {
  274. fn add_post(_: u32) -> Weight {
  275. 0
  276. }
  277. fn update_post() -> Weight {
  278. 0
  279. }
  280. fn change_thread_mode(_: u32) -> Weight {
  281. 0
  282. }
  283. }
  284. pub struct MockVotersParameters;
  285. impl VotersParameters for MockVotersParameters {
  286. fn total_voters_count() -> u32 {
  287. 4
  288. }
  289. }
  290. // The forum working group instance alias.
  291. pub type ForumWorkingGroupInstance = working_group::Instance1;
  292. // The storage working group instance alias.
  293. pub type StorageWorkingGroupInstance = working_group::Instance2;
  294. // The content directory working group instance alias.
  295. pub type ContentDirectoryWorkingGroupInstance = working_group::Instance3;
  296. // The membership working group instance alias.
  297. pub type MembershipWorkingGroupInstance = working_group::Instance4;
  298. parameter_types! {
  299. pub const MaxWorkerNumberLimit: u32 = 100;
  300. pub const LockId1: [u8; 8] = [1; 8];
  301. pub const LockId2: [u8; 8] = [2; 8];
  302. }
  303. pub struct WorkingGroupWeightInfo;
  304. impl working_group::Trait<ContentDirectoryWorkingGroupInstance> for Test {
  305. type Event = TestEvent;
  306. type MaxWorkerNumberLimit = MaxWorkerNumberLimit;
  307. type StakingHandler = StakingManager<Self, LockId1>;
  308. type StakingAccountValidator = membership::Module<Test>;
  309. type MemberOriginValidator = ();
  310. type MinUnstakingPeriodLimit = ();
  311. type RewardPeriod = ();
  312. type WeightInfo = WorkingGroupWeightInfo;
  313. }
  314. impl working_group::WeightInfo for WorkingGroupWeightInfo {
  315. fn on_initialize_leaving(_: u32) -> Weight {
  316. 0
  317. }
  318. fn on_initialize_rewarding_with_missing_reward(_: u32) -> Weight {
  319. 0
  320. }
  321. fn on_initialize_rewarding_with_missing_reward_cant_pay(_: u32) -> Weight {
  322. 0
  323. }
  324. fn on_initialize_rewarding_without_missing_reward(_: u32) -> Weight {
  325. 0
  326. }
  327. fn apply_on_opening(_: u32) -> Weight {
  328. 0
  329. }
  330. fn fill_opening_lead() -> Weight {
  331. 0
  332. }
  333. fn fill_opening_worker(_: u32) -> Weight {
  334. 0
  335. }
  336. fn update_role_account() -> Weight {
  337. 0
  338. }
  339. fn cancel_opening() -> Weight {
  340. 0
  341. }
  342. fn withdraw_application() -> Weight {
  343. 0
  344. }
  345. fn slash_stake(_: u32) -> Weight {
  346. 0
  347. }
  348. fn terminate_role_worker(_: u32) -> Weight {
  349. 0
  350. }
  351. fn terminate_role_lead(_: u32) -> Weight {
  352. 0
  353. }
  354. fn increase_stake() -> Weight {
  355. 0
  356. }
  357. fn decrease_stake() -> Weight {
  358. 0
  359. }
  360. fn spend_from_budget() -> Weight {
  361. 0
  362. }
  363. fn update_reward_amount() -> Weight {
  364. 0
  365. }
  366. fn set_status_text(_: u32) -> Weight {
  367. 0
  368. }
  369. fn update_reward_account() -> Weight {
  370. 0
  371. }
  372. fn set_budget() -> Weight {
  373. 0
  374. }
  375. fn add_opening(_: u32) -> Weight {
  376. 0
  377. }
  378. fn leave_role_immediatly() -> Weight {
  379. 0
  380. }
  381. fn leave_role_later() -> Weight {
  382. 0
  383. }
  384. }
  385. impl working_group::Trait<StorageWorkingGroupInstance> for Test {
  386. type Event = TestEvent;
  387. type MaxWorkerNumberLimit = MaxWorkerNumberLimit;
  388. type StakingHandler = StakingManager<Self, LockId2>;
  389. type StakingAccountValidator = membership::Module<Test>;
  390. type MemberOriginValidator = ();
  391. type MinUnstakingPeriodLimit = ();
  392. type RewardPeriod = ();
  393. type WeightInfo = WorkingGroupWeightInfo;
  394. }
  395. impl working_group::Trait<ForumWorkingGroupInstance> for Test {
  396. type Event = TestEvent;
  397. type MaxWorkerNumberLimit = MaxWorkerNumberLimit;
  398. type StakingHandler = staking_handler::StakingManager<Self, LockId2>;
  399. type StakingAccountValidator = membership::Module<Test>;
  400. type MemberOriginValidator = ();
  401. type MinUnstakingPeriodLimit = ();
  402. type RewardPeriod = ();
  403. type WeightInfo = WorkingGroupWeightInfo;
  404. }
  405. impl working_group::Trait<MembershipWorkingGroupInstance> for Test {
  406. type Event = TestEvent;
  407. type MaxWorkerNumberLimit = MaxWorkerNumberLimit;
  408. type StakingHandler = StakingManager<Self, LockId2>;
  409. type StakingAccountValidator = membership::Module<Test>;
  410. type MemberOriginValidator = ();
  411. type MinUnstakingPeriodLimit = ();
  412. type RewardPeriod = ();
  413. type WeightInfo = WorkingGroupWeightInfo;
  414. }
  415. pallet_staking_reward_curve::build! {
  416. const I_NPOS: PiecewiseLinear<'static> = curve!(
  417. min_inflation: 0_025_000,
  418. max_inflation: 0_100_000,
  419. ideal_stake: 0_500_000,
  420. falloff: 0_050_000,
  421. max_piece_count: 40,
  422. test_precision: 0_005_000,
  423. );
  424. }
  425. parameter_types! {
  426. pub const SessionsPerEra: SessionIndex = 3;
  427. pub const BondingDuration: staking::EraIndex = 3;
  428. pub const RewardCurve: &'static PiecewiseLinear<'static> = &I_NPOS;
  429. }
  430. impl staking::Trait for Test {
  431. type Currency = Balances;
  432. type UnixTime = Timestamp;
  433. type CurrencyToVote = ();
  434. type RewardRemainder = ();
  435. type Event = TestEvent;
  436. type Slash = ();
  437. type Reward = ();
  438. type SessionsPerEra = SessionsPerEra;
  439. type BondingDuration = BondingDuration;
  440. type SlashDeferDuration = ();
  441. type SlashCancelOrigin = frame_system::EnsureRoot<Self::AccountId>;
  442. type SessionInterface = Self;
  443. type RewardCurve = RewardCurve;
  444. type NextNewSession = ();
  445. type ElectionLookahead = ();
  446. type Call = Call;
  447. type MaxIterations = ();
  448. type MinSolutionScoreBump = ();
  449. type MaxNominatorRewardedPerValidator = ();
  450. type UnsignedPriority = ();
  451. type WeightInfo = ();
  452. }
  453. impl<LocalCall> frame_system::offchain::SendTransactionTypes<LocalCall> for Test
  454. where
  455. Call: From<LocalCall>,
  456. {
  457. type OverarchingCall = Call;
  458. type Extrinsic = Extrinsic;
  459. }
  460. pub type Extrinsic = TestXt<Call, ()>;
  461. impl staking::SessionInterface<u64> for Test {
  462. fn disable_validator(_: &u64) -> Result<bool, ()> {
  463. unimplemented!()
  464. }
  465. fn validators() -> Vec<u64> {
  466. unimplemented!()
  467. }
  468. fn prune_historical_up_to(_: u32) {
  469. unimplemented!()
  470. }
  471. }
  472. parameter_types! {
  473. pub DefaultProposalParameters: ProposalParameters<u64, u64> = default_proposal_parameters();
  474. }
  475. pub(crate) fn default_proposal_parameters() -> ProposalParameters<u64, u64> {
  476. ProposalParameters {
  477. voting_period: 43200,
  478. grace_period: 0,
  479. approval_quorum_percentage: 66,
  480. approval_threshold_percentage: 80,
  481. slashing_quorum_percentage: 60,
  482. slashing_threshold_percentage: 80,
  483. required_stake: Some(100_000),
  484. constitutionality: 1,
  485. }
  486. }
  487. macro_rules! call_wg {
  488. ($working_group:ident<$T:ty>, $function:ident $(,$x:expr)*) => {{
  489. match $working_group {
  490. WorkingGroup::Content =>
  491. <working_group::Module::<$T, ContentDirectoryWorkingGroupInstance> as WorkingGroupBudgetHandler<Test>>::$function($($x,)*),
  492. WorkingGroup::Storage =>
  493. <working_group::Module::<$T, StorageWorkingGroupInstance> as WorkingGroupBudgetHandler<Test>>::$function($($x,)*),
  494. WorkingGroup::Forum =>
  495. <working_group::Module::<$T, ForumWorkingGroupInstance> as WorkingGroupBudgetHandler<Test>>::$function($($x,)*),
  496. WorkingGroup::Membership =>
  497. <working_group::Module::<$T, MembershipWorkingGroupInstance> as WorkingGroupBudgetHandler<Test>>::$function($($x,)*),
  498. }
  499. }};
  500. }
  501. impl crate::Trait for Test {
  502. type Event = TestEvent;
  503. type MembershipOriginValidator = ();
  504. type ProposalEncoder = ();
  505. type WeightInfo = ();
  506. type SetMaxValidatorCountProposalParameters = DefaultProposalParameters;
  507. type RuntimeUpgradeProposalParameters = DefaultProposalParameters;
  508. type SignalProposalParameters = DefaultProposalParameters;
  509. type FundingRequestProposalParameters = DefaultProposalParameters;
  510. type CreateWorkingGroupLeadOpeningProposalParameters = DefaultProposalParameters;
  511. type FillWorkingGroupLeadOpeningProposalParameters = DefaultProposalParameters;
  512. type UpdateWorkingGroupBudgetProposalParameters = DefaultProposalParameters;
  513. type DecreaseWorkingGroupLeadStakeProposalParameters = DefaultProposalParameters;
  514. type SlashWorkingGroupLeadProposalParameters = DefaultProposalParameters;
  515. type SetWorkingGroupLeadRewardProposalParameters = DefaultProposalParameters;
  516. type TerminateWorkingGroupLeadProposalParameters = DefaultProposalParameters;
  517. type AmendConstitutionProposalParameters = DefaultProposalParameters;
  518. type CancelWorkingGroupLeadOpeningProposalParameters = DefaultProposalParameters;
  519. type SetMembershipPriceProposalParameters = DefaultProposalParameters;
  520. type SetCouncilBudgetIncrementProposalParameters = DefaultProposalParameters;
  521. type SetCouncilorRewardProposalParameters = DefaultProposalParameters;
  522. type SetInitialInvitationBalanceProposalParameters = DefaultProposalParameters;
  523. type SetInvitationCountProposalParameters = DefaultProposalParameters;
  524. type SetMembershipLeadInvitationQuotaProposalParameters = DefaultProposalParameters;
  525. type SetReferralCutProposalParameters = DefaultProposalParameters;
  526. type CreateBlogPostProposalParameters = DefaultProposalParameters;
  527. type EditBlogPostProoposalParamters = DefaultProposalParameters;
  528. type LockBlogPostProposalParameters = DefaultProposalParameters;
  529. type UnlockBlogPostProposalParameters = DefaultProposalParameters;
  530. type VetoProposalProposalParameters = DefaultProposalParameters;
  531. fn get_working_group_budget(working_group: WorkingGroup) -> BalanceOf<Test> {
  532. call_wg!(working_group<Test>, get_budget)
  533. }
  534. fn set_working_group_budget(working_group: WorkingGroup, budget: BalanceOf<Test>) {
  535. call_wg!(working_group<Test>, set_budget, budget)
  536. }
  537. }
  538. parameter_types! {
  539. pub const MinNumberOfExtraCandidates: u64 = 1;
  540. pub const AnnouncingPeriodDuration: u64 = 15;
  541. pub const IdlePeriodDuration: u64 = 27;
  542. pub const CouncilSize: u64 = 3;
  543. pub const MinCandidateStake: u64 = 11000;
  544. pub const CandidacyLockId: LockIdentifier = *b"council1";
  545. pub const CouncilorLockId: LockIdentifier = *b"council2";
  546. pub const ElectedMemberRewardPeriod: u64 = 10;
  547. pub const BudgetRefillAmount: u64 = 1000;
  548. // intentionally high number that prevents side-effecting tests other than budget refill tests
  549. pub const BudgetRefillPeriod: u64 = 1000;
  550. }
  551. pub type ReferendumInstance = referendum::Instance0;
  552. impl council::Trait for Test {
  553. type Event = TestEvent;
  554. type Referendum = referendum::Module<Test, ReferendumInstance>;
  555. type MinNumberOfExtraCandidates = MinNumberOfExtraCandidates;
  556. type CouncilSize = CouncilSize;
  557. type AnnouncingPeriodDuration = AnnouncingPeriodDuration;
  558. type IdlePeriodDuration = IdlePeriodDuration;
  559. type MinCandidateStake = MinCandidateStake;
  560. type CandidacyLock = StakingManager<Self, CandidacyLockId>;
  561. type CouncilorLock = StakingManager<Self, CouncilorLockId>;
  562. type ElectedMemberRewardPeriod = ElectedMemberRewardPeriod;
  563. type BudgetRefillPeriod = BudgetRefillPeriod;
  564. type StakingAccountValidator = ();
  565. type WeightInfo = CouncilWeightInfo;
  566. fn new_council_elected(_: &[council::CouncilMemberOf<Self>]) {}
  567. type MemberOriginValidator = ();
  568. }
  569. impl common::StakingAccountValidator<Test> for () {
  570. fn is_member_staking_account(_: &u64, _: &u64) -> bool {
  571. true
  572. }
  573. }
  574. pub struct CouncilWeightInfo;
  575. impl council::WeightInfo for CouncilWeightInfo {
  576. fn try_process_budget() -> Weight {
  577. 0
  578. }
  579. fn try_progress_stage_idle() -> Weight {
  580. 0
  581. }
  582. fn try_progress_stage_announcing_start_election(_: u32) -> Weight {
  583. 0
  584. }
  585. fn try_progress_stage_announcing_restart() -> Weight {
  586. 0
  587. }
  588. fn announce_candidacy() -> Weight {
  589. 0
  590. }
  591. fn release_candidacy_stake() -> Weight {
  592. 0
  593. }
  594. fn set_candidacy_note(_: u32) -> Weight {
  595. 0
  596. }
  597. fn withdraw_candidacy() -> Weight {
  598. 0
  599. }
  600. fn set_budget() -> Weight {
  601. 0
  602. }
  603. fn plan_budget_refill() -> Weight {
  604. 0
  605. }
  606. fn set_budget_increment() -> Weight {
  607. 0
  608. }
  609. fn set_councilor_reward() -> Weight {
  610. 0
  611. }
  612. fn funding_request(_: u32) -> Weight {
  613. 0
  614. }
  615. }
  616. parameter_types! {
  617. pub const VoteStageDuration: u64 = 19;
  618. pub const RevealStageDuration: u64 = 23;
  619. pub const MinimumVotingStake: u64 = 10000;
  620. pub const MaxSaltLength: u64 = 32; // use some multiple of 8 for ez testing
  621. pub const VotingLockId: LockIdentifier = *b"referend";
  622. pub const MaxWinnerTargetCount: u64 = 10;
  623. }
  624. impl referendum::Trait<ReferendumInstance> for Test {
  625. type Event = TestEvent;
  626. type MaxSaltLength = MaxSaltLength;
  627. type StakingHandler = staking_handler::StakingManager<Self, VotingLockId>;
  628. type ManagerOrigin =
  629. EnsureOneOf<Self::AccountId, EnsureSigned<Self::AccountId>, EnsureRoot<Self::AccountId>>;
  630. type VotePower = u64;
  631. type VoteStageDuration = VoteStageDuration;
  632. type RevealStageDuration = RevealStageDuration;
  633. type MinimumStake = MinimumVotingStake;
  634. type WeightInfo = ReferendumWeightInfo;
  635. type MaxWinnerTargetCount = MaxWinnerTargetCount;
  636. fn calculate_vote_power(
  637. _: &<Self as frame_system::Trait>::AccountId,
  638. _: &Self::Balance,
  639. ) -> Self::VotePower {
  640. 1
  641. }
  642. fn can_unlock_vote_stake(
  643. _: &referendum::CastVote<Self::Hash, Self::Balance, Self::MemberId>,
  644. ) -> bool {
  645. true
  646. }
  647. fn process_results(winners: &[referendum::OptionResult<Self::MemberId, Self::VotePower>]) {
  648. let tmp_winners: Vec<referendum::OptionResult<Self::MemberId, Self::VotePower>> = winners
  649. .iter()
  650. .map(|item| referendum::OptionResult {
  651. option_id: item.option_id,
  652. vote_power: item.vote_power.into(),
  653. })
  654. .collect();
  655. <council::Module<Test> as council::ReferendumConnection<Test>>::recieve_referendum_results(
  656. tmp_winners.as_slice(),
  657. );
  658. }
  659. fn is_valid_option_id(option_index: &u64) -> bool {
  660. <council::Module<Test> as council::ReferendumConnection<Test>>::is_valid_candidate_id(
  661. option_index,
  662. )
  663. }
  664. fn get_option_power(option_id: &u64) -> Self::VotePower {
  665. <council::Module<Test> as council::ReferendumConnection<Test>>::get_option_power(option_id)
  666. }
  667. fn increase_option_power(option_id: &u64, amount: &Self::VotePower) {
  668. <council::Module<Test> as council::ReferendumConnection<Test>>::increase_option_power(
  669. option_id, amount,
  670. );
  671. }
  672. }
  673. pub struct ReferendumWeightInfo;
  674. impl referendum::WeightInfo for ReferendumWeightInfo {
  675. fn on_initialize_revealing(_: u32) -> Weight {
  676. 0
  677. }
  678. fn on_initialize_voting() -> Weight {
  679. 0
  680. }
  681. fn vote() -> Weight {
  682. 0
  683. }
  684. fn reveal_vote_space_for_new_winner(_: u32) -> Weight {
  685. 0
  686. }
  687. fn reveal_vote_space_not_in_winners(_: u32) -> Weight {
  688. 0
  689. }
  690. fn reveal_vote_space_replace_last_winner(_: u32) -> Weight {
  691. 0
  692. }
  693. fn reveal_vote_already_existing(_: u32) -> Weight {
  694. 0
  695. }
  696. fn release_vote_stake() -> Weight {
  697. 0
  698. }
  699. }
  700. impl crate::WeightInfo for () {
  701. fn execute_signal_proposal(_: u32) -> Weight {
  702. 0
  703. }
  704. fn create_proposal_signal(_: u32, _: u32, _: u32) -> Weight {
  705. 0
  706. }
  707. fn create_proposal_runtime_upgrade(_: u32, _: u32, _: u32) -> Weight {
  708. 0
  709. }
  710. fn create_proposal_funding_request(_: u32, _: u32) -> Weight {
  711. 0
  712. }
  713. fn create_proposal_set_max_validator_count(_: u32, _: u32) -> Weight {
  714. 0
  715. }
  716. fn create_proposal_create_working_group_lead_opening(_: u32, _: u32, _: u32) -> Weight {
  717. 0
  718. }
  719. fn create_proposal_fill_working_group_lead_opening(_: u32, _: u32) -> Weight {
  720. 0
  721. }
  722. fn create_proposal_update_working_group_budget(_: u32, _: u32) -> Weight {
  723. 0
  724. }
  725. fn create_proposal_decrease_working_group_lead_stake(_: u32, _: u32) -> Weight {
  726. 0
  727. }
  728. fn create_proposal_slash_working_group_lead(_: u32) -> Weight {
  729. 0
  730. }
  731. fn create_proposal_set_working_group_lead_reward(_: u32, _: u32) -> Weight {
  732. 0
  733. }
  734. fn create_proposal_terminate_working_group_lead(_: u32, _: u32) -> Weight {
  735. 0
  736. }
  737. fn create_proposal_amend_constitution(_: u32, _: u32) -> Weight {
  738. 0
  739. }
  740. fn create_proposal_cancel_working_group_lead_opening(_: u32) -> Weight {
  741. 0
  742. }
  743. fn create_proposal_set_membership_price(_: u32, _: u32) -> Weight {
  744. 0
  745. }
  746. fn create_proposal_set_council_budget_increment(_: u32, _: u32) -> Weight {
  747. 0
  748. }
  749. fn create_proposal_set_councilor_reward(_: u32, _: u32) -> Weight {
  750. 0
  751. }
  752. fn create_proposal_set_initial_invitation_balance(_: u32, _: u32) -> Weight {
  753. 0
  754. }
  755. fn create_proposal_set_initial_invitation_count(_: u32, _: u32) -> Weight {
  756. 0
  757. }
  758. fn create_proposal_set_membership_lead_invitation_quota(_: u32) -> Weight {
  759. 0
  760. }
  761. fn create_proposal_set_referral_cut(_: u32, _: u32) -> Weight {
  762. 0
  763. }
  764. fn create_proposal_create_blog_post(_: u32, _: u32, _: u32, _: u32) -> Weight {
  765. 0
  766. }
  767. fn create_proposal_edit_blog_post(_: u32, _: u32, _: u32, _: u32) -> Weight {
  768. 0
  769. }
  770. fn create_proposal_lock_blog_post(_: u32, _: u32) -> Weight {
  771. 0
  772. }
  773. fn create_proposal_unlock_blog_post(_: u32, _: u32) -> Weight {
  774. 0
  775. }
  776. fn create_proposal_veto_proposal(_: u32, _: u32) -> Weight {
  777. 0
  778. }
  779. fn update_working_group_budget_positive_forum() -> Weight {
  780. 0
  781. }
  782. fn update_working_group_budget_negative_forum() -> Weight {
  783. 0
  784. }
  785. fn update_working_group_budget_positive_storage() -> Weight {
  786. 0
  787. }
  788. fn update_working_group_budget_negative_storage() -> Weight {
  789. 0
  790. }
  791. fn update_working_group_budget_positive_content() -> Weight {
  792. 0
  793. }
  794. fn update_working_group_budget_negative_content() -> Weight {
  795. 0
  796. }
  797. fn update_working_group_budget_positive_membership() -> Weight {
  798. 0
  799. }
  800. fn update_working_group_budget_negative_membership() -> Weight {
  801. 0
  802. }
  803. }
  804. impl ProposalEncoder<Test> for () {
  805. fn encode_proposal(_proposal_details: ProposalDetailsOf<Test>) -> Vec<u8> {
  806. Vec::new()
  807. }
  808. }
  809. impl frame_system::Trait for Test {
  810. type BaseCallFilter = ();
  811. type Origin = Origin;
  812. type Call = Call;
  813. type Index = u64;
  814. type BlockNumber = u64;
  815. type Hash = H256;
  816. type Hashing = BlakeTwo256;
  817. type AccountId = u64;
  818. type Lookup = IdentityLookup<Self::AccountId>;
  819. type Header = Header;
  820. type Event = TestEvent;
  821. type BlockHashCount = BlockHashCount;
  822. type MaximumBlockWeight = MaximumBlockWeight;
  823. type DbWeight = ();
  824. type BlockExecutionWeight = ();
  825. type ExtrinsicBaseWeight = ();
  826. type MaximumExtrinsicWeight = ();
  827. type MaximumBlockLength = MaximumBlockLength;
  828. type AvailableBlockRatio = AvailableBlockRatio;
  829. type Version = ();
  830. type PalletInfo = ();
  831. type AccountData = balances::AccountData<u64>;
  832. type OnNewAccount = ();
  833. type OnKilledAccount = ();
  834. type SystemWeightInfo = ();
  835. }
  836. impl pallet_timestamp::Trait for Test {
  837. type Moment = u64;
  838. type OnTimestampSet = ();
  839. type MinimumPeriod = MinimumPeriod;
  840. type WeightInfo = ();
  841. }
  842. impl LockComparator<<Test as balances::Trait>::Balance> for Test {
  843. fn are_locks_conflicting(
  844. _new_lock: &LockIdentifier,
  845. _existing_locks: &[LockIdentifier],
  846. ) -> bool {
  847. false
  848. }
  849. }
  850. pub fn initial_test_ext() -> sp_io::TestExternalities {
  851. let t = frame_system::GenesisConfig::default()
  852. .build_storage::<Test>()
  853. .unwrap();
  854. let mut result = Into::<sp_io::TestExternalities>::into(t.clone());
  855. // Make sure we are not in block 1 where no events are emitted
  856. // see https://substrate.dev/recipes/2-appetizers/4-events.html#emitting-events
  857. result.execute_with(|| {
  858. let mut block_number = frame_system::Module::<Test>::block_number();
  859. <System as OnFinalize<u64>>::on_finalize(block_number);
  860. block_number = block_number + 1;
  861. System::set_block_number(block_number);
  862. <System as OnInitialize<u64>>::on_initialize(block_number);
  863. });
  864. result
  865. }
  866. pub type Staking = staking::Module<Test>;
  867. pub type ProposalCodex = crate::Module<Test>;
  868. pub type ProposalsEngine = proposals_engine::Module<Test>;
  869. pub type Balances = balances::Module<Test>;
  870. pub type Timestamp = pallet_timestamp::Module<Test>;
  871. pub type System = frame_system::Module<Test>;