From f34c95ff4a0ae347e09e7fa02634006f3a3ac703 Mon Sep 17 00:00:00 2001 From: Hugo Trentesaux <hugo@trentesaux.fr> Date: Thu, 16 Nov 2023 12:06:07 +0100 Subject: [PATCH] add comments --- runtime/gdev/tests/balance_tests.rs | 30 +++++++++-------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/runtime/gdev/tests/balance_tests.rs b/runtime/gdev/tests/balance_tests.rs index 8db1efb15..de2ac25c8 100644 --- a/runtime/gdev/tests/balance_tests.rs +++ b/runtime/gdev/tests/balance_tests.rs @@ -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) -- GitLab