-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix inconsistencies in node contracts states #1010
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests well cover the cases related to issue #1002
Nice work !!
Added my comments
let node_contract = SmartContractModule::contracts(node_contract_id).unwrap(); | ||
assert_eq!(node_contract.state, types::ContractState::GracePeriod(11)); | ||
|
||
// Transfer some balance to the owner of the contract to settle only the cost of node resources (rent contract) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... for 2 billing cycles
.write() | ||
.should_call_bill_contract(rent_contract_id, Ok(Pays::Yes.into()), 11); | ||
run_to_block(11, Some(&mut pool_state)); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would have been nice to have some overdraft check here:
assert_ne!(rent_contract_overdraft, 0);
assert_eq!(rent_contract_reserve, spendable_balance);
or even:
assert_eq!(rent_contract_overdraft + rent_contract_reserve, rent_contract_cost_1_cycle);
.write() | ||
.should_call_bill_contract(node_contract_id, Ok(Pays::Yes.into()), 12); | ||
run_to_block(12, Some(&mut pool_state)); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also here something like:
assert_ne!(node_contract_overdraft, 0);
assert_eq!(node_contract_reserve, 0);
assert_eq!(rent_contract_overdraft, node_contract_ip_cost_1_cycle);
to be able to understand better what is happening in "backstage"
// Case 2: see https://github.com/threefoldtech/tfchain/issues/1002 | ||
// Calculate the rent contract cost | ||
let charlie_twin_id = 3; | ||
let (contract_cost, discount_level) = calculate_tft_cost(rent_contract_id, charlie_twin_id, 20); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename contract_cost
to rent_contract_cost_2_cycles
?
and amount_due
to rent_amount_due
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’ve decided to skip these changes because the current names reflect their purpose without adding unnecessary complexity. The additional qualifiers don’t seem essential as the context is clear.
|
||
let node_contract = SmartContractModule::contracts(rent_contract_id).unwrap(); | ||
assert_eq!(node_contract.state, types::ContractState::Created); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert_eq!(rent_contract_overdraft, 0);
assert_eq!(rent_contract_reserve, rent_contract_cost_2_cycles);
assert_eq!(balance_reserve_charlie, rent_contract_cost_2_cycles);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed test case 2
Test flow is great !
See my suggestions for improvement
@renauter Thank you for your thoughtful review. I’ve addressed most of your comments. I also appreciate the suggestion to add more assertions, but I believe these extra checks go beyond the scope of these test cases. The existing assertions already verify the core functionality being fixed, and adding more may detract from the specific focus of the test. |
Description
Related Issues:
#1002
Checklist:
Please delete options that are not relevant.