@@ -981,7 +981,8 @@ fn test_node_contract_billing_details() {
981
981
982
982
TFTPriceModule :: set_prices ( RuntimeOrigin :: signed ( alice ( ) ) , 50 , 101 ) . unwrap ( ) ;
983
983
984
- let twin = TfgridModule :: twins ( 2 ) . unwrap ( ) ;
984
+ let twin_id = 2 ;
985
+ let twin = TfgridModule :: twins ( twin_id) . unwrap ( ) ;
985
986
let initial_twin_balance = Balances :: total_balance ( & twin. account_id ) ;
986
987
987
988
assert_ok ! ( SmartContractModule :: create_node_contract(
@@ -1040,7 +1041,8 @@ fn test_node_contract_billing_works_for_non_existing_accounts() {
1040
1041
1041
1042
TFTPriceModule :: set_prices ( RuntimeOrigin :: signed ( alice ( ) ) , 50 , 101 ) . unwrap ( ) ;
1042
1043
1043
- let twin = TfgridModule :: twins ( 2 ) . unwrap ( ) ;
1044
+ let twin_id = 2 ;
1045
+ let twin = TfgridModule :: twins ( twin_id) . unwrap ( ) ;
1044
1046
let initial_twin_balance = Balances :: total_balance ( & twin. account_id ) ;
1045
1047
1046
1048
assert_ok ! ( SmartContractModule :: create_node_contract(
@@ -1124,7 +1126,8 @@ fn test_billing_node_contract_in_graceperiod_should_reset_unbilled_network_consu
1124
1126
assert_eq ! ( c1. state, types:: ContractState :: GracePeriod ( 11 ) ) ;
1125
1127
1126
1128
// contract payment should be overdrawn
1127
- let contract_payment_state = SmartContractModule :: contract_payment_state ( contract_id) . unwrap ( ) ;
1129
+ let contract_payment_state =
1130
+ SmartContractModule :: contract_payment_state ( contract_id) . unwrap ( ) ;
1128
1131
assert_ne ! ( contract_payment_state. get_overdraft( ) , 0 ) ;
1129
1132
1130
1133
// amount unbilled should have been reset after adding the amount to the contract overdraft
@@ -1148,7 +1151,8 @@ fn test_node_contract_billing_details_with_solution_provider() {
1148
1151
1149
1152
TFTPriceModule :: set_prices ( RuntimeOrigin :: signed ( alice ( ) ) , 50 , 101 ) . unwrap ( ) ;
1150
1153
1151
- let twin = TfgridModule :: twins ( 2 ) . unwrap ( ) ;
1154
+ let twin_id = 2 ;
1155
+ let twin = TfgridModule :: twins ( twin_id) . unwrap ( ) ;
1152
1156
let initial_twin_balance = Balances :: free_balance ( & twin. account_id ) ;
1153
1157
let initial_farmer_balance = Balances :: free_balance ( alice ( ) ) ;
1154
1158
@@ -1623,7 +1627,8 @@ fn test_node_contract_billing_cycles_cancel_contract_during_cycle_without_balanc
1623
1627
1624
1628
TFTPriceModule :: set_prices ( RuntimeOrigin :: signed ( alice ( ) ) , 50 , 101 ) . unwrap ( ) ;
1625
1629
1626
- let twin = TfgridModule :: twins ( 2 ) . unwrap ( ) ;
1630
+ let twin_id = 2 ;
1631
+ let twin = TfgridModule :: twins ( twin_id) . unwrap ( ) ;
1627
1632
let initial_twin_balance = Balances :: free_balance ( & twin. account_id ) ;
1628
1633
info ! ( "initial twin balance: {:?}" , initial_twin_balance) ;
1629
1634
let initial_farmer_balance = Balances :: free_balance ( alice ( ) ) ;
@@ -1637,7 +1642,6 @@ fn test_node_contract_billing_cycles_cancel_contract_during_cycle_without_balanc
1637
1642
None
1638
1643
) ) ;
1639
1644
let contract_id = 1 ;
1640
- let twin_id = 2 ;
1641
1645
push_contract_resources_used ( contract_id) ;
1642
1646
1643
1647
let ( amount_due_1, discount_received) = calculate_tft_cost ( contract_id, twin_id, 10 ) ;
@@ -1663,7 +1667,7 @@ fn test_node_contract_billing_cycles_cancel_contract_during_cycle_without_balanc
1663
1667
info ! ( "total amount billed: {:?}" , total_amount_billed) ;
1664
1668
1665
1669
let leave = 1000 ;
1666
- Balances :: transfer (
1670
+ Balances :: transfer_allow_death (
1667
1671
RuntimeOrigin :: signed ( bob ( ) ) ,
1668
1672
charlie ( ) ,
1669
1673
initial_twin_balance - total_amount_billed - leave,
@@ -1816,7 +1820,7 @@ fn test_restore_node_contract_in_grace_works() {
1816
1820
run_to_block ( 31 , Some ( & mut pool_state) ) ;
1817
1821
run_to_block ( 41 , Some ( & mut pool_state) ) ;
1818
1822
// Transfer some balance to the owner of the contract to trigger the grace period to stop
1819
- Balances :: transfer ( RuntimeOrigin :: signed ( bob ( ) ) , charlie ( ) , 100000000 ) . unwrap ( ) ;
1823
+ Balances :: transfer_allow_death ( RuntimeOrigin :: signed ( bob ( ) ) , charlie ( ) , 100000000 ) . unwrap ( ) ;
1820
1824
run_to_block ( 52 , Some ( & mut pool_state) ) ;
1821
1825
run_to_block ( 62 , Some ( & mut pool_state) ) ;
1822
1826
@@ -2009,6 +2013,7 @@ fn test_rent_contract_billing() {
2009
2013
node_id,
2010
2014
None
2011
2015
) ) ;
2016
+ let twin_id = 2 ;
2012
2017
let contract_id = 1 ;
2013
2018
2014
2019
let contract = SmartContractModule :: contracts ( contract_id) . unwrap ( ) ;
@@ -2038,7 +2043,7 @@ fn test_rent_contract_billing() {
2038
2043
run_to_block ( 21 , Some ( & mut pool_state) ) ;
2039
2044
2040
2045
// should bill partial cycle 2 [15-21], 6 blocks
2041
- let ( amount_due_as_u128, discount_received) = calculate_tft_cost ( contract_id, 2 , 6 ) ;
2046
+ let ( amount_due_as_u128, discount_received) = calculate_tft_cost ( contract_id, twin_id , 6 ) ;
2042
2047
assert_ne ! ( amount_due_as_u128, 0 ) ;
2043
2048
check_report_cost ( contract_id, amount_due_as_u128, 21 , discount_received) ;
2044
2049
@@ -2075,7 +2080,7 @@ fn test_rent_contract_billing() {
2075
2080
run_to_block ( 51 , Some ( & mut pool_state) ) ;
2076
2081
2077
2082
// should bill partial cycle 5 [45-51], 6 blocks
2078
- let ( amount_due_as_u128, discount_received) = calculate_tft_cost ( contract_id, 2 , 6 ) ;
2083
+ let ( amount_due_as_u128, discount_received) = calculate_tft_cost ( contract_id, twin_id , 6 ) ;
2079
2084
assert_ne ! ( amount_due_as_u128, 0 ) ;
2080
2085
check_report_cost ( contract_id, amount_due_as_u128, 51 , discount_received) ;
2081
2086
} ) ;
@@ -2159,6 +2164,7 @@ fn test_rent_contract_billing_cancel_should_bill_reserved_balance() {
2159
2164
node_id,
2160
2165
None
2161
2166
) ) ;
2167
+ let twin_id = 2 ;
2162
2168
let contract_id = 1 ;
2163
2169
2164
2170
let contract = SmartContractModule :: contracts ( contract_id) . unwrap ( ) ;
@@ -2173,7 +2179,8 @@ fn test_rent_contract_billing_cancel_should_bill_reserved_balance() {
2173
2179
. should_call_bill_contract ( contract_id, Ok ( Pays :: Yes . into ( ) ) , 11 ) ;
2174
2180
run_to_block ( 11 , Some ( & mut pool_state) ) ;
2175
2181
2176
- let ( amount_due_1_as_u128, discount_received) = calculate_tft_cost ( contract_id, 2 , 10 ) ;
2182
+ let ( amount_due_1_as_u128, discount_received) =
2183
+ calculate_tft_cost ( contract_id, twin_id, 10 ) ;
2177
2184
assert_ne ! ( amount_due_1_as_u128, 0 ) ;
2178
2185
check_report_cost (
2179
2186
contract_id,
@@ -2182,7 +2189,7 @@ fn test_rent_contract_billing_cancel_should_bill_reserved_balance() {
2182
2189
discount_received. clone ( ) ,
2183
2190
) ;
2184
2191
2185
- let twin = TfgridModule :: twins ( 2 ) . unwrap ( ) ;
2192
+ let twin = TfgridModule :: twins ( twin_id ) . unwrap ( ) ;
2186
2193
let total_balance = Balances :: total_balance ( & twin. account_id ) ;
2187
2194
let free_balance = Balances :: free_balance ( & twin. account_id ) ;
2188
2195
assert_ne ! ( total_balance, free_balance) ;
@@ -2191,16 +2198,16 @@ fn test_rent_contract_billing_cancel_should_bill_reserved_balance() {
2191
2198
// cancel contract
2192
2199
// it will bill before removing the contract and it should bill all
2193
2200
// reserved balance
2194
- let ( amount_due_2_as_u128, discount_received) = calculate_tft_cost ( contract_id, 2 , 2 ) ;
2201
+ let ( amount_due_2_as_u128, discount_received) = calculate_tft_cost ( contract_id, twin_id , 2 ) ;
2195
2202
assert_ok ! ( SmartContractModule :: cancel_contract(
2196
2203
RuntimeOrigin :: signed( bob( ) ) ,
2197
2204
contract_id
2198
2205
) ) ;
2199
2206
2200
- let twin = TfgridModule :: twins ( 2 ) . unwrap ( ) ;
2201
2207
let usable_balance = Balances :: usable_balance ( & twin. account_id ) ;
2202
2208
assert_ne ! ( usable_balance, 0 ) ;
2203
- Balances :: transfer ( RuntimeOrigin :: signed ( bob ( ) ) , alice ( ) , usable_balance) . unwrap ( ) ;
2209
+ Balances :: transfer_allow_death ( RuntimeOrigin :: signed ( bob ( ) ) , alice ( ) , usable_balance)
2210
+ . unwrap ( ) ;
2204
2211
2205
2212
// Last amount due is not the same as the first one
2206
2213
assert_ne ! ( amount_due_1_as_u128, amount_due_2_as_u128) ;
@@ -2229,9 +2236,10 @@ fn test_rent_contract_overdrawn_and_partial_bill() {
2229
2236
node_id,
2230
2237
None
2231
2238
) ) ;
2239
+ let twin_id = 3 ;
2232
2240
let contract_id = 1 ;
2233
2241
2234
- let twin = TfgridModule :: twins ( 3 ) . unwrap ( ) ;
2242
+ let twin = TfgridModule :: twins ( twin_id ) . unwrap ( ) ;
2235
2243
let initial_reservable_balance =
2236
2244
Balances :: usable_balance ( & twin. account_id ) - EXISTENTIAL_DEPOSIT ;
2237
2245
@@ -2247,7 +2255,7 @@ fn test_rent_contract_overdrawn_and_partial_bill() {
2247
2255
. should_call_bill_contract ( contract_id, Ok ( Pays :: Yes . into ( ) ) , 11 ) ;
2248
2256
run_to_block ( 11 , Some ( & mut pool_state) ) ;
2249
2257
2250
- let ( amount_due_per_cycle, _) = calculate_tft_cost ( contract_id, 2 , 10 ) ;
2258
+ let ( amount_due_per_cycle, _) = calculate_tft_cost ( contract_id, twin_id , 10 ) ;
2251
2259
assert_ne ! ( amount_due_per_cycle, 0 ) ;
2252
2260
2253
2261
// expect contractPaymentOverdarwn event with partially billed amount
@@ -2264,7 +2272,8 @@ fn test_rent_contract_overdrawn_and_partial_bill() {
2264
2272
true
2265
2273
) ;
2266
2274
2267
- let contract_payment_state = SmartContractModule :: contract_payment_state ( contract_id) . unwrap ( ) ;
2275
+ let contract_payment_state =
2276
+ SmartContractModule :: contract_payment_state ( contract_id) . unwrap ( ) ;
2268
2277
assert_eq ! (
2269
2278
contract_payment_state. get_reserve( ) ,
2270
2279
initial_reservable_balance
@@ -2295,7 +2304,8 @@ fn test_rent_contract_overdrawn_and_partial_bill() {
2295
2304
) ) ) ,
2296
2305
true
2297
2306
) ;
2298
- let contract_payment_state = SmartContractModule :: contract_payment_state ( contract_id) . unwrap ( ) ;
2307
+ let contract_payment_state =
2308
+ SmartContractModule :: contract_payment_state ( contract_id) . unwrap ( ) ;
2299
2309
assert_eq ! (
2300
2310
contract_payment_state. get_reserve( ) ,
2301
2311
initial_reservable_balance
@@ -2307,7 +2317,7 @@ fn test_rent_contract_overdrawn_and_partial_bill() {
2307
2317
let should_have_next_cycle = amount_due_per_cycle * 3 - initial_reservable_balance;
2308
2318
2309
2319
// transfer some balance to the owner of the contract to trigger the grace period to stop
2310
- Balances :: transfer (
2320
+ Balances :: transfer_allow_death (
2311
2321
RuntimeOrigin :: signed ( bob ( ) ) ,
2312
2322
charlie ( ) ,
2313
2323
should_have_next_cycle,
@@ -2319,7 +2329,8 @@ fn test_rent_contract_overdrawn_and_partial_bill() {
2319
2329
. should_call_bill_contract ( contract_id, Ok ( Pays :: Yes . into ( ) ) , 31 ) ;
2320
2330
run_to_block ( 31 , Some ( & mut pool_state) ) ;
2321
2331
2322
- let contract_payment_state = SmartContractModule :: contract_payment_state ( contract_id) . unwrap ( ) ;
2332
+ let contract_payment_state =
2333
+ SmartContractModule :: contract_payment_state ( contract_id) . unwrap ( ) ;
2323
2334
assert_eq ! (
2324
2335
contract_payment_state. get_reserve( ) ,
2325
2336
amount_due_per_cycle * 3
@@ -2349,6 +2360,7 @@ fn test_rent_contract_canceled_mid_cycle_should_bill_for_remainder() {
2349
2360
node_id,
2350
2361
None
2351
2362
) ) ;
2363
+ let twin_id = 2 ;
2352
2364
let contract_id = 1 ;
2353
2365
2354
2366
let contract = SmartContractModule :: contracts ( contract_id) . unwrap ( ) ;
@@ -2358,14 +2370,14 @@ fn test_rent_contract_canceled_mid_cycle_should_bill_for_remainder() {
2358
2370
types:: ContractData :: RentContract ( rent_contract)
2359
2371
) ;
2360
2372
2361
- let twin = TfgridModule :: twins ( 2 ) . unwrap ( ) ;
2373
+ let twin = TfgridModule :: twins ( twin_id ) . unwrap ( ) ;
2362
2374
2363
2375
let reserved_balance = Balances :: reserved_balance ( & twin. account_id ) ;
2364
2376
info ! ( "reserved balance: {:?}" , reserved_balance) ;
2365
2377
2366
2378
run_to_block ( 8 , Some ( & mut pool_state) ) ;
2367
2379
// Calculate the cost for 7 blocks of runtime (created a block 1, canceled at block 8)
2368
- let ( amount_due_as_u128, discount_received) = calculate_tft_cost ( contract_id, 2 , 7 ) ;
2380
+ let ( amount_due_as_u128, discount_received) = calculate_tft_cost ( contract_id, twin_id , 7 ) ;
2369
2381
// cancel rent contract at block 8
2370
2382
assert_ok ! ( SmartContractModule :: cancel_contract(
2371
2383
RuntimeOrigin :: signed( bob( ) ) ,
@@ -2380,7 +2392,7 @@ fn test_rent_contract_canceled_mid_cycle_should_bill_for_remainder() {
2380
2392
) ;
2381
2393
2382
2394
// Twin should have no more reserved balance
2383
- let twin = TfgridModule :: twins ( 2 ) . unwrap ( ) ;
2395
+ let twin = TfgridModule :: twins ( twin_id ) . unwrap ( ) ;
2384
2396
let reserved_balance = Balances :: reserved_balance ( & twin. account_id ) ;
2385
2397
assert_eq ! ( reserved_balance, 0 ) ;
2386
2398
} ) ;
@@ -2413,6 +2425,7 @@ fn test_create_rent_contract_and_node_contract_excludes_node_contract_from_billi
2413
2425
0 ,
2414
2426
None
2415
2427
) ) ;
2428
+ let twin_id = 2 ;
2416
2429
let node_contract_id = 2 ;
2417
2430
push_contract_resources_used ( node_contract_id) ;
2418
2431
@@ -2425,7 +2438,8 @@ fn test_create_rent_contract_and_node_contract_excludes_node_contract_from_billi
2425
2438
. should_call_bill_contract ( node_contract_id, Ok ( Pays :: Yes . into ( ) ) , 12 ) ;
2426
2439
run_to_block ( 12 , Some ( & mut pool_state) ) ;
2427
2440
2428
- let ( amount_due_as_u128, discount_received) = calculate_tft_cost ( rent_contract_id, 2 , 10 ) ;
2441
+ let ( amount_due_as_u128, discount_received) =
2442
+ calculate_tft_cost ( rent_contract_id, twin_id, 10 ) ;
2429
2443
assert_ne ! ( amount_due_as_u128, 0 ) ;
2430
2444
check_report_cost ( rent_contract_id, amount_due_as_u128, 11 , discount_received) ;
2431
2445
@@ -2567,6 +2581,7 @@ fn test_create_rent_contract_and_node_contract_with_ip_billing_works() {
2567
2581
node_id,
2568
2582
None
2569
2583
) ) ;
2584
+ let twin_id = 2 ;
2570
2585
let rent_contract_id = 1 ;
2571
2586
2572
2587
run_to_block ( 2 , Some ( & mut pool_state) ) ;
@@ -2588,7 +2603,8 @@ fn test_create_rent_contract_and_node_contract_with_ip_billing_works() {
2588
2603
run_to_block ( 11 , Some ( & mut pool_state) ) ;
2589
2604
2590
2605
// check contract 1 costs (Rent Contract)
2591
- let ( amount_due_as_u128, discount_received) = calculate_tft_cost ( rent_contract_id, 2 , 10 ) ;
2606
+ let ( amount_due_as_u128, discount_received) =
2607
+ calculate_tft_cost ( rent_contract_id, twin_id, 10 ) ;
2592
2608
assert_ne ! ( amount_due_as_u128, 0 ) ;
2593
2609
check_report_cost ( rent_contract_id, amount_due_as_u128, 11 , discount_received) ;
2594
2610
@@ -2598,7 +2614,8 @@ fn test_create_rent_contract_and_node_contract_with_ip_billing_works() {
2598
2614
run_to_block ( 12 , Some ( & mut pool_state) ) ;
2599
2615
2600
2616
// check contract 2 costs (Node Contract)
2601
- let ( amount_due_as_u128, discount_received) = calculate_tft_cost ( node_contract_id, 2 , 10 ) ;
2617
+ let ( amount_due_as_u128, discount_received) =
2618
+ calculate_tft_cost ( node_contract_id, twin_id, 10 ) ;
2602
2619
assert_ne ! ( amount_due_as_u128, 0 ) ;
2603
2620
check_report_cost ( node_contract_id, amount_due_as_u128, 12 , discount_received) ;
2604
2621
@@ -2700,7 +2717,7 @@ fn test_restore_rent_contract_in_grace_works() {
2700
2717
run_to_block ( 31 , Some ( & mut pool_state) ) ;
2701
2718
2702
2719
// Transfer some balance to the owner of the contract to trigger the grace period to stop
2703
- Balances :: transfer ( RuntimeOrigin :: signed ( bob ( ) ) , charlie ( ) , 100000000 ) . unwrap ( ) ;
2720
+ Balances :: transfer_allow_death ( RuntimeOrigin :: signed ( bob ( ) ) , charlie ( ) , 100000000 ) . unwrap ( ) ;
2704
2721
2705
2722
pool_state
2706
2723
. write ( )
@@ -2805,7 +2822,7 @@ fn test_restore_rent_contract_and_node_contracts_in_grace_works() {
2805
2822
run_to_block ( 32 , Some ( & mut pool_state) ) ;
2806
2823
2807
2824
// Transfer some balance to the owner of the contract to trigger the grace period to stop
2808
- Balances :: transfer ( RuntimeOrigin :: signed ( bob ( ) ) , charlie ( ) , 100000000 ) . unwrap ( ) ;
2825
+ Balances :: transfer_allow_death ( RuntimeOrigin :: signed ( bob ( ) ) , charlie ( ) , 100000000 ) . unwrap ( ) ;
2809
2826
2810
2827
pool_state
2811
2828
. write ( )
@@ -3576,15 +3593,16 @@ fn test_service_contract_bill_works() {
3576
3593
get_timestamp_in_seconds_for_block( 1 )
3577
3594
) ;
3578
3595
3579
- let consumer_twin = TfgridModule :: twins ( 2 ) . unwrap ( ) ;
3596
+ let consumer_twin_id = 2 ;
3597
+ let consumer_twin = TfgridModule :: twins ( consumer_twin_id) . unwrap ( ) ;
3580
3598
let consumer_balance = Balances :: free_balance ( & consumer_twin. account_id ) ;
3581
3599
assert_eq ! ( consumer_balance, 2500000000 ) ;
3582
3600
3583
3601
// Bill 20 min after contract approval
3584
3602
run_to_block ( 201 , Some ( & mut pool_state) ) ;
3585
3603
assert_ok ! ( SmartContractModule :: service_contract_bill(
3586
3604
RuntimeOrigin :: signed( alice( ) ) ,
3587
- 1 ,
3605
+ service_contract_id ,
3588
3606
VARIABLE_AMOUNT ,
3589
3607
b"bill_metadata_1" . to_vec( ) ,
3590
3608
) ) ;
@@ -3766,9 +3784,11 @@ fn test_service_contract_bill_out_of_funds_fails() {
3766
3784
approve_service_consumer_contract ( service_contract_id) ;
3767
3785
3768
3786
// Drain consumer account
3769
- let consumer_twin = TfgridModule :: twins ( 2 ) . unwrap ( ) ;
3787
+ let twin_id = 2 ;
3788
+ let consumer_twin = TfgridModule :: twins ( twin_id) . unwrap ( ) ;
3770
3789
let consumer_balance = Balances :: free_balance ( & consumer_twin. account_id ) ;
3771
- Balances :: transfer ( RuntimeOrigin :: signed ( bob ( ) ) , alice ( ) , consumer_balance) . unwrap ( ) ;
3790
+ Balances :: transfer_allow_death ( RuntimeOrigin :: signed ( bob ( ) ) , alice ( ) , consumer_balance)
3791
+ . unwrap ( ) ;
3772
3792
let consumer_balance = Balances :: free_balance ( & consumer_twin. account_id ) ;
3773
3793
assert_eq ! ( consumer_balance, 0 ) ;
3774
3794
0 commit comments