mocks.rs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #![cfg(test)]
  2. use frame_support::dispatch::DispatchError;
  3. use frame_support::{impl_outer_event, impl_outer_origin, parameter_types};
  4. use sp_core::H256;
  5. use sp_runtime::{
  6. testing::Header,
  7. traits::{BlakeTwo256, IdentityLookup},
  8. Perbill,
  9. };
  10. use crate::{Module, Trait};
  11. impl_outer_origin! {
  12. pub enum Origin for Test {}
  13. }
  14. mod bounty {
  15. pub use crate::Event;
  16. }
  17. impl_outer_event! {
  18. pub enum TestEvent for Test {
  19. bounty<T>,
  20. frame_system<T>,
  21. balances<T>,
  22. }
  23. }
  24. // Workaround for https://github.com/rust-lang/rust/issues/26925 . Remove when sorted.
  25. #[derive(Clone, PartialEq, Eq, Debug)]
  26. pub struct Test;
  27. parameter_types! {
  28. pub const BlockHashCount: u64 = 250;
  29. pub const MaximumBlockWeight: u32 = 1024;
  30. pub const MaximumBlockLength: u32 = 2 * 1024;
  31. pub const AvailableBlockRatio: Perbill = Perbill::one();
  32. }
  33. impl frame_system::Trait for Test {
  34. type BaseCallFilter = ();
  35. type Origin = Origin;
  36. type Call = ();
  37. type Index = u64;
  38. type BlockNumber = u64;
  39. type Hash = H256;
  40. type Hashing = BlakeTwo256;
  41. type AccountId = u64;
  42. type Lookup = IdentityLookup<Self::AccountId>;
  43. type Header = Header;
  44. type Event = TestEvent;
  45. type BlockHashCount = BlockHashCount;
  46. type MaximumBlockWeight = MaximumBlockWeight;
  47. type DbWeight = ();
  48. type BlockExecutionWeight = ();
  49. type ExtrinsicBaseWeight = ();
  50. type MaximumExtrinsicWeight = ();
  51. type MaximumBlockLength = MaximumBlockLength;
  52. type AvailableBlockRatio = AvailableBlockRatio;
  53. type Version = ();
  54. type AccountData = balances::AccountData<u64>;
  55. type OnNewAccount = ();
  56. type OnKilledAccount = ();
  57. type PalletInfo = ();
  58. type SystemWeightInfo = ();
  59. }
  60. impl Trait for Test {
  61. type Event = TestEvent;
  62. type BountyId = u64;
  63. type MemberOriginValidator = ();
  64. type WeightInfo = ();
  65. }
  66. impl crate::WeightInfo for () {
  67. fn create_bounty(_: u32) -> u64 {
  68. 0
  69. }
  70. }
  71. impl common::Trait for Test {
  72. type MemberId = u64;
  73. type ActorId = u64;
  74. }
  75. impl common::origin::MemberOriginValidator<Origin, u64, u64> for () {
  76. fn ensure_member_controller_account_origin(
  77. origin: Origin,
  78. _account_id: u64,
  79. ) -> Result<u64, DispatchError> {
  80. let signed_account_id = frame_system::ensure_signed(origin)?;
  81. Ok(signed_account_id)
  82. }
  83. fn is_member_controller_account(_member_id: &u64, _account_id: &u64) -> bool {
  84. true
  85. }
  86. }
  87. parameter_types! {
  88. pub const ExistentialDeposit: u32 = 0;
  89. }
  90. impl balances::Trait for Test {
  91. type Balance = u64;
  92. type DustRemoval = ();
  93. type Event = TestEvent;
  94. type ExistentialDeposit = ExistentialDeposit;
  95. type AccountStore = System;
  96. type WeightInfo = ();
  97. type MaxLocks = ();
  98. }
  99. pub fn build_test_externalities() -> sp_io::TestExternalities {
  100. let t = frame_system::GenesisConfig::default()
  101. .build_storage::<Test>()
  102. .unwrap();
  103. t.into()
  104. }
  105. pub type System = frame_system::Module<Test>;
  106. pub type Bounty = Module<Test>;