Newer
Older
use frame_support::{impl_outer_dispatch, impl_outer_origin, parameter_types, weights::Weight};
traits::{BlakeTwo256, IdentityLookup},
Perbill,
};
impl_outer_origin! {
pub enum Origin for Test {}
}
impl_outer_dispatch! {
pub enum Call for Test where origin: Origin {
oracle::ModuleOracle,
}
}
pub type OracleCall = super::Call<Test>;
// For testing the module, we construct most of a mock runtime. This means
// first constructing a configuration type (`Test`) which `impl`s each of the
// configuration traits of modules we want to use.
#[derive(Clone, Eq, PartialEq, Debug)]
pub struct Test;
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: Weight = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);
}
type Index = u64;
type BlockNumber = u64;
type Hash = H256;
type Hashing = BlakeTwo256;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Event = ();
type BlockHashCount = BlockHashCount;
type MaximumBlockWeight = MaximumBlockWeight;
type MaximumBlockLength = MaximumBlockLength;
type AvailableBlockRatio = AvailableBlockRatio;
type Version = ();
type DbWeight = ();
type BlockExecutionWeight = ();
type ExtrinsicBaseWeight = ();
thread_local! {
static TIME: RefCell<u32> = RefCell::new(0);
pub struct Timestamp;
impl Time for Timestamp {
type Moment = u32;
impl Timestamp {
pub fn set_timestamp(val: u32) {
TIME.with(|v| *v.borrow_mut() = val);
parameter_types! {
pub const MinimumCount: u32 = 3;
pub const ExpiresIn: u32 = 600;
impl Trait for Test {
type Event = ();
type OnNewData = ();
type CombineData = DefaultCombineData<Self, MinimumCount, ExpiresIn>;
type OracleKey = Key;
type OracleValue = Value;
type UnsignedPriority = UnsignedPriority;
type AuthorityId = UintAuthorityId;
}
pub type ModuleOracle = Module<Test>;
// This function basically just builds a genesis storage key/value store according to
// our desired mockup.
pub fn new_test_ext() -> sp_io::TestExternalities {
let mut storage = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();
let _ = GenesisConfig::<Test> {
members: vec![1, 2, 3].into(),
session_keys: vec![(1, 10.into()), (2, 20.into()), (3, 30.into())],
}
.assimilate_storage(&mut storage);
let mut t: sp_io::TestExternalities = storage.into();
t.execute_with(|| {
Timestamp::set_timestamp(12345);
});