Add more asserts and debug_asserts (#8541)

* Add more asserts and debug_asserts

fixing #8106

* Remove assignments

* convert debug_assert to runtime assert
This commit is contained in:
Falco Hirschenberger
2021-04-07 23:40:28 +02:00
committed by GitHub
parent a600e278ed
commit e932c3ecd2
14 changed files with 66 additions and 58 deletions
+2 -1
View File
@@ -44,7 +44,8 @@ benchmarks_instance_pallet! {
let balance = existential_deposit.saturating_mul(ED_MULTIPLIER.into());
let _ = <Balances<T, I> as Currency<_>>::make_free_balance_be(&caller, balance);
// Transfer `e - 1` existential deposits + 1 unit, which guarantees to create one account, and reap this user.
// Transfer `e - 1` existential deposits + 1 unit, which guarantees to create one account,
// and reap this user.
let recipient: T::AccountId = account("recipient", 0, SEED);
let recipient_lookup: <T::Lookup as StaticLookup>::Source = T::Lookup::unlookup(recipient.clone());
let transfer_amount = existential_deposit.saturating_mul((ED_MULTIPLIER - 1).into()) + 1u32.into();
+10 -6
View File
@@ -169,13 +169,13 @@ macro_rules! decl_tests {
&info_from_weight(1),
1,
).is_err());
assert!(<ChargeTransactionPayment<$test> as SignedExtension>::pre_dispatch(
assert_ok!(<ChargeTransactionPayment<$test> as SignedExtension>::pre_dispatch(
ChargeTransactionPayment::from(0),
&1,
CALL,
&info_from_weight(1),
1,
).is_ok());
));
Balances::set_lock(ID_1, &1, 10, WithdrawReasons::TRANSACTION_PAYMENT);
assert_ok!(<Balances as Currency<_>>::transfer(&1, &2, 1, AllowDeath));
@@ -394,7 +394,7 @@ macro_rules! decl_tests {
fn refunding_balance_should_work() {
<$ext_builder>::default().build().execute_with(|| {
let _ = Balances::deposit_creating(&1, 42);
assert!(Balances::mutate_account(&1, |a| a.reserved = 69).is_ok());
assert_ok!(Balances::mutate_account(&1, |a| a.reserved = 69));
Balances::unreserve(&1, 69);
assert_eq!(Balances::free_balance(1), 111);
assert_eq!(Balances::reserved_balance(1), 0);
@@ -669,7 +669,9 @@ macro_rules! decl_tests {
assert_eq!(Balances::reserved_balance(1), 50);
// Reserve some free balance
let _ = Balances::slash(&1, 1);
let res = Balances::slash(&1, 1);
assert_eq!(res, (NegativeImbalance::new(1), 0));
// The account should be dead.
assert_eq!(Balances::free_balance(1), 0);
assert_eq!(Balances::reserved_balance(1), 0);
@@ -727,7 +729,8 @@ macro_rules! decl_tests {
]
);
let _ = Balances::slash(&1, 1);
let res = Balances::slash(&1, 1);
assert_eq!(res, (NegativeImbalance::new(1), 0));
assert_eq!(
events(),
@@ -756,7 +759,8 @@ macro_rules! decl_tests {
]
);
let _ = Balances::slash(&1, 100);
let res = Balances::slash(&1, 100);
assert_eq!(res, (NegativeImbalance::new(100), 0));
assert_eq!(
events(),
+4 -2
View File
@@ -175,12 +175,14 @@ fn emit_events_with_no_existential_deposit_suicide_with_dust() {
]
);
let _ = Balances::slash(&1, 98);
let res = Balances::slash(&1, 98);
assert_eq!(res, (NegativeImbalance::new(98), 0));
// no events
assert_eq!(events(), []);
let _ = Balances::slash(&1, 1);
let res = Balances::slash(&1, 1);
assert_eq!(res, (NegativeImbalance::new(1), 0));
assert_eq!(
events(),
@@ -105,7 +105,7 @@ impl pallet_transaction_payment::Config for Test {
pub struct OnDustRemoval;
impl OnUnbalanced<NegativeImbalance<Test>> for OnDustRemoval {
fn on_nonzero_unbalanced(amount: NegativeImbalance<Test>) {
let _ = Balances::resolve_into_existing(&1, amount);
assert_ok!(Balances::resolve_into_existing(&1, amount));
}
}
parameter_types! {