mock.rs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #![cfg(test)]
  2. pub use super::discovery;
  3. pub use crate::roles::actors;
  4. pub use crate::traits::Roles;
  5. pub use primitives::{Blake2Hasher, H256};
  6. pub use runtime_primitives::{
  7. testing::{Digest, DigestItem, Header, UintAuthorityId},
  8. traits::{BlakeTwo256, IdentityLookup, OnFinalize},
  9. BuildStorage, Perbill,
  10. };
  11. use srml_support::{impl_outer_event, impl_outer_origin, parameter_types};
  12. impl_outer_origin! {
  13. pub enum Origin for Test {}
  14. }
  15. impl_outer_event! {
  16. pub enum MetaEvent for Test {
  17. discovery<T>,
  18. }
  19. }
  20. // Workaround for https://github.com/rust-lang/rust/issues/26925 . Remove when sorted.
  21. #[derive(Clone, PartialEq, Eq, Debug)]
  22. pub struct Test;
  23. parameter_types! {
  24. pub const BlockHashCount: u64 = 250;
  25. pub const MaximumBlockWeight: u32 = 1024;
  26. pub const MaximumBlockLength: u32 = 2 * 1024;
  27. pub const AvailableBlockRatio: Perbill = Perbill::one();
  28. }
  29. impl system::Trait for Test {
  30. type Origin = Origin;
  31. type Index = u64;
  32. type BlockNumber = u64;
  33. type Call = ();
  34. type Hash = H256;
  35. type Hashing = BlakeTwo256;
  36. type AccountId = u64;
  37. type Lookup = IdentityLookup<Self::AccountId>;
  38. type Header = Header;
  39. type Event = MetaEvent;
  40. type BlockHashCount = BlockHashCount;
  41. type MaximumBlockWeight = MaximumBlockWeight;
  42. type MaximumBlockLength = MaximumBlockLength;
  43. type AvailableBlockRatio = AvailableBlockRatio;
  44. type Version = ();
  45. }
  46. pub fn alice_account() -> u64 {
  47. 1
  48. }
  49. pub fn bob_account() -> u64 {
  50. 2
  51. }
  52. impl discovery::Trait for Test {
  53. type Event = MetaEvent;
  54. type Roles = MockRoles;
  55. }
  56. pub struct MockRoles {}
  57. impl Roles<Test> for MockRoles {
  58. fn is_role_account(account_id: &u64) -> bool {
  59. *account_id == alice_account()
  60. }
  61. fn account_has_role(_account_id: &u64, _role: actors::Role) -> bool {
  62. false
  63. }
  64. fn random_account_for_role(_role: actors::Role) -> Result<u64, &'static str> {
  65. Err("not implemented")
  66. }
  67. }
  68. pub fn initial_test_ext() -> runtime_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 Discovery = discovery::Module<Test>;