-
Notifications
You must be signed in to change notification settings - Fork 300
Expand file tree
/
Copy pathmock.rs
More file actions
106 lines (84 loc) · 2.31 KB
/
Copy pathmock.rs
File metadata and controls
106 lines (84 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#![cfg(test)]
use super::*;
use frame_support::{
construct_runtime, derive_impl, parameter_types,
traits::{ConstU32, SortedMembers},
};
use sp_runtime::{traits::IdentityLookup, BuildStorage};
use std::cell::RefCell;
mod oracle {
pub use super::super::*;
}
pub type AccountId = u128;
type Key = u32;
type Value = u32;
#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)]
impl frame_system::Config for Test {
type AccountId = AccountId;
type Lookup = IdentityLookup<Self::AccountId>;
type Block = Block;
}
thread_local! {
static TIME: RefCell<u32> = RefCell::new(0);
static MEMBERS: RefCell<Vec<AccountId>> = RefCell::new(vec![1, 2, 3]);
}
pub struct Timestamp;
impl Time for Timestamp {
type Moment = u32;
fn now() -> Self::Moment {
TIME.with(|v| *v.borrow())
}
}
impl Timestamp {
pub fn set_timestamp(val: u32) {
TIME.with(|v| *v.borrow_mut() = val);
}
}
parameter_types! {
pub const RootOperatorAccountId: AccountId = 4;
pub const MaxFeedValues: u32 = 5;
}
pub struct Members;
impl SortedMembers<AccountId> for Members {
fn sorted_members() -> Vec<AccountId> {
MEMBERS.with(|v| v.borrow().clone())
}
#[cfg(feature = "runtime-benchmarks")]
fn add(who: &AccountId) {
MEMBERS.with(|v| v.borrow_mut().push(*who));
}
}
impl Config for Test {
type OnNewData = ();
type CombineData = DefaultCombineData<Self, ConstU32<3>, ConstU32<600>>;
type Time = Timestamp;
type OracleKey = Key;
type OracleValue = Value;
type RootOperatorAccountId = RootOperatorAccountId;
type Members = Members;
type WeightInfo = ();
type MaxHasDispatchedSize = ConstU32<100>;
type MaxFeedValues = MaxFeedValues;
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = ();
}
type Block = frame_system::mocking::MockBlock<Test>;
construct_runtime!(
pub enum Test {
System: frame_system,
ModuleOracle: oracle,
}
);
pub fn set_members(members: Vec<AccountId>) {
MEMBERS.with(|v| *v.borrow_mut() = members);
}
// 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 storage = frame_system::GenesisConfig::<Test>::default().build_storage().unwrap();
let mut t: sp_io::TestExternalities = storage.into();
t.execute_with(|| {
Timestamp::set_timestamp(12345);
});
t
}