Skip to content
Snippets Groups Projects
Commit f34c95ff authored by Hugo Trentesaux's avatar Hugo Trentesaux Committed by Hugo Trentesaux
Browse files

add comments

parent 341c2e8d
Branches
Tags
1 merge request!193add balance transfer tests
Pipeline #34252 waiting for manual action
......@@ -25,6 +25,7 @@ use sp_keyring::AccountKeyring;
/// test currency transfer
/// (does not take fees into account because it's only calls, not extrinsics)
/// test final balance of Alice and Eve accounts
#[test]
fn test_transfer() {
ExtBuilder::new(1, 3, 4)
......@@ -52,23 +53,7 @@ fn test_transfer() {
})
}
/// test balance transfer
#[test]
fn test_transfer() {
ExtBuilder::new(1, 3, 4)
.with_initial_balances(vec![(AccountKeyring::Alice.to_account_id(), 600)])
.build()
.execute_with(|| {
run_to_block(1);
assert_ok!(Balances::transfer_allow_death(
frame_system::RawOrigin::Signed(AccountKeyring::Alice.to_account_id()).into(),
AccountKeyring::Dave.to_account_id().into(),
500
));
})
}
/// test balance transfer without enough balance (would prefer TokenError::BelowMinimum or NotExpendable)
/// test balance transfer without enough balance
#[test]
fn test_transfer_not_enough() {
ExtBuilder::new(1, 3, 4)
......@@ -82,24 +67,26 @@ fn test_transfer_not_enough() {
AccountKeyring::Dave.to_account_id().into(),
500
),
sp_runtime::TokenError::Frozen
sp_runtime::TokenError::Frozen // frozen because trying to transfer more than liquid
);
})
}
/// test balance transfer without enough balance (would prefer TokenError::FundsUnavailable)
/// test balance transfer without enough balance
/// in this case, it is the total issuance which cause problem, hence the arithmetic underflow
#[test]
fn test_transfer_underflow() {
ExtBuilder::new(1, 3, 4)
.with_initial_balances(vec![(AccountKeyring::Alice.to_account_id(), 499)])
.with_initial_balances(vec![(AccountKeyring::Alice.to_account_id(), 400)])
.build()
.execute_with(|| {
run_to_block(1);
assert_eq!(Balances::total_issuance(), 400);
assert_noop!(
Balances::transfer_allow_death(
frame_system::RawOrigin::Signed(AccountKeyring::Alice.to_account_id()).into(),
AccountKeyring::Dave.to_account_id().into(),
500
500 // larger than total issuance
),
sp_runtime::ArithmeticError::Underflow
);
......@@ -107,6 +94,7 @@ fn test_transfer_underflow() {
}
/// test balance transfer without enough balance
/// can not transfer 500 when only 499 available
#[test]
fn test_transfer_funds_unavailable() {
ExtBuilder::new(1, 3, 4)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment