Skip to content
Snippets Groups Projects

add balance transfer tests

Merged Hugo Trentesaux requested to merge hugo-dev into master
1 file
+ 9
21
Compare changes
  • Side-by-side
  • Inline
@@ -25,6 +25,7 @@ use sp_keyring::AccountKeyring;
@@ -25,6 +25,7 @@ use sp_keyring::AccountKeyring;
/// test currency transfer
/// test currency transfer
/// (does not take fees into account because it's only calls, not extrinsics)
/// (does not take fees into account because it's only calls, not extrinsics)
 
/// test final balance of Alice and Eve accounts
#[test]
#[test]
fn test_transfer() {
fn test_transfer() {
ExtBuilder::new(1, 3, 4)
ExtBuilder::new(1, 3, 4)
@@ -52,23 +53,7 @@ fn test_transfer() {
@@ -52,23 +53,7 @@ fn test_transfer() {
})
})
}
}
/// test balance transfer
/// test balance transfer without enough balance
#[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]
#[test]
fn test_transfer_not_enough() {
fn test_transfer_not_enough() {
ExtBuilder::new(1, 3, 4)
ExtBuilder::new(1, 3, 4)
@@ -82,24 +67,26 @@ fn test_transfer_not_enough() {
@@ -82,24 +67,26 @@ fn test_transfer_not_enough() {
AccountKeyring::Dave.to_account_id().into(),
AccountKeyring::Dave.to_account_id().into(),
500
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]
#[test]
fn test_transfer_underflow() {
fn test_transfer_underflow() {
ExtBuilder::new(1, 3, 4)
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()
.build()
.execute_with(|| {
.execute_with(|| {
run_to_block(1);
run_to_block(1);
 
assert_eq!(Balances::total_issuance(), 400);
assert_noop!(
assert_noop!(
Balances::transfer_allow_death(
Balances::transfer_allow_death(
frame_system::RawOrigin::Signed(AccountKeyring::Alice.to_account_id()).into(),
frame_system::RawOrigin::Signed(AccountKeyring::Alice.to_account_id()).into(),
AccountKeyring::Dave.to_account_id().into(),
AccountKeyring::Dave.to_account_id().into(),
500
500 // larger than total issuance
),
),
sp_runtime::ArithmeticError::Underflow
sp_runtime::ArithmeticError::Underflow
);
);
@@ -107,6 +94,7 @@ fn test_transfer_underflow() {
@@ -107,6 +94,7 @@ fn test_transfer_underflow() {
}
}
/// test balance transfer without enough balance
/// test balance transfer without enough balance
 
/// can not transfer 500 when only 499 available
#[test]
#[test]
fn test_transfer_funds_unavailable() {
fn test_transfer_funds_unavailable() {
ExtBuilder::new(1, 3, 4)
ExtBuilder::new(1, 3, 4)
Loading