mock.rs 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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::Trait for Test {
  42. type Event = ();
  43. type MemberId = u64;
  44. type PaidTermId = u64;
  45. type SubscriptionId = u64;
  46. type ActorId = u64;
  47. }
  48. parameter_types! {
  49. pub const ExistentialDeposit: u32 = 0;
  50. pub const TransferFee: u32 = 0;
  51. pub const CreationFee: u32 = 0;
  52. }
  53. impl balances::Trait for Test {
  54. /// The type for recording an account's balance.
  55. type Balance = u64;
  56. /// What to do if an account's free balance gets zeroed.
  57. type OnFreeBalanceZero = ();
  58. /// What to do if a new account is created.
  59. type OnNewAccount = ();
  60. type Event = ();
  61. type DustRemoval = ();
  62. type TransferPayment = ();
  63. type ExistentialDeposit = ExistentialDeposit;
  64. type TransferFee = TransferFee;
  65. type CreationFee = CreationFee;
  66. }
  67. impl stake::Trait for Test {
  68. type Currency = Balances;
  69. type StakePoolId = StakePoolId;
  70. type StakingEventsHandler = ();
  71. type StakeId = u64;
  72. type SlashId = u64;
  73. }
  74. parameter_types! {
  75. pub const CancellationFee: u64 = 5;
  76. pub const RejectionFee: u64 = 3;
  77. pub const TitleMaxLength: u32 = 100;
  78. pub const DescriptionMaxLength: u32 = 10000;
  79. pub const MaxActiveProposalLimit: u32 = 100;
  80. }
  81. impl proposal_engine::Trait for Test {
  82. type Event = ();
  83. type ProposerOriginValidator = ();
  84. type VoterOriginValidator = ();
  85. type TotalVotersCounter = MockVotersParameters;
  86. type ProposalId = u32;
  87. type StakeHandlerProvider = proposal_engine::DefaultStakeHandlerProvider;
  88. type CancellationFee = CancellationFee;
  89. type RejectionFee = RejectionFee;
  90. type TitleMaxLength = TitleMaxLength;
  91. type DescriptionMaxLength = DescriptionMaxLength;
  92. type MaxActiveProposalLimit = MaxActiveProposalLimit;
  93. type DispatchableCallCode = crate::Call<Test>;
  94. }
  95. impl Default for crate::Call<Test> {
  96. fn default() -> Self {
  97. panic!("shouldn't call default for Call");
  98. }
  99. }
  100. impl mint::Trait for Test {
  101. type Currency = Balances;
  102. type MintId = u64;
  103. }
  104. impl governance::council::Trait for Test {
  105. type Event = ();
  106. type CouncilTermEnded = ();
  107. }
  108. impl common::origin::ActorOriginValidator<Origin, u64, u64> for () {
  109. fn ensure_actor_origin(origin: Origin, _: u64) -> Result<u64, &'static str> {
  110. let account_id = system::ensure_signed(origin)?;
  111. Ok(account_id)
  112. }
  113. }
  114. parameter_types! {
  115. pub const MaxPostEditionNumber: u32 = 5;
  116. pub const MaxThreadInARowNumber: u32 = 3;
  117. pub const ThreadTitleLengthLimit: u32 = 200;
  118. pub const PostLengthLimit: u32 = 2000;
  119. }
  120. impl proposal_discussion::Trait for Test {
  121. type Event = ();
  122. type PostAuthorOriginValidator = ();
  123. type ThreadId = u64;
  124. type PostId = u64;
  125. type MaxPostEditionNumber = MaxPostEditionNumber;
  126. type ThreadTitleLengthLimit = ThreadTitleLengthLimit;
  127. type PostLengthLimit = PostLengthLimit;
  128. type MaxThreadInARowNumber = MaxThreadInARowNumber;
  129. }
  130. pub struct MockVotersParameters;
  131. impl VotersParameters for MockVotersParameters {
  132. fn total_voters_count() -> u32 {
  133. 4
  134. }
  135. }
  136. parameter_types! {
  137. pub const TextProposalMaxLength: u32 = 20_000;
  138. pub const RuntimeUpgradeWasmProposalMaxLength: u32 = 20_000;
  139. }
  140. impl governance::election::Trait for Test {
  141. type Event = ();
  142. type CouncilElected = ();
  143. }
  144. impl content_working_group::Trait for Test {
  145. type Event = ();
  146. }
  147. impl recurring_rewards::Trait for Test {
  148. type PayoutStatusHandler = ();
  149. type RecipientId = u64;
  150. type RewardRelationshipId = u64;
  151. }
  152. impl versioned_store_permissions::Trait for Test {
  153. type Credential = u64;
  154. type CredentialChecker = ();
  155. type CreateClassPermissionsChecker = ();
  156. }
  157. impl versioned_store::Trait for Test {
  158. type Event = ();
  159. }
  160. impl hiring::Trait for Test {
  161. type OpeningId = u64;
  162. type ApplicationId = u64;
  163. type ApplicationDeactivatedHandler = ();
  164. type StakeHandlerProvider = hiring::Module<Self>;
  165. }
  166. srml_staking_reward_curve::build! {
  167. const I_NPOS: PiecewiseLinear<'static> = curve!(
  168. min_inflation: 0_025_000,
  169. max_inflation: 0_100_000,
  170. ideal_stake: 0_500_000,
  171. falloff: 0_050_000,
  172. max_piece_count: 40,
  173. test_precision: 0_005_000,
  174. );
  175. }
  176. parameter_types! {
  177. pub const SessionsPerEra: SessionIndex = 3;
  178. pub const BondingDuration: staking::EraIndex = 3;
  179. pub const RewardCurve: &'static PiecewiseLinear<'static> = &I_NPOS;
  180. }
  181. impl staking::Trait for Test {
  182. type Currency = balances::Module<Self>;
  183. type Time = timestamp::Module<Self>;
  184. type CurrencyToVote = ();
  185. type RewardRemainder = ();
  186. type Event = ();
  187. type Slash = ();
  188. type Reward = ();
  189. type SessionsPerEra = SessionsPerEra;
  190. type BondingDuration = BondingDuration;
  191. type SessionInterface = Self;
  192. type RewardCurve = RewardCurve;
  193. }
  194. impl staking::SessionInterface<u64> for Test {
  195. fn disable_validator(_: &u64) -> Result<bool, ()> {
  196. unimplemented!()
  197. }
  198. fn validators() -> Vec<u64> {
  199. unimplemented!()
  200. }
  201. fn prune_historical_up_to(_: u32) {
  202. unimplemented!()
  203. }
  204. }
  205. impl crate::Trait for Test {
  206. type TextProposalMaxLength = TextProposalMaxLength;
  207. type RuntimeUpgradeWasmProposalMaxLength = RuntimeUpgradeWasmProposalMaxLength;
  208. type MembershipOriginValidator = ();
  209. type ProposalEncoder = ();
  210. }
  211. impl ProposalEncoder<Test> for () {
  212. fn encode_proposal(_proposal_details: ProposalDetailsOf<Test>) -> Vec<u8> {
  213. Vec::new()
  214. }
  215. }
  216. impl system::Trait for Test {
  217. type Origin = Origin;
  218. type Index = u64;
  219. type BlockNumber = u64;
  220. type Call = ();
  221. type Hash = H256;
  222. type Hashing = BlakeTwo256;
  223. type AccountId = u64;
  224. type Lookup = IdentityLookup<Self::AccountId>;
  225. type Header = Header;
  226. type Event = ();
  227. type BlockHashCount = BlockHashCount;
  228. type MaximumBlockWeight = MaximumBlockWeight;
  229. type MaximumBlockLength = MaximumBlockLength;
  230. type AvailableBlockRatio = AvailableBlockRatio;
  231. type Version = ();
  232. }
  233. impl timestamp::Trait for Test {
  234. type Moment = u64;
  235. type OnTimestampSet = ();
  236. type MinimumPeriod = MinimumPeriod;
  237. }
  238. pub fn initial_test_ext() -> runtime_io::TestExternalities {
  239. let t = system::GenesisConfig::default()
  240. .build_storage::<Test>()
  241. .unwrap();
  242. t.into()
  243. }
  244. pub type ProposalCodex = crate::Module<Test>;
  245. pub type ProposalsEngine = proposal_engine::Module<Test>;
  246. pub type Balances = balances::Module<Test>;