Skip to content

Commit da05bc8

Browse files
kianenigmabkchr
andauthored
Thread-local parameter_types for testing. (#7542)
* Thread-local parameter_types for testing. * Better docs. * Some minors * Merge'em * Update frame/support/src/lib.rs Co-authored-by: Bastian Köcher <[email protected]> * Align more to basti's trick * Update frame/support/src/lib.rs * Update frame/support/src/lib.rs Co-authored-by: Bastian Köcher <[email protected]> Co-authored-by: Bastian Köcher <[email protected]>
1 parent 30618c5 commit da05bc8

File tree

1 file changed

+8
-54
lines changed

1 file changed

+8
-54
lines changed

src/mock.rs

Lines changed: 8 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,6 @@ pub(crate) type Balance = u128;
4747

4848
thread_local! {
4949
static SESSION: RefCell<(Vec<AccountId>, HashSet<AccountId>)> = RefCell::new(Default::default());
50-
static SESSION_PER_ERA: RefCell<SessionIndex> = RefCell::new(3);
51-
static EXISTENTIAL_DEPOSIT: RefCell<Balance> = RefCell::new(0);
52-
static SLASH_DEFER_DURATION: RefCell<EraIndex> = RefCell::new(0);
53-
static ELECTION_LOOKAHEAD: RefCell<BlockNumber> = RefCell::new(0);
54-
static PERIOD: RefCell<BlockNumber> = RefCell::new(1);
55-
static MAX_ITERATIONS: RefCell<u32> = RefCell::new(0);
5650
}
5751

5852
/// Another session handler struct to test on_disabled.
@@ -92,53 +86,6 @@ pub fn is_disabled(controller: AccountId) -> bool {
9286
SESSION.with(|d| d.borrow().1.contains(&stash))
9387
}
9488

95-
pub struct ExistentialDeposit;
96-
impl Get<Balance> for ExistentialDeposit {
97-
fn get() -> Balance {
98-
EXISTENTIAL_DEPOSIT.with(|v| *v.borrow())
99-
}
100-
}
101-
102-
pub struct SessionsPerEra;
103-
impl Get<SessionIndex> for SessionsPerEra {
104-
fn get() -> SessionIndex {
105-
SESSION_PER_ERA.with(|v| *v.borrow())
106-
}
107-
}
108-
impl Get<BlockNumber> for SessionsPerEra {
109-
fn get() -> BlockNumber {
110-
SESSION_PER_ERA.with(|v| *v.borrow() as BlockNumber)
111-
}
112-
}
113-
114-
pub struct ElectionLookahead;
115-
impl Get<BlockNumber> for ElectionLookahead {
116-
fn get() -> BlockNumber {
117-
ELECTION_LOOKAHEAD.with(|v| *v.borrow())
118-
}
119-
}
120-
121-
pub struct Period;
122-
impl Get<BlockNumber> for Period {
123-
fn get() -> BlockNumber {
124-
PERIOD.with(|v| *v.borrow())
125-
}
126-
}
127-
128-
pub struct SlashDeferDuration;
129-
impl Get<EraIndex> for SlashDeferDuration {
130-
fn get() -> EraIndex {
131-
SLASH_DEFER_DURATION.with(|v| *v.borrow())
132-
}
133-
}
134-
135-
pub struct MaxIterations;
136-
impl Get<u32> for MaxIterations {
137-
fn get() -> u32 {
138-
MAX_ITERATIONS.with(|v| *v.borrow())
139-
}
140-
}
141-
14289
impl_outer_origin! {
14390
pub enum Origin for Test where system = frame_system {}
14491
}
@@ -186,7 +133,14 @@ parameter_types! {
186133
pub const MaximumBlockLength: u32 = 2 * 1024;
187134
pub const AvailableBlockRatio: Perbill = Perbill::one();
188135
pub const MaxLocks: u32 = 1024;
136+
pub static SessionsPerEra: SessionIndex = 3;
137+
pub static ExistentialDeposit: Balance = 0;
138+
pub static SlashDeferDuration: EraIndex = 0;
139+
pub static ElectionLookahead: BlockNumber = 0;
140+
pub static Period: BlockNumber = 1;
141+
pub static MaxIterations: u32 = 0;
189142
}
143+
190144
impl frame_system::Trait for Test {
191145
type BaseCallFilter = ();
192146
type Origin = Origin;
@@ -437,7 +391,7 @@ impl ExtBuilder {
437391
pub fn set_associated_constants(&self) {
438392
EXISTENTIAL_DEPOSIT.with(|v| *v.borrow_mut() = self.existential_deposit);
439393
SLASH_DEFER_DURATION.with(|v| *v.borrow_mut() = self.slash_defer_duration);
440-
SESSION_PER_ERA.with(|v| *v.borrow_mut() = self.session_per_era);
394+
SESSIONS_PER_ERA.with(|v| *v.borrow_mut() = self.session_per_era);
441395
ELECTION_LOOKAHEAD.with(|v| *v.borrow_mut() = self.election_lookahead);
442396
PERIOD.with(|v| *v.borrow_mut() = self.session_length);
443397
MAX_ITERATIONS.with(|v| *v.borrow_mut() = self.max_offchain_iterations);

0 commit comments

Comments
 (0)