mock.rs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. #![cfg(test)]
  2. pub use super::{council, election, proposals};
  3. pub use crate::currency::GovernanceCurrency;
  4. use crate::membership;
  5. pub use system;
  6. pub use primitives::{Blake2Hasher, H256};
  7. pub use sr_primitives::{
  8. testing::{Digest, DigestItem, Header, UintAuthorityId},
  9. traits::{BlakeTwo256, Convert, IdentityLookup, OnFinalize},
  10. weights::Weight,
  11. BuildStorage, Perbill,
  12. };
  13. use srml_support::{impl_outer_origin, parameter_types};
  14. impl_outer_origin! {
  15. pub enum Origin for Test {}
  16. }
  17. // Workaround for https://github.com/rust-lang/rust/issues/26925 . Remove when sorted.
  18. #[derive(Clone, PartialEq, Eq, Debug)]
  19. pub struct Test;
  20. parameter_types! {
  21. pub const BlockHashCount: u64 = 250;
  22. pub const MaximumBlockWeight: u32 = 1024;
  23. pub const MaximumBlockLength: u32 = 2 * 1024;
  24. pub const AvailableBlockRatio: Perbill = Perbill::one();
  25. pub const MinimumPeriod: u64 = 5;
  26. }
  27. impl system::Trait for Test {
  28. type Origin = Origin;
  29. type Index = u64;
  30. type BlockNumber = u64;
  31. type Call = ();
  32. type Hash = H256;
  33. type Hashing = BlakeTwo256;
  34. type AccountId = u64;
  35. type Lookup = IdentityLookup<Self::AccountId>;
  36. type Header = Header;
  37. type Event = ();
  38. type BlockHashCount = BlockHashCount;
  39. type MaximumBlockWeight = MaximumBlockWeight;
  40. type MaximumBlockLength = MaximumBlockLength;
  41. type AvailableBlockRatio = AvailableBlockRatio;
  42. type Version = ();
  43. }
  44. impl timestamp::Trait for Test {
  45. type Moment = u64;
  46. type OnTimestampSet = ();
  47. type MinimumPeriod = MinimumPeriod;
  48. }
  49. impl council::Trait for Test {
  50. type Event = ();
  51. type CouncilTermEnded = (Election,);
  52. }
  53. impl election::Trait for Test {
  54. type Event = ();
  55. type CouncilElected = (Council,);
  56. }
  57. impl membership::members::Trait for Test {
  58. type Event = ();
  59. type MemberId = u32;
  60. type SubscriptionId = u32;
  61. type PaidTermId = u32;
  62. type ActorId = u32;
  63. type InitialMembersBalance = InitialMembersBalance;
  64. }
  65. parameter_types! {
  66. pub const ExistentialDeposit: u32 = 0;
  67. pub const TransferFee: u32 = 0;
  68. pub const CreationFee: u32 = 0;
  69. pub const TransactionBaseFee: u32 = 1;
  70. pub const TransactionByteFee: u32 = 0;
  71. pub const InitialMembersBalance: u32 = 0;
  72. }
  73. impl balances::Trait for Test {
  74. /// The type for recording an account's balance.
  75. type Balance = u64;
  76. /// What to do if an account's free balance gets zeroed.
  77. type OnFreeBalanceZero = ();
  78. /// What to do if a new account is created.
  79. type OnNewAccount = ();
  80. /// The ubiquitous event type.
  81. type Event = ();
  82. type DustRemoval = ();
  83. type TransferPayment = ();
  84. type ExistentialDeposit = ExistentialDeposit;
  85. type TransferFee = TransferFee;
  86. type CreationFee = CreationFee;
  87. }
  88. impl GovernanceCurrency for Test {
  89. type Currency = balances::Module<Self>;
  90. }
  91. // TODO add a Hook type to capture TriggerElection and CouncilElected hooks
  92. // This function basically just builds a genesis storage key/value store according to
  93. // our desired mockup.
  94. pub fn initial_test_ext() -> runtime_io::TestExternalities {
  95. let mut t = system::GenesisConfig::default()
  96. .build_storage::<Test>()
  97. .unwrap();
  98. membership::members::GenesisConfig::<Test> {
  99. default_paid_membership_fee: 0,
  100. members: vec![
  101. (1, "member1".into(), "".into(), "".into()),
  102. (2, "member2".into(), "".into(), "".into()),
  103. (3, "member3".into(), "".into(), "".into()),
  104. (4, "member4".into(), "".into(), "".into()),
  105. (5, "member5".into(), "".into(), "".into()),
  106. (6, "member6".into(), "".into(), "".into()),
  107. (7, "member7".into(), "".into(), "".into()),
  108. (8, "member8".into(), "".into(), "".into()),
  109. (9, "member9".into(), "".into(), "".into()),
  110. (10, "member10".into(), "".into(), "".into()),
  111. (11, "member11".into(), "".into(), "".into()),
  112. (12, "member12".into(), "".into(), "".into()),
  113. (13, "member13".into(), "".into(), "".into()),
  114. (14, "member14".into(), "".into(), "".into()),
  115. (15, "member15".into(), "".into(), "".into()),
  116. (16, "member16".into(), "".into(), "".into()),
  117. (17, "member17".into(), "".into(), "".into()),
  118. (18, "member18".into(), "".into(), "".into()),
  119. (19, "member19".into(), "".into(), "".into()),
  120. (20, "member20".into(), "".into(), "".into()),
  121. ],
  122. }
  123. .assimilate_storage(&mut t)
  124. .unwrap();
  125. t.into()
  126. }
  127. pub type Election = election::Module<Test>;
  128. pub type Council = council::Module<Test>;
  129. pub type System = system::Module<Test>;
  130. pub type Balances = balances::Module<Test>;