Use parameter_types instead of thread_local for test-setup (#12036)

* Edit to Assets. parameter_types

* fixes

* Test Fixes. WIP

* Edits to pallet-aura

* Camel Case

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>

* Implementation of mutate fn

* update to pallet-aura

* Update to frame-system. Fixes

* Update to frame-support-test. CamelCases

* Updates to frame- contracts, offences, staking, bounties, child bounties

* Edit to mutate fn. Changes to frame-contracts. CamelCase pallet-aura

* Edits to frame-contracts & executive

* cargo +nightly fmt

* unused import removed

* unused import removed

* cargo +nightly fmt

* minor adjustment

* updates

* updates

* cargo +nightly fmt

* cargo +nightly fmt

* take fn implemented

* update

* update

* Fixes to CallFilter

* cargo +nightly fmt

* final fixes

* Default changed to $value

* Update frame/support/src/lib.rs

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
This commit is contained in:
Boluwatife Bakre
2022-09-08 11:46:25 +01:00
committed by GitHub
parent bec123a50f
commit 3ec4d13e9f
32 changed files with 378 additions and 402 deletions
+17 -12
View File
@@ -21,7 +21,7 @@ use super::*;
use crate as pallet_assets;
use frame_support::{
construct_runtime,
construct_runtime, parameter_types,
traits::{ConstU32, ConstU64, GenesisBuild},
};
use sp_core::H256;
@@ -101,44 +101,49 @@ impl Config for Test {
type Extra = ();
}
use std::{cell::RefCell, collections::HashMap};
use std::collections::HashMap;
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
pub(crate) enum Hook {
pub enum Hook {
Died(u32, u64),
}
thread_local! {
static FROZEN: RefCell<HashMap<(u32, u64), u64>> = RefCell::new(Default::default());
static HOOKS: RefCell<Vec<Hook>> = RefCell::new(Default::default());
parameter_types! {
static Frozen: HashMap<(u32, u64), u64> = Default::default();
static Hooks: Vec<Hook> = Default::default();
}
pub struct TestFreezer;
impl FrozenBalance<u32, u64, u64> for TestFreezer {
fn frozen_balance(asset: u32, who: &u64) -> Option<u64> {
FROZEN.with(|f| f.borrow().get(&(asset, *who)).cloned())
Frozen::get().get(&(asset, *who)).cloned()
}
fn died(asset: u32, who: &u64) {
HOOKS.with(|h| h.borrow_mut().push(Hook::Died(asset, *who)));
Hooks::mutate(|v| v.push(Hook::Died(asset, *who)));
// Sanity check: dead accounts have no balance.
assert!(Assets::balance(asset, *who).is_zero());
}
}
pub(crate) fn set_frozen_balance(asset: u32, who: u64, amount: u64) {
FROZEN.with(|f| f.borrow_mut().insert((asset, who), amount));
Frozen::mutate(|v| {
v.insert((asset, who), amount);
});
}
pub(crate) fn clear_frozen_balance(asset: u32, who: u64) {
FROZEN.with(|f| f.borrow_mut().remove(&(asset, who)));
Frozen::mutate(|v| {
v.remove(&(asset, who));
});
}
pub(crate) fn hooks() -> Vec<Hook> {
HOOKS.with(|h| h.borrow().clone())
Hooks::get().clone()
}
pub(crate) fn take_hooks() -> Vec<Hook> {
HOOKS.with(|h| h.take())
Hooks::take()
}
pub(crate) fn new_test_ext() -> sp_io::TestExternalities {