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
+14 -16
View File
@@ -810,8 +810,6 @@ mod tests {
use super::*;
use crate as pallet_transaction_payment;
use std::cell::RefCell;
use codec::Encode;
use sp_core::H256;
@@ -850,8 +848,8 @@ mod tests {
const CALL: &<Runtime as frame_system::Config>::Call =
&Call::Balances(BalancesCall::transfer { dest: 2, value: 69 });
thread_local! {
static EXTRINSIC_BASE_WEIGHT: RefCell<Weight> = RefCell::new(Weight::zero());
parameter_types! {
static ExtrinsicBaseWeight: Weight = Weight::zero();
}
pub struct BlockWeights;
@@ -860,7 +858,7 @@ mod tests {
frame_system::limits::BlockWeights::builder()
.base_block(Weight::zero())
.for_class(DispatchClass::all(), |weights| {
weights.base_extrinsic = EXTRINSIC_BASE_WEIGHT.with(|v| *v.borrow()).into();
weights.base_extrinsic = ExtrinsicBaseWeight::get().into();
})
.for_class(DispatchClass::non_mandatory(), |weights| {
weights.max_total = Weight::from_ref_time(1024).into();
@@ -932,9 +930,9 @@ mod tests {
}
}
thread_local! {
static TIP_UNBALANCED_AMOUNT: RefCell<u64> = RefCell::new(0);
static FEE_UNBALANCED_AMOUNT: RefCell<u64> = RefCell::new(0);
parameter_types! {
static TipUnbalancedAmount: u64 = 0;
static FeeUnbalancedAmount: u64 = 0;
}
pub struct DealWithFees;
@@ -943,9 +941,9 @@ mod tests {
mut fees_then_tips: impl Iterator<Item = pallet_balances::NegativeImbalance<Runtime>>,
) {
if let Some(fees) = fees_then_tips.next() {
FEE_UNBALANCED_AMOUNT.with(|a| *a.borrow_mut() += fees.peek());
FeeUnbalancedAmount::mutate(|a| *a += fees.peek());
if let Some(tips) = fees_then_tips.next() {
TIP_UNBALANCED_AMOUNT.with(|a| *a.borrow_mut() += tips.peek());
TipUnbalancedAmount::mutate(|a| *a += tips.peek());
}
}
}
@@ -1002,7 +1000,7 @@ mod tests {
self
}
fn set_constants(&self) {
EXTRINSIC_BASE_WEIGHT.with(|v| *v.borrow_mut() = self.base_weight);
ExtrinsicBaseWeight::mutate(|v| *v = self.base_weight);
TRANSACTION_BYTE_FEE.with(|v| *v.borrow_mut() = self.byte_fee);
WEIGHT_TO_FEE.with(|v| *v.borrow_mut() = self.weight_to_fee);
}
@@ -1074,10 +1072,10 @@ mod tests {
&Ok(())
));
assert_eq!(Balances::free_balance(1), 100 - 5 - 5 - 10);
assert_eq!(FEE_UNBALANCED_AMOUNT.with(|a| *a.borrow()), 5 + 5 + 10);
assert_eq!(TIP_UNBALANCED_AMOUNT.with(|a| *a.borrow()), 0);
assert_eq!(FeeUnbalancedAmount::get(), 5 + 5 + 10);
assert_eq!(TipUnbalancedAmount::get(), 0);
FEE_UNBALANCED_AMOUNT.with(|a| *a.borrow_mut() = 0);
FeeUnbalancedAmount::mutate(|a| *a = 0);
let pre = ChargeTransactionPayment::<Runtime>::from(5 /* tipped */)
.pre_dispatch(&2, CALL, &info_from_weight(Weight::from_ref_time(100)), len)
@@ -1092,8 +1090,8 @@ mod tests {
&Ok(())
));
assert_eq!(Balances::free_balance(2), 200 - 5 - 10 - 50 - 5);
assert_eq!(FEE_UNBALANCED_AMOUNT.with(|a| *a.borrow()), 5 + 10 + 50);
assert_eq!(TIP_UNBALANCED_AMOUNT.with(|a| *a.borrow()), 5);
assert_eq!(FeeUnbalancedAmount::get(), 5 + 10 + 50);
assert_eq!(TipUnbalancedAmount::get(), 5);
});
}