mock.rs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #![cfg(test)]
  2. use crate::*;
  3. use crate::{Module, Trait};
  4. use balances;
  5. use frame_support::{impl_outer_origin, parameter_types};
  6. use sp_core::H256;
  7. use sp_runtime::{
  8. testing::Header,
  9. traits::{BlakeTwo256, IdentityLookup},
  10. Perbill,
  11. };
  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. }
  24. impl system::Trait for Test {
  25. type BaseCallFilter = ();
  26. type Origin = Origin;
  27. type Call = ();
  28. type Index = u64;
  29. type BlockNumber = u64;
  30. type Hash = H256;
  31. type Hashing = BlakeTwo256;
  32. type AccountId = u64;
  33. type Lookup = IdentityLookup<Self::AccountId>;
  34. type Header = Header;
  35. type Event = ();
  36. type BlockHashCount = BlockHashCount;
  37. type MaximumBlockWeight = MaximumBlockWeight;
  38. type DbWeight = ();
  39. type BlockExecutionWeight = ();
  40. type ExtrinsicBaseWeight = ();
  41. type MaximumExtrinsicWeight = ();
  42. type MaximumBlockLength = MaximumBlockLength;
  43. type AvailableBlockRatio = AvailableBlockRatio;
  44. type Version = ();
  45. type ModuleToIndex = ();
  46. type AccountData = balances::AccountData<u64>;
  47. type OnNewAccount = ();
  48. type OnKilledAccount = ();
  49. }
  50. parameter_types! {
  51. pub const ExistentialDeposit: u32 = 500;
  52. pub const StakePoolId: [u8; 8] = *b"joystake";
  53. }
  54. impl balances::Trait for Test {
  55. type Balance = u64;
  56. type DustRemoval = ();
  57. type Event = ();
  58. type ExistentialDeposit = ExistentialDeposit;
  59. type AccountStore = System;
  60. }
  61. impl Trait for Test {
  62. type Currency = Balances;
  63. type StakePoolId = StakePoolId;
  64. type StakingEventsHandler = ();
  65. type StakeId = u64;
  66. type SlashId = u64;
  67. }
  68. pub fn build_test_externalities() -> sp_io::TestExternalities {
  69. let t = system::GenesisConfig::default()
  70. .build_storage::<Test>()
  71. .unwrap();
  72. t.into()
  73. }
  74. pub type System = system::Module<Test>;
  75. pub type Balances = balances::Module<Test>;
  76. pub type StakePool = Module<Test>;
  77. // Some helper methods for creating Stake states
  78. pub mod fixtures {
  79. use super::*;
  80. pub type OngoingSlashes = BTreeMap<
  81. <Test as Trait>::SlashId,
  82. Slash<<Test as system::Trait>::BlockNumber, BalanceOf<Test>>,
  83. >;
  84. }