mock.rs 26 KB

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