Skip to content

Commit

Permalink
Add decrease_balance related tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrylavrenov committed Jan 4, 2024
1 parent 8dc698a commit 27c26d3
Showing 1 changed file with 73 additions and 1 deletion.
74 changes: 73 additions & 1 deletion frame/evm-balances/src/tests/fungible.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
use frame_support::{
assert_noop, assert_ok,
traits::fungible::{Inspect, Unbalanced},
traits::{
fungible::{Inspect, Unbalanced},
tokens::Precision,
},
};
use sp_core::H160;
use sp_runtime::TokenError;
Expand Down Expand Up @@ -167,3 +170,72 @@ fn set_total_issuance_works() {
assert_eq!(EvmBalances::total_issuance(), set_total_issuance_balance);
});
}

#[test]
fn decrease_balance_works_exact_expendable() {
new_test_ext().execute_with_ext(|_| {
// Check test preconditions.
assert_eq!(EvmBalances::total_balance(&alice()), INIT_BALANCE);

let decreased_balance = 100;

// Invoke the function under test.
assert_ok!(EvmBalances::decrease_balance(
&alice(),
decreased_balance,
Precision::Exact,
Preservation::Expendable,
Fortitude::Polite
));

// Assert state changes.
assert_eq!(
EvmBalances::total_balance(&alice()),
INIT_BALANCE - decreased_balance
);
});
}

#[test]
fn decrease_balance_works_best_effort_preserve() {
new_test_ext().execute_with_ext(|_| {
// Check test preconditions.
assert_eq!(EvmBalances::total_balance(&alice()), INIT_BALANCE);

let decreased_balance = INIT_BALANCE + 1;

// Invoke the function under test.
assert_ok!(EvmBalances::decrease_balance(
&alice(),
decreased_balance,
Precision::BestEffort,
Preservation::Preserve,
Fortitude::Polite
));

// Assert state changes.
assert_eq!(EvmBalances::total_balance(&alice()), 1);
});
}

#[test]
fn decrease_balance_fails_funds_unavailable() {
new_test_ext().execute_with_ext(|_| {
// Check test preconditions.
assert_eq!(EvmBalances::total_balance(&alice()), INIT_BALANCE);

let decreased_balance = INIT_BALANCE + 1;

// Invoke the function under test.
assert_noop!(
EvmBalances::decrease_balance(
&alice(),
decreased_balance,
Precision::Exact,
Preservation::Preserve,
Fortitude::Polite
),
TokenError::FundsUnavailable
);
});
}

0 comments on commit 27c26d3

Please sign in to comment.