Skip to content

Commit 3286f3e

Browse files
committed
refactor: minor test refactor
1 parent 566c9df commit 3286f3e

File tree

1 file changed

+20
-30
lines changed
  • substrate-node/pallets/pallet-smart-contract/src

1 file changed

+20
-30
lines changed

substrate-node/pallets/pallet-smart-contract/src/tests.rs

+20-30
Original file line numberDiff line numberDiff line change
@@ -3043,9 +3043,6 @@ fn test_node_contract_on_dedicated_node_shouldnt_be_restored_if_rent_contract_in
30433043

30443044
let node_id = 1;
30453045

3046-
// Set the TFT prices
3047-
TFTPriceModule::set_prices(RuntimeOrigin::signed(alice()), 50, 101).unwrap();
3048-
30493046
// Create a rent contract
30503047
assert_ok!(SmartContractModule::create_rent_contract(
30513048
RuntimeOrigin::signed(bob()),
@@ -3106,7 +3103,8 @@ fn test_node_contract_on_dedicated_node_shouldnt_be_restored_if_rent_contract_in
31063103
// Transfer some balance to the owner of the contract to settle only the cost of IP rent (node contract)
31073104
// Case 1: See https://github.com/threefoldtech/tfchain/issues/1002
31083105
// Calculate the node contract cost
3109-
let (amount_due, discount_level) = calculate_tft_cost(node_contract_id, 2, 10);
3106+
let bob_twin_id = 2;
3107+
let (amount_due, discount_level) = calculate_tft_cost(node_contract_id, bob_twin_id, 10);
31103108
log::debug!("Amount due: {}, discount level: {:?}", amount_due, discount_level);
31113109
Balances::transfer_allow_death(RuntimeOrigin::signed(charlie()), bob(), amount_due).unwrap();
31123110

@@ -3118,7 +3116,7 @@ fn test_node_contract_on_dedicated_node_shouldnt_be_restored_if_rent_contract_in
31183116
// Check if last event is Contract billed event
31193117
let events = System::events();
31203118
log::debug!("Events: {:?}", events);
3121-
let contract_bill_event = types::ContractBill {
3119+
let contract_bill = types::ContractBill {
31223120
contract_id: node_contract_id,
31233121
timestamp: 1628082132,
31243122
discount_level,
@@ -3129,7 +3127,7 @@ fn test_node_contract_on_dedicated_node_shouldnt_be_restored_if_rent_contract_in
31293127
.last()
31303128
.unwrap()
31313129
.event,
3132-
MockEvent::SmartContractModule(SmartContractEvent::ContractBilled(contract_bill_event))
3130+
MockEvent::SmartContractModule(SmartContractEvent::ContractBilled(contract_bill))
31333131
);
31343132

31353133
// Node contract cost settled (IP address cost), but it should remain in the grace period due to the suspended rent contract
@@ -3149,9 +3147,6 @@ fn test_node_contract_with_overdraft_on_dedicated_node_shouldnt_be_restored_when
31493147

31503148
let node_id = 1;
31513149

3152-
// Set the TFT prices
3153-
TFTPriceModule::set_prices(RuntimeOrigin::signed(alice()), 50, 101).unwrap();
3154-
31553150
// Create a rent contract
31563151
assert_ok!(SmartContractModule::create_rent_contract(
31573152
RuntimeOrigin::signed(charlie()),
@@ -3198,7 +3193,8 @@ fn test_node_contract_with_overdraft_on_dedicated_node_shouldnt_be_restored_when
31983193
// Transfer some balance to the owner of the contract to settle only the cost of node resources (rent contract)
31993194
// Case 2: see https://github.com/threefoldtech/tfchain/issues/1002
32003195
// Calculate the rent contract cost
3201-
let (contract_cost, discount_level) = calculate_tft_cost(rent_contract_id, 3, 20);
3196+
let charlie_twin_id = 3;
3197+
let (contract_cost, discount_level) = calculate_tft_cost(rent_contract_id, charlie_twin_id, 20);
32023198
let amount_due = contract_cost - spendable_balance;
32033199
log::debug!("Amount due: {}, discount level: {:?}", amount_due, discount_level);
32043200
Balances::transfer_allow_death(RuntimeOrigin::signed(bob()), charlie(), amount_due).unwrap();
@@ -3228,9 +3224,6 @@ fn test_rent_contract_should_wait_for_proper_distribution_of_rewards_when_grace_
32283224

32293225
let node_id = 1;
32303226

3231-
// Set the TFT prices
3232-
TFTPriceModule::set_prices(RuntimeOrigin::signed(alice()), 50, 101).unwrap();
3233-
32343227
// Create a rent contract
32353228
assert_ok!(SmartContractModule::create_rent_contract(
32363229
RuntimeOrigin::signed(bob()),
@@ -3333,13 +3326,14 @@ fn test_rent_contract_should_wait_for_proper_distribution_of_rewards_when_grace_
33333326
// Check if the last event is NodeContractCanceled event
33343327
assert_eq!(
33353328
events
3336-
.iter()
3337-
.filter(|e| matches!(
3338-
e.event,
3339-
MockEvent::SmartContractModule(SmartContractEvent::NodeContractCanceled { .. })
3340-
))
3341-
.count(),
3342-
1
3329+
.last()
3330+
.unwrap()
3331+
.event,
3332+
MockEvent::SmartContractModule(SmartContractEvent::NodeContractCanceled{
3333+
contract_id: node_contract_id,
3334+
node_id: node_id,
3335+
twin_id: 2
3336+
})
33433337
);
33443338
// The rent contract should be canceled in the next cycle
33453339
let block_number: u64 = 131;
@@ -3354,13 +3348,12 @@ fn test_rent_contract_should_wait_for_proper_distribution_of_rewards_when_grace_
33543348
let events = System::events();
33553349
assert_eq!(
33563350
events
3357-
.iter()
3358-
.filter(|e| matches!(
3359-
e.event,
3360-
MockEvent::SmartContractModule(SmartContractEvent::RentContractCanceled { .. })
3361-
))
3362-
.count(),
3363-
1
3351+
.last()
3352+
.unwrap()
3353+
.event,
3354+
MockEvent::SmartContractModule(SmartContractEvent::RentContractCanceled{
3355+
contract_id: rent_contract_id,
3356+
})
33643357
);
33653358
// No part of the user's balance should be reserved
33663359
assert_eq!(Balances::reserved_balance(&bob()), 0);
@@ -3377,9 +3370,6 @@ fn test_node_contract_in_grace_period_should_maintain_start_block_number_if_rent
33773370

33783371
let node_id = 1;
33793372

3380-
// Set the TFT prices
3381-
TFTPriceModule::set_prices(RuntimeOrigin::signed(alice()), 50, 101).unwrap();
3382-
33833373
// Create a rent contract
33843374
assert_ok!(SmartContractModule::create_rent_contract(
33853375
RuntimeOrigin::signed(bob()),

0 commit comments

Comments
 (0)