mock.rs 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. #![cfg(test)]
  2. use frame_support::{impl_outer_dispatch, impl_outer_origin, parameter_types};
  3. use sp_core::H256;
  4. use sp_runtime::curve::PiecewiseLinear;
  5. use sp_runtime::{
  6. testing::Header,
  7. traits::{BlakeTwo256, IdentityLookup},
  8. Perbill,
  9. };
  10. use sp_staking::SessionIndex;
  11. pub use system;
  12. use crate::{ProposalDetailsOf, ProposalEncoder};
  13. use proposals_engine::VotersParameters;
  14. use sp_runtime::testing::TestXt;
  15. impl_outer_origin! {
  16. pub enum Origin for Test {}
  17. }
  18. // Workaround for https://github.com/rust-lang/rust/issues/26925 . Remove when sorted.
  19. #[derive(Clone, PartialEq, Eq, Debug)]
  20. pub struct Test;
  21. parameter_types! {
  22. pub const BlockHashCount: u64 = 250;
  23. pub const MaximumBlockWeight: u32 = 1024;
  24. pub const MaximumBlockLength: u32 = 2 * 1024;
  25. pub const AvailableBlockRatio: Perbill = Perbill::one();
  26. pub const MinimumPeriod: u64 = 5;
  27. pub const StakePoolId: [u8; 8] = *b"joystake";
  28. }
  29. impl_outer_dispatch! {
  30. pub enum Call for Test where origin: Origin {
  31. codex::ProposalCodex,
  32. proposals::ProposalsEngine,
  33. staking::Staking,
  34. system::System,
  35. }
  36. }
  37. impl common::currency::GovernanceCurrency for Test {
  38. type Currency = balances::Module<Self>;
  39. }
  40. parameter_types! {
  41. pub const ScreenedMemberMaxInitialBalance: u64 = 500;
  42. }
  43. impl membership::Trait for Test {
  44. type Event = ();
  45. type MemberId = u64;
  46. type PaidTermId = u64;
  47. type SubscriptionId = u64;
  48. type ActorId = u64;
  49. type ScreenedMemberMaxInitialBalance = ScreenedMemberMaxInitialBalance;
  50. }
  51. parameter_types! {
  52. pub const ExistentialDeposit: u32 = 0;
  53. }
  54. impl balances::Trait for Test {
  55. type Balance = u64;
  56. type DustRemoval = ();
  57. type Event = ();
  58. type ExistentialDeposit = ExistentialDeposit;
  59. type AccountStore = System;
  60. }
  61. impl stake::Trait for Test {
  62. type Currency = Balances;
  63. type StakePoolId = StakePoolId;
  64. type StakingEventsHandler = ();
  65. type StakeId = u64;
  66. type SlashId = u64;
  67. }
  68. parameter_types! {
  69. pub const CancellationFee: u64 = 5;
  70. pub const RejectionFee: u64 = 3;
  71. pub const TitleMaxLength: u32 = 100;
  72. pub const DescriptionMaxLength: u32 = 10000;
  73. pub const MaxActiveProposalLimit: u32 = 100;
  74. }
  75. impl proposals_engine::Trait for Test {
  76. type Event = ();
  77. type ProposerOriginValidator = ();
  78. type VoterOriginValidator = ();
  79. type TotalVotersCounter = MockVotersParameters;
  80. type ProposalId = u32;
  81. type StakeHandlerProvider = proposals_engine::DefaultStakeHandlerProvider;
  82. type CancellationFee = CancellationFee;
  83. type RejectionFee = RejectionFee;
  84. type TitleMaxLength = TitleMaxLength;
  85. type DescriptionMaxLength = DescriptionMaxLength;
  86. type MaxActiveProposalLimit = MaxActiveProposalLimit;
  87. type DispatchableCallCode = crate::Call<Test>;
  88. }
  89. impl Default for crate::Call<Test> {
  90. fn default() -> Self {
  91. panic!("shouldn't call default for Call");
  92. }
  93. }
  94. impl minting::Trait for Test {
  95. type Currency = Balances;
  96. type MintId = u64;
  97. }
  98. impl governance::council::Trait for Test {
  99. type Event = ();
  100. type CouncilTermEnded = ();
  101. }
  102. impl common::origin::ActorOriginValidator<Origin, u64, u64> for () {
  103. fn ensure_actor_origin(origin: Origin, _: u64) -> Result<u64, &'static str> {
  104. let account_id = system::ensure_signed(origin)?;
  105. Ok(account_id)
  106. }
  107. }
  108. parameter_types! {
  109. pub const MaxPostEditionNumber: u32 = 5;
  110. pub const MaxThreadInARowNumber: u32 = 3;
  111. pub const ThreadTitleLengthLimit: u32 = 200;
  112. pub const PostLengthLimit: u32 = 2000;
  113. }
  114. impl proposals_discussion::Trait for Test {
  115. type Event = ();
  116. type PostAuthorOriginValidator = ();
  117. type ThreadId = u64;
  118. type PostId = u64;
  119. type MaxPostEditionNumber = MaxPostEditionNumber;
  120. type ThreadTitleLengthLimit = ThreadTitleLengthLimit;
  121. type PostLengthLimit = PostLengthLimit;
  122. type MaxThreadInARowNumber = MaxThreadInARowNumber;
  123. }
  124. pub struct MockVotersParameters;
  125. impl VotersParameters for MockVotersParameters {
  126. fn total_voters_count() -> u32 {
  127. 4
  128. }
  129. }
  130. parameter_types! {
  131. pub const TextProposalMaxLength: u32 = 20_000;
  132. pub const RuntimeUpgradeWasmProposalMaxLength: u32 = 20_000;
  133. }
  134. impl governance::election::Trait for Test {
  135. type Event = ();
  136. type CouncilElected = ();
  137. }
  138. // The content directory working group instance alias.
  139. pub type ContentDirectoryWorkingGroupInstance = working_group::Instance3;
  140. // The storage working group instance alias.
  141. pub type StorageWorkingGroupInstance = working_group::Instance2;
  142. parameter_types! {
  143. pub const MaxWorkerNumberLimit: u32 = 100;
  144. }
  145. impl working_group::Trait<ContentDirectoryWorkingGroupInstance> for Test {
  146. type Event = ();
  147. type MaxWorkerNumberLimit = MaxWorkerNumberLimit;
  148. }
  149. impl working_group::Trait<StorageWorkingGroupInstance> for Test {
  150. type Event = ();
  151. type MaxWorkerNumberLimit = MaxWorkerNumberLimit;
  152. }
  153. impl recurring_rewards::Trait for Test {
  154. type PayoutStatusHandler = ();
  155. type RecipientId = u64;
  156. type RewardRelationshipId = u64;
  157. }
  158. impl hiring::Trait for Test {
  159. type OpeningId = u64;
  160. type ApplicationId = u64;
  161. type ApplicationDeactivatedHandler = ();
  162. type StakeHandlerProvider = hiring::Module<Self>;
  163. }
  164. pallet_staking_reward_curve::build! {
  165. const I_NPOS: PiecewiseLinear<'static> = curve!(
  166. min_inflation: 0_025_000,
  167. max_inflation: 0_100_000,
  168. ideal_stake: 0_500_000,
  169. falloff: 0_050_000,
  170. max_piece_count: 40,
  171. test_precision: 0_005_000,
  172. );
  173. }
  174. parameter_types! {
  175. pub const SessionsPerEra: SessionIndex = 3;
  176. pub const BondingDuration: staking::EraIndex = 3;
  177. pub const RewardCurve: &'static PiecewiseLinear<'static> = &I_NPOS;
  178. }
  179. impl staking::Trait for Test {
  180. type Currency = Balances;
  181. type UnixTime = Timestamp;
  182. type CurrencyToVote = ();
  183. type RewardRemainder = ();
  184. type Event = ();
  185. type Slash = ();
  186. type Reward = ();
  187. type SessionsPerEra = SessionsPerEra;
  188. type BondingDuration = BondingDuration;
  189. type SlashDeferDuration = ();
  190. type SlashCancelOrigin = system::EnsureRoot<Self::AccountId>;
  191. type SessionInterface = Self;
  192. type RewardCurve = RewardCurve;
  193. type NextNewSession = ();
  194. type ElectionLookahead = ();
  195. type Call = Call;
  196. type MaxIterations = ();
  197. type MinSolutionScoreBump = ();
  198. type MaxNominatorRewardedPerValidator = ();
  199. type UnsignedPriority = ();
  200. }
  201. impl<LocalCall> system::offchain::SendTransactionTypes<LocalCall> for Test
  202. where
  203. Call: From<LocalCall>,
  204. {
  205. type OverarchingCall = Call;
  206. type Extrinsic = Extrinsic;
  207. }
  208. pub type Extrinsic = TestXt<Call, ()>;
  209. impl staking::SessionInterface<u64> for Test {
  210. fn disable_validator(_: &u64) -> Result<bool, ()> {
  211. unimplemented!()
  212. }
  213. fn validators() -> Vec<u64> {
  214. unimplemented!()
  215. }
  216. fn prune_historical_up_to(_: u32) {
  217. unimplemented!()
  218. }
  219. }
  220. impl crate::Trait for Test {
  221. type TextProposalMaxLength = TextProposalMaxLength;
  222. type RuntimeUpgradeWasmProposalMaxLength = RuntimeUpgradeWasmProposalMaxLength;
  223. type MembershipOriginValidator = ();
  224. type ProposalEncoder = ();
  225. }
  226. impl ProposalEncoder<Test> for () {
  227. fn encode_proposal(_proposal_details: ProposalDetailsOf<Test>) -> Vec<u8> {
  228. Vec::new()
  229. }
  230. }
  231. impl system::Trait for Test {
  232. type BaseCallFilter = ();
  233. type Origin = Origin;
  234. type Call = Call;
  235. type Index = u64;
  236. type BlockNumber = u64;
  237. type Hash = H256;
  238. type Hashing = BlakeTwo256;
  239. type AccountId = u64;
  240. type Lookup = IdentityLookup<Self::AccountId>;
  241. type Header = Header;
  242. type Event = ();
  243. type BlockHashCount = BlockHashCount;
  244. type MaximumBlockWeight = MaximumBlockWeight;
  245. type DbWeight = ();
  246. type BlockExecutionWeight = ();
  247. type ExtrinsicBaseWeight = ();
  248. type MaximumExtrinsicWeight = ();
  249. type MaximumBlockLength = MaximumBlockLength;
  250. type AvailableBlockRatio = AvailableBlockRatio;
  251. type Version = ();
  252. type ModuleToIndex = ();
  253. type AccountData = balances::AccountData<u64>;
  254. type OnNewAccount = ();
  255. type OnKilledAccount = ();
  256. }
  257. impl pallet_timestamp::Trait for Test {
  258. type Moment = u64;
  259. type OnTimestampSet = ();
  260. type MinimumPeriod = MinimumPeriod;
  261. }
  262. pub fn initial_test_ext() -> sp_io::TestExternalities {
  263. let t = system::GenesisConfig::default()
  264. .build_storage::<Test>()
  265. .unwrap();
  266. t.into()
  267. }
  268. pub type Staking = staking::Module<Test>;
  269. pub type ProposalCodex = crate::Module<Test>;
  270. pub type ProposalsEngine = proposals_engine::Module<Test>;
  271. pub type Balances = balances::Module<Test>;
  272. pub type Timestamp = pallet_timestamp::Module<Test>;
  273. pub type System = system::Module<Test>;