@@ -5,7 +5,7 @@ use crate::{
5
5
use frame_support:: {
6
6
assert_noop, assert_ok,
7
7
dispatch:: Pays ,
8
- traits:: { Currency , ExistenceRequirement , LockableCurrency , WithdrawReasons } ,
8
+ traits:: { LockableCurrency , WithdrawReasons } ,
9
9
BoundedVec ,
10
10
} ;
11
11
use frame_system:: { EventRecord , Phase , RawOrigin } ;
@@ -1505,11 +1505,10 @@ fn test_node_contract_billing_cycles_cancel_contract_during_cycle_without_balanc
1505
1505
let total_amount_billed = initial_twin_balance - usable_balance;
1506
1506
1507
1507
let extrinsic_fee = 10000 ;
1508
- Balances :: transfer (
1509
- & bob ( ) ,
1510
- & alice ( ) ,
1508
+ Balances :: transfer_keep_alive (
1509
+ RuntimeOrigin :: signed ( bob ( ) ) ,
1510
+ alice ( ) ,
1511
1511
initial_twin_balance - total_amount_billed - extrinsic_fee,
1512
- ExistenceRequirement :: AllowDeath ,
1513
1512
)
1514
1513
. unwrap ( ) ;
1515
1514
@@ -1642,13 +1641,7 @@ fn test_restore_node_contract_in_grace_works() {
1642
1641
run_to_block ( 31 , Some ( & mut pool_state) ) ;
1643
1642
run_to_block ( 41 , Some ( & mut pool_state) ) ;
1644
1643
// Transfer some balance to the owner of the contract to trigger the grace period to stop
1645
- Balances :: transfer (
1646
- & bob ( ) ,
1647
- & charlie ( ) ,
1648
- 100000000 ,
1649
- ExistenceRequirement :: AllowDeath ,
1650
- )
1651
- . unwrap ( ) ;
1644
+ Balances :: transfer_keep_alive ( RuntimeOrigin :: signed ( bob ( ) ) , charlie ( ) , 100000000 ) . unwrap ( ) ;
1652
1645
run_to_block ( 52 , Some ( & mut pool_state) ) ;
1653
1646
run_to_block ( 62 , Some ( & mut pool_state) ) ;
1654
1647
@@ -1861,7 +1854,9 @@ fn test_rent_contract_billing_cancel_should_bill_reserved_balance() {
1861
1854
. should_call_bill_contract ( contract_id, Ok ( Pays :: Yes . into ( ) ) , 11 ) ;
1862
1855
run_to_block ( 11 , Some ( & mut pool_state) ) ;
1863
1856
1864
- let ( amount_due_as_u128, discount_received) = calculate_tft_cost ( contract_id, 2 , 10 ) ;
1857
+ let bob_twin_id = 2 ;
1858
+ let ( amount_due_as_u128, discount_received) =
1859
+ calculate_tft_cost ( contract_id, bob_twin_id, 10 ) ;
1865
1860
assert_ne ! ( amount_due_as_u128, 0 ) ;
1866
1861
check_report_cost (
1867
1862
contract_id,
@@ -1870,39 +1865,33 @@ fn test_rent_contract_billing_cancel_should_bill_reserved_balance() {
1870
1865
discount_received. clone ( ) ,
1871
1866
) ;
1872
1867
1873
- let twin = TfgridModule :: twins ( 2 ) . unwrap ( ) ;
1874
- let usable_balance = Balances :: usable_balance ( & twin. account_id ) ;
1875
- let free_balance = Balances :: free_balance ( & twin. account_id ) ;
1876
- assert_ne ! ( usable_balance, free_balance) ;
1868
+ let bob_twin = TfgridModule :: twins ( bob_twin_id) . unwrap ( ) ;
1869
+ let usable_balance = Balances :: usable_balance ( & bob_twin. account_id ) ;
1870
+ let free_balance = Balances :: free_balance ( & bob_twin. account_id ) ;
1871
+ assert_ne ! ( usable_balance, free_balance) ; // there is some locked balance
1872
+ let locked_balance = free_balance - usable_balance;
1877
1873
1878
1874
run_to_block ( 13 , Some ( & mut pool_state) ) ;
1879
1875
// cancel contract
1880
1876
// it will bill before removing the contract and it should bill all
1881
1877
// reserved balance
1882
- let ( amount_due_as_u128, discount_received) = calculate_tft_cost ( contract_id, 2 , 2 ) ;
1878
+ let ( amount_due_as_u128, discount_received) =
1879
+ calculate_tft_cost ( contract_id, bob_twin_id, 2 ) ;
1880
+
1883
1881
assert_ok ! ( SmartContractModule :: cancel_contract(
1884
1882
RuntimeOrigin :: signed( bob( ) ) ,
1885
1883
contract_id
1886
1884
) ) ;
1887
1885
1888
- let twin = TfgridModule :: twins ( 2 ) . unwrap ( ) ;
1889
- let usable_balance = Balances :: usable_balance ( & twin. account_id ) ;
1890
- assert_ne ! ( usable_balance, 0 ) ;
1891
- Balances :: transfer (
1892
- & bob ( ) ,
1893
- & alice ( ) ,
1894
- usable_balance,
1895
- ExistenceRequirement :: AllowDeath ,
1896
- )
1897
- . unwrap ( ) ;
1898
-
1899
1886
// Last amount due is the same as the first one
1900
1887
assert_ne ! ( amount_due_as_u128, 0 ) ;
1901
1888
check_report_cost ( contract_id, amount_due_as_u128, 13 , discount_received) ;
1902
1889
1903
- let usable_balance = Balances :: usable_balance ( & twin. account_id ) ;
1904
- let free_balance = Balances :: free_balance ( & twin. account_id ) ;
1905
- assert_eq ! ( usable_balance, free_balance) ;
1890
+ let usable_balance = Balances :: usable_balance ( & bob_twin. account_id ) ;
1891
+ let past_free_balance = free_balance;
1892
+ let free_balance = Balances :: free_balance ( & bob_twin. account_id ) ;
1893
+ assert_eq ! ( usable_balance, free_balance) ; // there is no more locked balance
1894
+ assert_eq ! ( past_free_balance - free_balance, locked_balance) ; // locked balance was transfered to alice
1906
1895
} ) ;
1907
1896
}
1908
1897
@@ -2271,13 +2260,7 @@ fn test_restore_rent_contract_in_grace_works() {
2271
2260
run_to_block ( 31 , Some ( & mut pool_state) ) ;
2272
2261
2273
2262
// Transfer some balance to the owner of the contract to trigger the grace period to stop
2274
- Balances :: transfer (
2275
- & bob ( ) ,
2276
- & charlie ( ) ,
2277
- 100000000 ,
2278
- ExistenceRequirement :: AllowDeath ,
2279
- )
2280
- . unwrap ( ) ;
2263
+ Balances :: transfer_keep_alive ( RuntimeOrigin :: signed ( bob ( ) ) , charlie ( ) , 100000000 ) . unwrap ( ) ;
2281
2264
2282
2265
pool_state
2283
2266
. write ( )
@@ -2380,13 +2363,7 @@ fn test_restore_rent_contract_and_node_contracts_in_grace_works() {
2380
2363
run_to_block ( 32 , Some ( & mut pool_state) ) ;
2381
2364
2382
2365
// Transfer some balance to the owner of the contract to trigger the grace period to stop
2383
- Balances :: transfer (
2384
- & bob ( ) ,
2385
- & charlie ( ) ,
2386
- 100000000 ,
2387
- ExistenceRequirement :: AllowDeath ,
2388
- )
2389
- . unwrap ( ) ;
2366
+ Balances :: transfer_keep_alive ( RuntimeOrigin :: signed ( bob ( ) ) , charlie ( ) , 100000000 ) . unwrap ( ) ;
2390
2367
2391
2368
pool_state
2392
2369
. write ( )
@@ -3342,17 +3319,11 @@ fn test_service_contract_bill_out_of_funds_fails() {
3342
3319
approve_service_consumer_contract ( service_contract_id) ;
3343
3320
3344
3321
// Drain consumer account
3345
- let consumer_twin = TfgridModule :: twins ( 2 ) . unwrap ( ) ;
3346
- let consumer_balance = Balances :: free_balance ( & consumer_twin. account_id ) ;
3347
- Balances :: transfer (
3348
- & bob ( ) ,
3349
- & alice ( ) ,
3350
- consumer_balance,
3351
- ExistenceRequirement :: AllowDeath ,
3352
- )
3353
- . unwrap ( ) ;
3354
- let consumer_balance = Balances :: free_balance ( & consumer_twin. account_id ) ;
3355
- assert_eq ! ( consumer_balance, 0 ) ;
3322
+ let consumer_twin_id = 2 ;
3323
+ let consumer_twin = TfgridModule :: twins ( consumer_twin_id) . unwrap ( ) ;
3324
+ Balances :: transfer_all ( RuntimeOrigin :: signed ( bob ( ) ) , alice ( ) , true ) . unwrap ( ) ;
3325
+ let consumer_free_balance = Balances :: free_balance ( & consumer_twin. account_id ) ;
3326
+ assert_eq ! ( consumer_free_balance, EXISTENTIAL_DEPOSIT ) ;
3356
3327
3357
3328
// Bill 1h after contract approval
3358
3329
run_to_block ( 601 , Some ( & mut pool_state) ) ;
@@ -3412,7 +3383,7 @@ fn test_lock() {
3412
3383
3413
3384
let id: u64 = 1 ;
3414
3385
// Try to lock less than EXISTENTIAL_DEPOSIT should fail
3415
- Balances :: set_lock ( id. to_be_bytes ( ) , & bob ( ) , 100 , WithdrawReasons :: all ( ) ) ;
3386
+ Balances :: set_lock ( id. to_be_bytes ( ) , & bob ( ) , 1 , WithdrawReasons :: all ( ) ) ;
3416
3387
3417
3388
// usable balance should now return free balance - EXISTENTIAL_DEPOSIT cause there was some activity
3418
3389
let usable_balance = Balances :: usable_balance ( & bob ( ) ) ;
@@ -3421,7 +3392,7 @@ fn test_lock() {
3421
3392
3422
3393
// ----- INITIAL ------ //
3423
3394
// Try to lock more than EXISTENTIAL_DEPOSIT should succeed
3424
- let to_lock = 100 + EXISTENTIAL_DEPOSIT ;
3395
+ let to_lock = 1 + EXISTENTIAL_DEPOSIT ;
3425
3396
3426
3397
Balances :: set_lock ( id. to_be_bytes ( ) , & bob ( ) , to_lock, WithdrawReasons :: all ( ) ) ;
3427
3398
@@ -3432,7 +3403,7 @@ fn test_lock() {
3432
3403
3433
3404
// ----- UPDATE ------ //
3434
3405
// updating a lock should succeed
3435
- let to_lock = 500 + EXISTENTIAL_DEPOSIT ;
3406
+ let to_lock = 10 + EXISTENTIAL_DEPOSIT ;
3436
3407
3437
3408
Balances :: set_lock ( id. to_be_bytes ( ) , & bob ( ) , to_lock, WithdrawReasons :: all ( ) ) ;
3438
3409
0 commit comments