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 <bkchr@users.noreply.github.com>

* Align more to basti's trick

* Update frame/support/src/lib.rs

* Update frame/support/src/lib.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
Co-authored-by: Bastian Köcher <git@kchr.de>
This commit is contained in:
Kian Paimani
2020-11-20 18:54:19 +01:00
committed by GitHub
parent 52d261e3c7
commit b64b17536a
12 changed files with 128 additions and 217 deletions
+3 -13
View File
@@ -18,7 +18,6 @@
//! The crate's tests.
use super::*;
use std::cell::RefCell;
use codec::Encode;
use frame_support::{
impl_outer_origin, impl_outer_dispatch, assert_noop, assert_ok, parameter_types,
@@ -154,6 +153,8 @@ parameter_types! {
pub const CooloffPeriod: u64 = 2;
pub const MaxVotes: u32 = 100;
pub const MaxProposals: u32 = MAX_PROPOSALS;
pub static PreimageByteDeposit: u64 = 0;
pub static InstantAllowed: bool = false;
}
ord_parameter_types! {
pub const One: u64 = 1;
@@ -171,18 +172,7 @@ impl Contains<u64> for OneToFive {
#[cfg(feature = "runtime-benchmarks")]
fn add(_m: &u64) {}
}
thread_local! {
static PREIMAGE_BYTE_DEPOSIT: RefCell<u64> = RefCell::new(0);
static INSTANT_ALLOWED: RefCell<bool> = RefCell::new(false);
}
pub struct PreimageByteDeposit;
impl Get<u64> for PreimageByteDeposit {
fn get() -> u64 { PREIMAGE_BYTE_DEPOSIT.with(|v| *v.borrow()) }
}
pub struct InstantAllowed;
impl Get<bool> for InstantAllowed {
fn get() -> bool { INSTANT_ALLOWED.with(|v| *v.borrow()) }
}
impl super::Trait for Test {
type Proposal = Call;
type Event = Event;