Add tests for BIP-78 sender checklist#663
Conversation
64d92a3 to
d3d7762
Compare
Pull Request Test Coverage Report for Build 15142770410Details
💛 - Coveralls |
d3d7762 to
4968d0b
Compare
c270010 to
417035e
Compare
|
Archived check #339 for the updated checklist Checklist for review (These checks are not confirming that the logic in each test is sound, just organization and completeness)
|
|
A few questions and comments
|
benalleng
left a comment
There was a problem hiding this comment.
This is a great and I think almost there! just a few comments, and perhaps a QoL change i'd like is some doc strings that organize the tests perhaps mirror the checklist in some way by just adding the checklist string above each test that is relevant to that. Most notably the fee tests are a bit confusing in their names albeit they do what they say they will just harder to track.
|
Its rather disappointing |
spacebear21
left a comment
There was a problem hiding this comment.
This is awesome! I haven't gone through every test to check the logic yet but at a high level it looks great.
@benalleng it's worth bringing up again now that the sender checks that use the ensure! macro do not get picked up by cargo mutants as explained in #539 (comment). It would be great to address this so we can get include all of these critical paths in mutation coverage now that we have proper tests in place.
payjoin/src/send/mod.rs
Outdated
| assert!( | ||
| result.is_err(), | ||
| "Process proposal should reject proposal since the version is different than the original psbt" | ||
| ); | ||
|
|
||
| match result { | ||
| Ok(_) => panic!("Expected error, got success"), |
There was a problem hiding this comment.
Isn't this assert/panic pattern redundant? I think this is effectively the same thing as:
| assert!( | |
| result.is_err(), | |
| "Process proposal should reject proposal since the version is different than the original psbt" | |
| ); | |
| match result { | |
| Ok(_) => panic!("Expected error, got success"), | |
| match result { | |
| Ok(_) => panic!("Process proposal should reject proposal since the version is different than the original psbt"), |
There was a problem hiding this comment.
I think so. There was an existing test for one of the sender checks in this format - I kept the new tests in the same format but I'll update these to remove the redundancy
payjoin/src/send/mod.rs
Outdated
| let result = ctx.process_proposal(proposal); | ||
| assert!( | ||
| result.is_err(), | ||
| "Process proposal should reject proposal since the locktime is different than the original psbt" | ||
| ); | ||
|
|
||
| match result { | ||
| Ok(_) => panic!("Expected error, got success"), | ||
| Err(error) => assert_eq!( | ||
| format!("{error}"), | ||
| InternalProposalError::LockTimesDontMatch { | ||
| proposed: proposed_locktime, | ||
| original: original_locktime | ||
| } | ||
| .to_string() | ||
| ), |
There was a problem hiding this comment.
Even beyond @spacebear21 's comment, this pattern may be simplified in many places with
assert_eq!(
ctx.process_proposal(proposal).unwrap_err().to_string(),
InternalProposalError::LockTimesDontMatch {
proposed: proposed_locktime,
original: original_locktime
}.to_string()
);Even better would be an Internal[T]Error match versus a to_string match if the Internal[T]Error is visible in the test
There was a problem hiding this comment.
I discovered even more appropriate syntax
assert!(matches!(
ctx.process_proposal(proposal),
Err(InternalProposalError::LockTimesDontMatch {
proposed,
original
}) if proposed == proposed_locktime && original == original_locktime
));which does not match on the display impl but on the variant itself, and avoids the unwrap, but I suppose that can be saved for a follow up. An LLM should be able to do this conversion and then you can self review before asking for one here, but it should be one-shot.
I'd like to put these mutant cathces into a different PR, there are enough failed mutants that I think it's worth separating it from here |
|
Thanks @benalleng for the checklist. I incorrectly assumed that there'd be an |
|
The tests are a great improvement in coverage as-is. I'm not even sure the missing checks are candidates for That's not to say additional checks aren't welcome, i'd just hate for them to slow you down. |
417035e to
cfc4d61
Compare
|
Updated to reformat the assertions and add the test for |
|
Transitioning these tests to use just I would like to maybe use |
I think the custom message is useful in |
67d195d to
11b1b65
Compare
11b1b65 to
b8d7aab
Compare
There was a problem hiding this comment.
ACK b8d7aab
I did go through the logic of each test individually, though I didn't check with @benalleng 's checklist
@benalleng , does that checklist become an issue or attach to the adversarial tests issue? Or the issue that says this can finally check [ ] has many unit tests, if one exists?
@shinghim How would you like to handle the suggested assert!(matches! syntax or the ensure! for sequence? Would you like to grab them or shall I find a time to follow up? You mentioned the receiver side too.
Thanks for keeping these piecemeal and easy to review
|
I think it's Ok to tag onto #339 as there is already some discussion there about these test there. As for creating a higher level [ ] has many unit tests in the readme, I think that could be helpful to keep everything like this, mutants, etc organized. And we can decide there whether it deserves to be checked |
Adding tests for each
ensure!for the sender checks. Will partially address #339 - I'll follow up with another PR for the receiver side