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

Remove unwrap() in receive::v1::test #543

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

pseudoramdom
Copy link

Partially address #487

Replace .unwrap() with .map_err wherever applicable. Otherwise fallback to ?

Copy link
Contributor

@DanGould DanGould left a comment

Choose a reason for hiding this comment

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

Thanks for taking a shot at this for the first time with minimal instruction.

The general approach is correct but we should be able to refine it so that the changes to the tests are a net removal. (edit: impl StdError might add lines, but that's OK. I mean changes specifically to test lines since we're removing .unwrap() lines.)

Anywhere there's a .map_err(|e| e.to_string())?; or map_err(|e| format!(...*in tests* should be replaced by a simple?in tests unless there's a very good reason to do otherwise. If std::error::Error needs to be implemented onInternal*` error types in order to make this happen, that should be done. If StdError is implemented on internal types, that should be used chained to replace the non-internal StdError implementation to de-duplicate work.

@coveralls
Copy link
Collaborator

Pull Request Test Coverage Report for Build 13384843632

Details

  • 56 of 56 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.1%) to 79.189%

Totals Coverage Status
Change from base Build 13375398808: 0.1%
Covered Lines: 4022
Relevant Lines: 5079

💛 - Coveralls

.unwrap()
.require_network(network)
.unwrap())
// Convert script to address with proper error handling
Copy link
Contributor

Choose a reason for hiding this comment

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

Inline comments like this tend to go stale, so I prefer not to use them except if overwhelmingly necessary, instead abstracting to a helper function with a /// docstring. I don't think any comment is necessary here.

assert!(psbt.is_ok(), "Payjoin should be a valid PSBT");
payjoin
.apply_fee(None, None)
.map_err(|e| format!("Payjoin should be a valid PSBT: {:?}", e))?;
Copy link
Contributor

Choose a reason for hiding this comment

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

In e.g. payjoin-cli adding context is helpful. In the tests where you get a line number and you're a dev running tests and reading code, I'd rather the error is propagated with a simple ?, even if that requires impl StdError on inner types. That way we can reduce noise in LoC and custom static strings in the tests.

.require_network(network)
.unwrap())
let script_address = Address::from_script(script, network)
.map_err(|e| e.to_string())?;
Copy link
Contributor

Choose a reason for hiding this comment

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

Prefer a simple ? wherever there isn't an overwhelming reason not to use one e.g. if context is necessary in application code

Comment on lines +904 to +911
let mut payjoin_clone = payjoin.clone();
let psbt = payjoin.apply_fee(None, Some(FeeRate::from_sat_per_vb_unchecked(1000)));
assert!(psbt.is_ok(), "Payjoin should be a valid PSBT");

let psbt = payjoin_clone.apply_fee(None, Some(FeeRate::from_sat_per_vb_unchecked(995)));
assert!(psbt.is_err(), "Payjoin exceeds receiver fee preference and should error");

Ok(())
Copy link
Contributor

@DanGould DanGould Feb 18, 2025

Choose a reason for hiding this comment

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

I sincerely appreciate the change and offer my feedback in hopes it helps make contributions without friction based on the customs of this repo while recognizing you woudn't know to do this without prior instruction.

Make sure to read all of the Contributing section of the README, and specifically apply the formatting and linting sections in order to avoid CI failures from new indentation like this. cargo fmt on nightly would prevent this from a new indentation change.

Also, I see a space was added on 907. Don't add new whitespace outside of a content or formatting commit. I think this change should really just be the 2 lines (whitespace and Ok((())

Copy link
Author

Choose a reason for hiding this comment

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

Totally understand. Thanks for flagging that.
I checked the contribution section for testing but I did indeed miss the part on formatting and lint. I'll work on addressing them. Thx!

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