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

Update select_first_candidate to return InternalSelectionError::Empty #542

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

Conversation

pseudoramdom
Copy link

Fix #535

Update select_first_candidate to return InternalSelectionError::Empty when there are no candidates available for selection

@pseudoramdom
Copy link
Author

Hi there! I'm new here. I didn't see this covered in any existing tests, unless you'd like me to add one?

@DanGould
Copy link
Contributor

If you are up to adding a test that'd be a welcome addition

@coveralls
Copy link
Collaborator

coveralls commented Feb 18, 2025

Pull Request Test Coverage Report for Build 13667156981

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 30 of 32 (93.75%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.1%) to 79.825%

Changes Missing Coverage Covered Lines Changed/Added Lines %
payjoin/src/receive/v1/mod.rs 30 32 93.75%
Totals Coverage Status
Change from base Build 13659398070: 0.1%
Covered Lines: 4558
Relevant Lines: 5710

💛 - Coveralls

@spacebear21
Copy link
Collaborator

Also, currently we actually check for an empty candidates set twice: the first one is here.

So this specific code change would be unreachable unless calling select_first_candidate directly, but it's a private function so I'm not sure that would a be a useful test. Perhaps we should remove the empty check in try_preserving_privacy and have it in avoid_uih and select_first_candidate only?

@DanGould
Copy link
Contributor

Yes please remove the empty check in try_... and leave it to avoid_uih and select_first_candidate only

@pseudoramdom pseudoramdom force-pushed the 535-select_first_candidate-error branch from c113c09 to 57d21c0 Compare March 1, 2025 06:28
@pseudoramdom
Copy link
Author

pseudoramdom commented Mar 1, 2025

I made the requested changes.
I was able to add a test but InternalSelectionError has an access level of pub(crate).
I had to resort to a string check . Let me know if that works.

@0xBEEFCAF3
Copy link
Collaborator

@pseudoramdom Do you mind squashing your commits into one?

Copy link
Contributor

@benalleng benalleng left a comment

Choose a reason for hiding this comment

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

Just a small nit to keep the test signatures consistent

Copy link
Contributor

@benalleng benalleng left a comment

Choose a reason for hiding this comment

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

The test looks good

Copy link
Collaborator

@spacebear21 spacebear21 left a comment

Choose a reason for hiding this comment

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

ACK 5066eef

Thanks @pseudoramdom and reviewers!

nit: looks like all previous commit messages got squashed into this one, it would be nice to clean up the commit message before merging this. We generally follow the commit guidelines established in https://cbea.ms/git-commit/

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.

LGTM other than the commit messages. Please follow the seven rules from cbeams.

Thank you for your contribution 😎

…pty`

Fix payjoin#535

- Update select_first_candidate to return InternalSelectionError::Empty when there are no candidates available for selection.
- Include test `empty_candidates_inputs`
@pseudoramdom pseudoramdom force-pushed the 535-select_first_candidate-error branch from 5066eef to 25d2af5 Compare March 5, 2025 02:27
@pseudoramdom
Copy link
Author

Thanks for the reviews folks! Fixed the commit message. Let me know if it looks good.

@pseudoramdom pseudoramdom requested a review from DanGould March 5, 2025 02:40
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 the update. I think there is one sincere issue with the test, as discovered by @elnosh in another PR that I've repeated in my comments below.

I would like to understand the rationale of the change in the PR body, in complete sentences, rather than just a repeat of the title. The commit message is closer but I still need it to follow the seven rules, namely 2, 6, and 7, seem broken to me. Much more important than the what is the why, or rationale for the change.

Comment on lines +873 to +881
if let Err(err) = result {
let debug_str = format!("{:?}", err);
assert!(
debug_str.contains("Empty"),
"Error should indicate 'Empty' but was: {}",
debug_str
);
}
Ok(())
Copy link
Contributor

Choose a reason for hiding this comment

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

This pattern will ignore an Ok result where there should be an error. Instead match, panic! on the Ok case and assert! on the Err case as pointed out by @elnosh

@@ -847,6 +845,42 @@ pub(crate) mod test {
}
}

#[test]
fn empty_candidates_inputs() -> Result<(), BoxError> {
Copy link
Contributor

Choose a reason for hiding this comment

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

You can take advantage of the BoxError here by using ? to propagate errors instead of calling .expect. Doing so will make the test more brief and readable.

A followup commit might make this change to use BoxError in the other tests in this module.

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.

select_first_candidate returns a InternalSelectionError::NotFound
6 participants