mock.rs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. #![cfg(test)]
  2. pub use super::{council, election};
  3. pub use common::currency::GovernanceCurrency;
  4. use frame_support::{impl_outer_origin, parameter_types};
  5. use sp_core::H256;
  6. use sp_runtime::{
  7. testing::Header,
  8. traits::{BlakeTwo256, IdentityLookup},
  9. BuildStorage, Perbill,
  10. };
  11. pub use system;
  12. impl_outer_origin! {
  13. pub enum Origin for Test {}
  14. }
  15. // Workaround for https://github.com/rust-lang/rust/issues/26925 . Remove when sorted.
  16. #[derive(Clone, PartialEq, Eq, Debug)]
  17. pub struct Test;
  18. parameter_types! {
  19. pub const BlockHashCount: u64 = 250;
  20. pub const MaximumBlockWeight: u32 = 1024;
  21. pub const MaximumBlockLength: u32 = 2 * 1024;
  22. pub const AvailableBlockRatio: Perbill = Perbill::one();
  23. pub const MinimumPeriod: u64 = 5;
  24. }
  25. impl system::Trait for Test {
  26. type BaseCallFilter = ();
  27. type Origin = Origin;
  28. type Call = ();
  29. type Index = u64;
  30. type BlockNumber = u64;
  31. type Hash = H256;
  32. type Hashing = BlakeTwo256;
  33. type AccountId = u64;
  34. type Lookup = IdentityLookup<Self::AccountId>;
  35. type Header = Header;
  36. type Event = ();
  37. type BlockHashCount = BlockHashCount;
  38. type MaximumBlockWeight = MaximumBlockWeight;
  39. type DbWeight = ();
  40. type BlockExecutionWeight = ();
  41. type ExtrinsicBaseWeight = ();
  42. type MaximumExtrinsicWeight = ();
  43. type MaximumBlockLength = MaximumBlockLength;
  44. type AvailableBlockRatio = AvailableBlockRatio;
  45. type Version = ();
  46. type ModuleToIndex = ();
  47. type AccountData = balances::AccountData<u64>;
  48. type OnNewAccount = ();
  49. type OnKilledAccount = ();
  50. }
  51. impl pallet_timestamp::Trait for Test {
  52. type Moment = u64;
  53. type OnTimestampSet = ();
  54. type MinimumPeriod = MinimumPeriod;
  55. }
  56. impl council::Trait for Test {
  57. type Event = ();
  58. type CouncilTermEnded = (Election,);
  59. }
  60. impl election::Trait for Test {
  61. type Event = ();
  62. type CouncilElected = (Council,);
  63. }
  64. impl membership::Trait for Test {
  65. type Event = ();
  66. type MemberId = u64;
  67. type SubscriptionId = u32;
  68. type PaidTermId = u32;
  69. type ActorId = u32;
  70. }
  71. impl minting::Trait for Test {
  72. type Currency = Balances;
  73. type MintId = u64;
  74. }
  75. impl recurringrewards::Trait for Test {
  76. type PayoutStatusHandler = ();
  77. type RecipientId = u64;
  78. type RewardRelationshipId = u64;
  79. }
  80. parameter_types! {
  81. pub const ExistentialDeposit: u32 = 0;
  82. }
  83. impl balances::Trait for Test {
  84. type Balance = u64;
  85. type DustRemoval = ();
  86. type Event = ();
  87. type ExistentialDeposit = ExistentialDeposit;
  88. type AccountStore = System;
  89. }
  90. impl GovernanceCurrency for Test {
  91. type Currency = balances::Module<Self>;
  92. }
  93. // TODO add a Hook type to capture TriggerElection and CouncilElected hooks
  94. // This function basically just builds a genesis storage key/value store according to
  95. // our desired mockup.
  96. pub fn initial_test_ext() -> sp_io::TestExternalities {
  97. let mut t = system::GenesisConfig::default()
  98. .build_storage::<Test>()
  99. .unwrap();
  100. let members_config_builder = membership::genesis::GenesisConfigBuilder::<Test>::default()
  101. .default_paid_membership_fee(0)
  102. .members(vec![
  103. // member_id, account_id
  104. (0, 1),
  105. (1, 2),
  106. (2, 3),
  107. (3, 4),
  108. (4, 5),
  109. (5, 6),
  110. (6, 7),
  111. (7, 8),
  112. (8, 9),
  113. (9, 10),
  114. (10, 11),
  115. (11, 12),
  116. (12, 13),
  117. (13, 14),
  118. (14, 15),
  119. (15, 16),
  120. (16, 17),
  121. (17, 18),
  122. (18, 19),
  123. (19, 20),
  124. ]);
  125. members_config_builder
  126. .build()
  127. .assimilate_storage(&mut t)
  128. .unwrap();
  129. // build the council config to initialize the mint
  130. let council_config = council::GenesisConfig::<Test>::default()
  131. .build_storage()
  132. .unwrap();
  133. council_config.assimilate_storage(&mut t).unwrap();
  134. t.into()
  135. }
  136. pub type Election = election::Module<Test>;
  137. pub type Council = council::Module<Test>;
  138. pub type System = system::Module<Test>;
  139. pub type Balances = balances::Module<Test>;