-
Notifications
You must be signed in to change notification settings - Fork 17
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
added tests for calculate_fee(), calculate_waste() and effective_value() #25
base: main
Are you sure you want to change the base?
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.
Test vectors looks good.
Below few comments on unwraps, and few non-blocking comments, doesn't have to be addressed in the PR.
.value | ||
.saturating_sub(calculate_fee(output.weight, feerate)) | ||
.saturating_sub(calculate_fee(output.weight, feerate)?)) |
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.
A better name for this could be output.spending_weight
. Weight can imply two things, the weight of the output, or the weight of the spending transaction's input. We need the second weight here.
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.
Any input on this?
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 agree that spending_weight is a better name than weight. Perhaps input_weight or utxo_weight would be other options to consider. Anything to differentiate the two would improve the readability of the code.
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.
utACK 4ebff2c
The test structure looks good to me. Although I haven't ran or checked the calculations.
One small nit remaining.
ACK from me module @delcin-raj 's review.
.value | ||
.saturating_sub(calculate_fee(output.weight, feerate)) | ||
.saturating_sub(calculate_fee(output.weight, feerate)?)) |
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.
Any input on this?
fmt failed because of an error in line 707. It reads |
Should fix, unless the number itself is wrong.. |
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 think these validations of low and high fee rate should be handled in pub
functions.
Not in calculate_fee
@@ -75,6 +76,8 @@ pub enum ExcessStrategy { | |||
pub enum SelectionError { | |||
InsufficientFunds, | |||
NoSolutionFound, | |||
NegativeFeeRate, |
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.
NonPositiveFeeRate will be accurate
@@ -75,6 +76,8 @@ pub enum ExcessStrategy { | |||
pub enum SelectionError { | |||
InsufficientFunds, | |||
NoSolutionFound, | |||
NegativeFeeRate, | |||
AbnormallyHighFee, |
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.
AbnormallyHighFeeRate
I added tests: test_calculate_fee(), test_effective_value_when_less_than_zero(), test_effective_value_when_greater_than_zero(), test_effective_value when_less_than_zero(), test_calculate_waste_to_drain(), and test_calculate_waste_to_miner() per issue number 24.