mock.rs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. mod working_group_mod {
  11. pub use working_group::Event;
  12. pub use working_group::Instance2;
  13. pub use working_group::Trait;
  14. }
  15. mod membership_mod {
  16. pub use membership::members::Event;
  17. }
  18. mod discovery {
  19. pub use crate::Event;
  20. }
  21. impl_outer_origin! {
  22. pub enum Origin for Test {}
  23. }
  24. impl_outer_event! {
  25. pub enum MetaEvent for Test {
  26. discovery<T>,
  27. balances<T>,
  28. membership_mod<T>,
  29. working_group_mod Instance2 <T>,
  30. }
  31. }
  32. // Workaround for https://github.com/rust-lang/rust/issues/26925 . Remove when sorted.
  33. #[derive(Clone, PartialEq, Eq, Debug)]
  34. pub struct Test;
  35. parameter_types! {
  36. pub const BlockHashCount: u64 = 250;
  37. pub const MaximumBlockWeight: u32 = 1024;
  38. pub const MaximumBlockLength: u32 = 2 * 1024;
  39. pub const AvailableBlockRatio: Perbill = Perbill::one();
  40. pub const MinimumPeriod: u64 = 5;
  41. pub const InitialMembersBalance: u64 = 2000;
  42. pub const StakePoolId: [u8; 8] = *b"joystake";
  43. pub const ExistentialDeposit: u32 = 0;
  44. pub const TransferFee: u32 = 0;
  45. pub const CreationFee: u32 = 0;
  46. }
  47. impl system::Trait for Test {
  48. type Origin = Origin;
  49. type Index = u64;
  50. type BlockNumber = u64;
  51. type Call = ();
  52. type Hash = H256;
  53. type Hashing = BlakeTwo256;
  54. type AccountId = u64;
  55. type Lookup = IdentityLookup<Self::AccountId>;
  56. type Header = Header;
  57. type Event = MetaEvent;
  58. type BlockHashCount = BlockHashCount;
  59. type MaximumBlockWeight = MaximumBlockWeight;
  60. type MaximumBlockLength = MaximumBlockLength;
  61. type AvailableBlockRatio = AvailableBlockRatio;
  62. type Version = ();
  63. }
  64. impl Trait for Test {
  65. type Event = MetaEvent;
  66. }
  67. impl hiring::Trait for Test {
  68. type OpeningId = u64;
  69. type ApplicationId = u64;
  70. type ApplicationDeactivatedHandler = ();
  71. type StakeHandlerProvider = hiring::Module<Self>;
  72. }
  73. impl minting::Trait for Test {
  74. type Currency = Balances;
  75. type MintId = u64;
  76. }
  77. impl stake::Trait for Test {
  78. type Currency = Balances;
  79. type StakePoolId = StakePoolId;
  80. type StakingEventsHandler = ();
  81. type StakeId = u64;
  82. type SlashId = u64;
  83. }
  84. impl membership::members::Trait for Test {
  85. type Event = MetaEvent;
  86. type MemberId = u64;
  87. type PaidTermId = u64;
  88. type SubscriptionId = u64;
  89. type ActorId = u64;
  90. type InitialMembersBalance = InitialMembersBalance;
  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. impl working_group::Trait<working_group::Instance2> for Test {
  112. type Event = MetaEvent;
  113. }
  114. impl timestamp::Trait for Test {
  115. type Moment = u64;
  116. type OnTimestampSet = ();
  117. type MinimumPeriod = MinimumPeriod;
  118. }
  119. pub fn initial_test_ext() -> runtime_io::TestExternalities {
  120. let t = system::GenesisConfig::default()
  121. .build_storage::<Test>()
  122. .unwrap();
  123. t.into()
  124. }
  125. pub type Balances = balances::Module<Test>;
  126. pub type System = system::Module<Test>;
  127. pub type Discovery = Module<Test>;
  128. pub(crate) fn hire_storage_provider() -> (u64, u64) {
  129. let storage_provider_id = 1;
  130. let role_account_id = 1;
  131. let storage_provider = working_group::Worker {
  132. member_id: 1,
  133. role_account: role_account_id,
  134. reward_relationship: None,
  135. role_stake_profile: None,
  136. };
  137. <working_group::WorkerById<Test, working_group::Instance2>>::insert(
  138. storage_provider_id,
  139. storage_provider,
  140. );
  141. (role_account_id, storage_provider_id)
  142. }