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
+85 -98
View File
@@ -441,23 +441,23 @@ mod tests {
exec::AccountIdOf,
tests::{Test, ALICE, BOB, CHARLIE},
};
use frame_support::parameter_types;
use pretty_assertions::assert_eq;
use std::cell::RefCell;
type TestMeter = RawMeter<Test, TestExt, Root>;
thread_local! {
static TEST_EXT: RefCell<TestExt> = RefCell::new(Default::default());
parameter_types! {
static TestExtTestValue: TestExt = Default::default();
}
#[derive(Debug, PartialEq, Eq)]
#[derive(Debug, PartialEq, Eq, Clone)]
struct LimitCheck {
origin: AccountIdOf<Test>,
limit: BalanceOf<Test>,
min_leftover: BalanceOf<Test>,
}
#[derive(Debug, PartialEq, Eq)]
#[derive(Debug, PartialEq, Eq, Clone)]
struct Charge {
origin: AccountIdOf<Test>,
contract: AccountIdOf<Test>,
@@ -465,8 +465,8 @@ mod tests {
terminated: bool,
}
#[derive(Default, Debug, PartialEq, Eq)]
struct TestExt {
#[derive(Default, Debug, PartialEq, Eq, Clone)]
pub struct TestExt {
limit_checks: Vec<LimitCheck>,
charges: Vec<Charge>,
}
@@ -485,12 +485,9 @@ mod tests {
min_leftover: BalanceOf<Test>,
) -> Result<BalanceOf<Test>, DispatchError> {
let limit = limit.unwrap_or(42);
TEST_EXT.with(|ext| {
ext.borrow_mut().limit_checks.push(LimitCheck {
origin: origin.clone(),
limit,
min_leftover,
})
TestExtTestValue::mutate(|ext| {
ext.limit_checks
.push(LimitCheck { origin: origin.clone(), limit, min_leftover })
});
Ok(limit)
}
@@ -501,8 +498,8 @@ mod tests {
amount: &DepositOf<Test>,
terminated: bool,
) {
TEST_EXT.with(|ext| {
ext.borrow_mut().charges.push(Charge {
TestExtTestValue::mutate(|ext| {
ext.charges.push(Charge {
origin: origin.clone(),
contract: contract.clone(),
amount: amount.clone(),
@@ -513,7 +510,7 @@ mod tests {
}
fn clear_ext() {
TEST_EXT.with(|ext| ext.borrow_mut().clear())
TestExtTestValue::mutate(|ext| ext.clear())
}
fn new_info(deposit: BalanceOf<Test>) -> ContractInfo<Test> {
@@ -533,15 +530,13 @@ mod tests {
TestMeter::new(&ALICE, Some(1_000), 0).unwrap();
TEST_EXT.with(|ext| {
assert_eq!(
*ext.borrow(),
TestExt {
limit_checks: vec![LimitCheck { origin: ALICE, limit: 1_000, min_leftover: 0 }],
..Default::default()
}
)
});
assert_eq!(
TestExtTestValue::get(),
TestExt {
limit_checks: vec![LimitCheck { origin: ALICE, limit: 1_000, min_leftover: 0 }],
..Default::default()
}
)
}
#[test]
@@ -556,15 +551,13 @@ mod tests {
nested0.charge(&Default::default()).unwrap();
meter.absorb(nested0, &ALICE, &BOB, None);
TEST_EXT.with(|ext| {
assert_eq!(
*ext.borrow(),
TestExt {
limit_checks: vec![LimitCheck { origin: ALICE, limit: 1_000, min_leftover: 0 }],
..Default::default()
}
)
});
assert_eq!(
TestExtTestValue::get(),
TestExt {
limit_checks: vec![LimitCheck { origin: ALICE, limit: 1_000, min_leftover: 0 }],
..Default::default()
}
)
}
#[test]
@@ -582,20 +575,18 @@ mod tests {
.unwrap();
meter.absorb(nested0, &ALICE, &BOB, None);
TEST_EXT.with(|ext| {
assert_eq!(
*ext.borrow(),
TestExt {
limit_checks: vec![LimitCheck { origin: ALICE, limit: 1_000, min_leftover: 0 }],
charges: vec![Charge {
origin: ALICE,
contract: BOB,
amount: Deposit::Charge(<Test as Config>::Currency::minimum_balance() * 2),
terminated: false,
}]
}
)
});
assert_eq!(
TestExtTestValue::get(),
TestExt {
limit_checks: vec![LimitCheck { origin: ALICE, limit: 1_000, min_leftover: 0 }],
charges: vec![Charge {
origin: ALICE,
contract: BOB,
amount: Deposit::Charge(<Test as Config>::Currency::minimum_balance() * 2),
terminated: false,
}]
}
)
}
#[test]
@@ -638,34 +629,32 @@ mod tests {
assert_eq!(nested1_info.storage_deposit, 40);
assert_eq!(nested2_info.storage_deposit, min_balance);
TEST_EXT.with(|ext| {
assert_eq!(
*ext.borrow(),
TestExt {
limit_checks: vec![LimitCheck { origin: ALICE, limit: 1_000, min_leftover: 0 }],
charges: vec![
Charge {
origin: ALICE,
contract: CHARLIE,
amount: Deposit::Refund(10),
terminated: false
},
Charge {
origin: ALICE,
contract: CHARLIE,
amount: Deposit::Refund(4),
terminated: false
},
Charge {
origin: ALICE,
contract: BOB,
amount: Deposit::Charge(2),
terminated: false
}
]
}
)
});
assert_eq!(
TestExtTestValue::get(),
TestExt {
limit_checks: vec![LimitCheck { origin: ALICE, limit: 1_000, min_leftover: 0 }],
charges: vec![
Charge {
origin: ALICE,
contract: CHARLIE,
amount: Deposit::Refund(10),
terminated: false
},
Charge {
origin: ALICE,
contract: CHARLIE,
amount: Deposit::Refund(4),
terminated: false
},
Charge {
origin: ALICE,
contract: BOB,
amount: Deposit::Charge(2),
terminated: false
}
]
}
)
}
#[test]
@@ -697,27 +686,25 @@ mod tests {
meter.absorb(nested0, &ALICE, &BOB, None);
drop(meter);
TEST_EXT.with(|ext| {
assert_eq!(
*ext.borrow(),
TestExt {
limit_checks: vec![LimitCheck { origin: ALICE, limit: 1_000, min_leftover: 0 }],
charges: vec![
Charge {
origin: ALICE,
contract: CHARLIE,
amount: Deposit::Refund(400),
terminated: true
},
Charge {
origin: ALICE,
contract: BOB,
amount: Deposit::Charge(12),
terminated: false
}
]
}
)
});
assert_eq!(
TestExtTestValue::get(),
TestExt {
limit_checks: vec![LimitCheck { origin: ALICE, limit: 1_000, min_leftover: 0 }],
charges: vec![
Charge {
origin: ALICE,
contract: CHARLIE,
amount: Deposit::Refund(400),
terminated: true
},
Charge {
origin: ALICE,
contract: BOB,
amount: Deposit::Charge(12),
terminated: false
}
]
}
)
}
}