Newer
Older
use frame_support::{impl_outer_dispatch, impl_outer_event, impl_outer_origin, parameter_types};
mod oracle {
pub use super::super::*;
}
impl_outer_event! {
pub enum TestEvent for Test {
frame_system<T>,
oracle<T>,
}
}
impl_outer_origin! {
pub enum Origin for Test {}
}
impl_outer_dispatch! {
pub enum Call for Test where origin: Origin {
oracle::ModuleOracle,
}
}
// 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;
}
type Index = u64;
type BlockNumber = u64;
type Hash = H256;
type Hashing = BlakeTwo256;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Event = TestEvent;
type BlockWeights = ();
type BlockLength = ();
pub type System = frame_system::Module<Test>;
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;
pub const RootOperatorAccountId: AccountId = 4;
type Event = TestEvent;
type CombineData = DefaultCombineData<Self, MinimumCount, ExpiresIn>;
type OracleKey = Key;
type OracleValue = Value;
type RootOperatorAccountId = RootOperatorAccountId;
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> {
phantom: Default::default(),
}
.assimilate_storage(&mut storage);
let mut t: sp_io::TestExternalities = storage.into();
t.execute_with(|| {
Timestamp::set_timestamp(12345);
});