Skip to content
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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

chippsmith
Copy link

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.

src/lib.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@rajarshimaitra rajarshimaitra left a 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.

src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
.value
.saturating_sub(calculate_fee(output.weight, feerate))
.saturating_sub(calculate_fee(output.weight, feerate)?))
Copy link
Contributor

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any input on this?

Copy link
Author

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.

Copy link
Contributor

@rajarshimaitra rajarshimaitra left a 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.

src/lib.rs Show resolved Hide resolved
.value
.saturating_sub(calculate_fee(output.weight, feerate))
.saturating_sub(calculate_fee(output.weight, feerate)?))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any input on this?

@chippsmith
Copy link
Author

fmt failed because of an error in line 707. It reads result: Ok(999_99_999_990), instead of result: Ok(99_999_999_990). Im not sure if I should fix that or not since this is pending review from @delcin-raj.

@rajarshimaitra
Copy link
Contributor

Should fix, unless the number itself is wrong..

Copy link
Collaborator

@delcin-raj delcin-raj left a 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,
Copy link
Collaborator

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,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AbnormallyHighFeeRate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants