mock.rs 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. #![cfg(test)]
  2. // srml_staking_reward_curve::build! - substrate macro produces a warning.
  3. // TODO: remove after post-Rome substrate upgrade
  4. #![allow(array_into_iter)]
  5. use crate::{ProposalDetailsOf, ProposalEncoder};
  6. pub use primitives::{Blake2Hasher, H256};
  7. use proposal_engine::VotersParameters;
  8. use sr_primitives::curve::PiecewiseLinear;
  9. pub use sr_primitives::{
  10. testing::{Digest, DigestItem, Header, UintAuthorityId},
  11. traits::{BlakeTwo256, Convert, IdentityLookup, OnFinalize},
  12. weights::Weight,
  13. BuildStorage, DispatchError, Perbill,
  14. };
  15. use sr_staking_primitives::SessionIndex;
  16. use srml_support::{impl_outer_dispatch, impl_outer_origin, parameter_types};
  17. pub use system;
  18. impl_outer_origin! {
  19. pub enum Origin for Test {}
  20. }
  21. // Workaround for https://github.com/rust-lang/rust/issues/26925 . Remove when sorted.
  22. #[derive(Clone, PartialEq, Eq, Debug)]
  23. pub struct Test;
  24. parameter_types! {
  25. pub const BlockHashCount: u64 = 250;
  26. pub const MaximumBlockWeight: u32 = 1024;
  27. pub const MaximumBlockLength: u32 = 2 * 1024;
  28. pub const AvailableBlockRatio: Perbill = Perbill::one();
  29. pub const MinimumPeriod: u64 = 5;
  30. pub const StakePoolId: [u8; 8] = *b"joystake";
  31. }
  32. impl_outer_dispatch! {
  33. pub enum Call for Test where origin: Origin {
  34. codex::ProposalCodex,
  35. proposals::ProposalsEngine,
  36. }
  37. }
  38. impl common::currency::GovernanceCurrency for Test {
  39. type Currency = balances::Module<Self>;
  40. }
  41. impl membership::members::Trait for Test {
  42. type Event = ();
  43. type MemberId = u64;
  44. type PaidTermId = u64;
  45. type SubscriptionId = u64;
  46. type ActorId = u64;
  47. type InitialMembersBalance = ();
  48. }
  49. parameter_types! {
  50. pub const ExistentialDeposit: u32 = 0;
  51. pub const TransferFee: u32 = 0;
  52. pub const CreationFee: u32 = 0;
  53. }
  54. impl balances::Trait for Test {
  55. /// The type for recording an account's balance.
  56. type Balance = u64;
  57. /// What to do if an account's free balance gets zeroed.
  58. type OnFreeBalanceZero = ();
  59. /// What to do if a new account is created.
  60. type OnNewAccount = ();
  61. type Event = ();
  62. type DustRemoval = ();
  63. type TransferPayment = ();
  64. type ExistentialDeposit = ExistentialDeposit;
  65. type TransferFee = TransferFee;
  66. type CreationFee = CreationFee;
  67. }
  68. impl stake::Trait for Test {
  69. type Currency = Balances;
  70. type StakePoolId = StakePoolId;
  71. type StakingEventsHandler = ();
  72. type StakeId = u64;
  73. type SlashId = u64;
  74. }
  75. parameter_types! {
  76. pub const CancellationFee: u64 = 5;
  77. pub const RejectionFee: u64 = 3;
  78. pub const TitleMaxLength: u32 = 100;
  79. pub const DescriptionMaxLength: u32 = 10000;
  80. pub const MaxActiveProposalLimit: u32 = 100;
  81. }
  82. impl proposal_engine::Trait for Test {
  83. type Event = ();
  84. type ProposerOriginValidator = ();
  85. type VoterOriginValidator = ();
  86. type TotalVotersCounter = MockVotersParameters;
  87. type ProposalId = u32;
  88. type StakeHandlerProvider = proposal_engine::DefaultStakeHandlerProvider;
  89. type CancellationFee = CancellationFee;
  90. type RejectionFee = RejectionFee;
  91. type TitleMaxLength = TitleMaxLength;
  92. type DescriptionMaxLength = DescriptionMaxLength;
  93. type MaxActiveProposalLimit = MaxActiveProposalLimit;
  94. type DispatchableCallCode = crate::Call<Test>;
  95. }
  96. impl Default for crate::Call<Test> {
  97. fn default() -> Self {
  98. panic!("shouldn't call default for Call");
  99. }
  100. }
  101. impl mint::Trait for Test {
  102. type Currency = Balances;
  103. type MintId = u64;
  104. }
  105. impl governance::council::Trait for Test {
  106. type Event = ();
  107. type CouncilTermEnded = ();
  108. }
  109. impl common::origin::ActorOriginValidator<Origin, u64, u64> for () {
  110. fn ensure_actor_origin(origin: Origin, _: u64) -> Result<u64, &'static str> {
  111. let account_id = system::ensure_signed(origin)?;
  112. Ok(account_id)
  113. }
  114. }
  115. parameter_types! {
  116. pub const MaxPostEditionNumber: u32 = 5;
  117. pub const MaxThreadInARowNumber: u32 = 3;
  118. pub const ThreadTitleLengthLimit: u32 = 200;
  119. pub const PostLengthLimit: u32 = 2000;
  120. }
  121. impl proposal_discussion::Trait for Test {
  122. type Event = ();
  123. type PostAuthorOriginValidator = ();
  124. type ThreadId = u64;
  125. type PostId = u64;
  126. type MaxPostEditionNumber = MaxPostEditionNumber;
  127. type ThreadTitleLengthLimit = ThreadTitleLengthLimit;
  128. type PostLengthLimit = PostLengthLimit;
  129. type MaxThreadInARowNumber = MaxThreadInARowNumber;
  130. }
  131. pub struct MockVotersParameters;
  132. impl VotersParameters for MockVotersParameters {
  133. fn total_voters_count() -> u32 {
  134. 4
  135. }
  136. }
  137. parameter_types! {
  138. pub const TextProposalMaxLength: u32 = 20_000;
  139. pub const RuntimeUpgradeWasmProposalMaxLength: u32 = 20_000;
  140. }
  141. impl governance::election::Trait for Test {
  142. type Event = ();
  143. type CouncilElected = ();
  144. }
  145. impl content_working_group::Trait for Test {
  146. type Event = ();
  147. }
  148. impl recurring_rewards::Trait for Test {
  149. type PayoutStatusHandler = ();
  150. type RecipientId = u64;
  151. type RewardRelationshipId = u64;
  152. }
  153. impl versioned_store_permissions::Trait for Test {
  154. type Credential = u64;
  155. type CredentialChecker = ();
  156. type CreateClassPermissionsChecker = ();
  157. }
  158. impl versioned_store::Trait for Test {
  159. type Event = ();
  160. }
  161. impl hiring::Trait for Test {
  162. type OpeningId = u64;
  163. type ApplicationId = u64;
  164. type ApplicationDeactivatedHandler = ();
  165. type StakeHandlerProvider = hiring::Module<Self>;
  166. }
  167. srml_staking_reward_curve::build! {
  168. const I_NPOS: PiecewiseLinear<'static> = curve!(
  169. min_inflation: 0_025_000,
  170. max_inflation: 0_100_000,
  171. ideal_stake: 0_500_000,
  172. falloff: 0_050_000,
  173. max_piece_count: 40,
  174. test_precision: 0_005_000,
  175. );
  176. }
  177. parameter_types! {
  178. pub const SessionsPerEra: SessionIndex = 3;
  179. pub const BondingDuration: staking::EraIndex = 3;
  180. pub const RewardCurve: &'static PiecewiseLinear<'static> = &I_NPOS;
  181. }
  182. impl staking::Trait for Test {
  183. type Currency = balances::Module<Self>;
  184. type Time = timestamp::Module<Self>;
  185. type CurrencyToVote = ();
  186. type RewardRemainder = ();
  187. type Event = ();
  188. type Slash = ();
  189. type Reward = ();
  190. type SessionsPerEra = SessionsPerEra;
  191. type BondingDuration = BondingDuration;
  192. type SessionInterface = Self;
  193. type RewardCurve = RewardCurve;
  194. }
  195. impl staking::SessionInterface<u64> for Test {
  196. fn disable_validator(_: &u64) -> Result<bool, ()> {
  197. unimplemented!()
  198. }
  199. fn validators() -> Vec<u64> {
  200. unimplemented!()
  201. }
  202. fn prune_historical_up_to(_: u32) {
  203. unimplemented!()
  204. }
  205. }
  206. impl crate::Trait for Test {
  207. type TextProposalMaxLength = TextProposalMaxLength;
  208. type RuntimeUpgradeWasmProposalMaxLength = RuntimeUpgradeWasmProposalMaxLength;
  209. type MembershipOriginValidator = ();
  210. type ProposalEncoder = ();
  211. }
  212. impl ProposalEncoder<Test> for () {
  213. fn encode_proposal(_proposal_details: ProposalDetailsOf<Test>) -> Vec<u8> {
  214. Vec::new()
  215. }
  216. }
  217. impl system::Trait for Test {
  218. type Origin = Origin;
  219. type Index = u64;
  220. type BlockNumber = u64;
  221. type Call = ();
  222. type Hash = H256;
  223. type Hashing = BlakeTwo256;
  224. type AccountId = u64;
  225. type Lookup = IdentityLookup<Self::AccountId>;
  226. type Header = Header;
  227. type Event = ();
  228. type BlockHashCount = BlockHashCount;
  229. type MaximumBlockWeight = MaximumBlockWeight;
  230. type MaximumBlockLength = MaximumBlockLength;
  231. type AvailableBlockRatio = AvailableBlockRatio;
  232. type Version = ();
  233. }
  234. impl timestamp::Trait for Test {
  235. type Moment = u64;
  236. type OnTimestampSet = ();
  237. type MinimumPeriod = MinimumPeriod;
  238. }
  239. pub fn initial_test_ext() -> runtime_io::TestExternalities {
  240. let t = system::GenesisConfig::default()
  241. .build_storage::<Test>()
  242. .unwrap();
  243. t.into()
  244. }
  245. pub type ProposalCodex = crate::Module<Test>;
  246. pub type ProposalsEngine = proposal_engine::Module<Test>;
  247. pub type Balances = balances::Module<Test>;