mock.rs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. #![cfg(test)]
  2. pub use crate::*;
  3. pub use primitives::{Blake2Hasher, H256};
  4. pub use sr_primitives::{
  5. testing::{Digest, DigestItem, Header, UintAuthorityId},
  6. traits::{BlakeTwo256, IdentityLookup, OnFinalize},
  7. BuildStorage, Perbill,
  8. };
  9. use srml_support::{impl_outer_event, impl_outer_origin, parameter_types};
  10. // The storage working group instance alias.
  11. pub type StorageWorkingGroupInstance = working_group::Instance2;
  12. mod working_group_mod {
  13. pub use super::StorageWorkingGroupInstance;
  14. pub use working_group::Event;
  15. pub use working_group::Trait;
  16. }
  17. mod membership_mod {
  18. pub use membership::Event;
  19. }
  20. mod discovery {
  21. pub use crate::Event;
  22. }
  23. impl_outer_origin! {
  24. pub enum Origin for Test {}
  25. }
  26. impl_outer_event! {
  27. pub enum MetaEvent for Test {
  28. discovery<T>,
  29. balances<T>,
  30. membership_mod<T>,
  31. working_group_mod StorageWorkingGroupInstance <T>,
  32. }
  33. }
  34. // Workaround for https://github.com/rust-lang/rust/issues/26925 . Remove when sorted.
  35. #[derive(Clone, PartialEq, Eq, Debug)]
  36. pub struct Test;
  37. parameter_types! {
  38. pub const BlockHashCount: u64 = 250;
  39. pub const MaximumBlockWeight: u32 = 1024;
  40. pub const MaximumBlockLength: u32 = 2 * 1024;
  41. pub const AvailableBlockRatio: Perbill = Perbill::one();
  42. pub const MinimumPeriod: u64 = 5;
  43. pub const StakePoolId: [u8; 8] = *b"joystake";
  44. pub const ExistentialDeposit: u32 = 0;
  45. pub const TransferFee: u32 = 0;
  46. pub const CreationFee: u32 = 0;
  47. }
  48. impl system::Trait for Test {
  49. type Origin = Origin;
  50. type Index = u64;
  51. type BlockNumber = u64;
  52. type Call = ();
  53. type Hash = H256;
  54. type Hashing = BlakeTwo256;
  55. type AccountId = u64;
  56. type Lookup = IdentityLookup<Self::AccountId>;
  57. type Header = Header;
  58. type Event = MetaEvent;
  59. type BlockHashCount = BlockHashCount;
  60. type MaximumBlockWeight = MaximumBlockWeight;
  61. type MaximumBlockLength = MaximumBlockLength;
  62. type AvailableBlockRatio = AvailableBlockRatio;
  63. type Version = ();
  64. }
  65. impl Trait for Test {
  66. type Event = MetaEvent;
  67. }
  68. impl hiring::Trait for Test {
  69. type OpeningId = u64;
  70. type ApplicationId = u64;
  71. type ApplicationDeactivatedHandler = ();
  72. type StakeHandlerProvider = hiring::Module<Self>;
  73. }
  74. impl minting::Trait for Test {
  75. type Currency = Balances;
  76. type MintId = u64;
  77. }
  78. impl stake::Trait for Test {
  79. type Currency = Balances;
  80. type StakePoolId = StakePoolId;
  81. type StakingEventsHandler = ();
  82. type StakeId = u64;
  83. type SlashId = u64;
  84. }
  85. impl membership::Trait for Test {
  86. type Event = MetaEvent;
  87. type MemberId = u64;
  88. type PaidTermId = u64;
  89. type SubscriptionId = u64;
  90. type ActorId = u64;
  91. }
  92. impl common::currency::GovernanceCurrency for Test {
  93. type Currency = Balances;
  94. }
  95. impl balances::Trait for Test {
  96. type Balance = u64;
  97. type OnFreeBalanceZero = ();
  98. type OnNewAccount = ();
  99. type TransferPayment = ();
  100. type DustRemoval = ();
  101. type Event = MetaEvent;
  102. type ExistentialDeposit = ExistentialDeposit;
  103. type TransferFee = TransferFee;
  104. type CreationFee = CreationFee;
  105. }
  106. impl recurringrewards::Trait for Test {
  107. type PayoutStatusHandler = ();
  108. type RecipientId = u64;
  109. type RewardRelationshipId = u64;
  110. }
  111. parameter_types! {
  112. pub const MaxWorkerNumberLimit: u32 = 3;
  113. }
  114. impl working_group::Trait<StorageWorkingGroupInstance> for Test {
  115. type Event = MetaEvent;
  116. type MaxWorkerNumberLimit = MaxWorkerNumberLimit;
  117. }
  118. impl timestamp::Trait for Test {
  119. type Moment = u64;
  120. type OnTimestampSet = ();
  121. type MinimumPeriod = MinimumPeriod;
  122. }
  123. pub fn initial_test_ext() -> runtime_io::TestExternalities {
  124. let t = system::GenesisConfig::default()
  125. .build_storage::<Test>()
  126. .unwrap();
  127. t.into()
  128. }
  129. pub type Balances = balances::Module<Test>;
  130. pub type System = system::Module<Test>;
  131. pub type Discovery = Module<Test>;
  132. pub(crate) fn hire_storage_provider() -> (u64, u64) {
  133. let storage_provider_id = 1;
  134. let role_account_id = 1;
  135. let storage_provider = working_group::Worker {
  136. member_id: 1,
  137. role_account_id,
  138. reward_relationship: None,
  139. role_stake_profile: None,
  140. };
  141. <working_group::WorkerById<Test, StorageWorkingGroupInstance>>::insert(
  142. storage_provider_id,
  143. storage_provider,
  144. );
  145. (role_account_id, storage_provider_id)
  146. }