Conversation
|
No missed mutants as of 54c9110 |
Pull Request Test Coverage Report for Build 15424551466Warning: 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
💛 - Coveralls |
|
In reference to the fact that I did have a mutation that was missed but I can no longer reproduce it and the logic indicates it shouldn't have happened but it did, I don't think we need to worry about this too much but something to point out if anyone else is able to reproduce it |
payjoin/src/send/mod.rs
Outdated
| if self.output_substitution == OutputSubstitution::Disabled | ||
| || (proposed_txout.script_pubkey == original_output.script_pubkey | ||
| && proposed_txout.value < original_output.value) | ||
| { | ||
| return Err(InternalProposalError::DisallowedOutputSubstitution); | ||
| }; |
There was a problem hiding this comment.
I think this is more strict than the original, it errors if output substitution is disabled, regardless of the output
There was a problem hiding this comment.
Good catch, I think I have the logic cleaned up here now.
| macro_rules! ensure { | ||
| ($cond:expr, $error:ident) => { | ||
| if !($cond) { | ||
| return Err(InternalProposalError::$error); | ||
| } | ||
| }; | ||
| } | ||
|
|
There was a problem hiding this comment.
I wonder, could this be replaced with a simple function?
fn ensure<T>(condition: bool, error: T) -> Result<(), T> {
if !condition {
return Err(error);
}
Ok(())
}
ensure(original_fee <= proposed_fee, InternalProposalError::AbsoluteFeeDecreased)?;In addition to keeping to DRY, it would make this diff easier to reason about and validate. The key thing to ensure with this approach is that mutants can still modify the operators in the condition.
There was a problem hiding this comment.
So I don't think it catches everything, we lose 8 possible mutants when going about this approach, I will check what gets missed. I am going to go out on a limb and assume that the .is_empty() or .is_some() by themselves as params are not mutated while they are in a traditional if clause as the clause can just be replaced with true or false. operands like || && <= etc are still mutated here I'm assuming.
I am checking now what can no-longer be mutated.
There was a problem hiding this comment.
I think actually these new mutants are just a byproduct of how the if clauses added a small amount of complexity into the catches, we can use this ensure function.
It was mostly the fact that >= has only one mutant; <
While the inverse > has two mutants; < and ==
Also having to check if (!is_empty()) adds a mutant with the negation vs the base ensure
12ba639 to
e3b048f
Compare
|
Mutation coverage as of e3b048f |
|
I wanted to mention that these example psbts in I had a hard time grokking what key values to change on the psbt specifically to get to each error there but I do think targeting the key values instead of just creating new psbt strings is a better way to do this. I tried to find an exact example but I couldn't before I stepped off but I'm fairly certain these psbts would fail on more than just each assert it is testing for. |
There was a problem hiding this comment.
ACK e3b048f
The function is so much better and it seems each instance is the same as before.
In the tests, did you try to make the PSBTs in rust rather than just with strings? It seems like a bit of a shortcut to read in strings, but if you're confident they contain what the comments state, and you did try to have semantic rust that was for some reason a PITA, I don't see a great reason to oppose letting this in as-is. How did you make the strings?
|
I used |
|
Sat down and managed to make them in rust after-all it was actually rather easy after realizing I had the psbt strings as reference to what should be changed 😅 |
e4b0b5a to
5e2bd4f
Compare
|
Tested again and confirmed no new mutants on 5e2bd4f |
payjoin/src/send/mod.rs
Outdated
| assert_eq!( | ||
| ctx.clone().process_proposal(proposal.clone()).unwrap_err().to_string(), | ||
| InternalProposalError::DisallowedOutputSubstitution.to_string() | ||
| ); |
There was a problem hiding this comment.
assert!(match!
| assert_eq!( | |
| ctx.clone().process_proposal(proposal.clone()).unwrap_err().to_string(), | |
| InternalProposalError::DisallowedOutputSubstitution.to_string() | |
| ); | |
| assert!(matches!( | |
| ctx.clone().process_proposal(proposal.clone()).unwrap_err(), | |
| InternalProposalError::DisallowedOutputSubstitution | |
| )); |
payjoin/src/send/mod.rs
Outdated
| let mut proposal: bitcoin::Psbt = PARSED_PAYJOIN_PROPOSAL.clone(); | ||
|
|
||
| ctx.fee_contribution = None; | ||
| proposal.unsigned_tx.output.get_mut(0).unwrap().value = |
There was a problem hiding this comment.
In the future, especially for tests, I think output[0] would work here and still panic. The only time to use get_mut(0) is if you wanted to handle it without a panic.
|
yeah if you use output[0] you don't even need the unwrap! |
|
I just need to bite the bullet and finally make a pre-commit hook 😅 |
790aa6b to
4fe9c78
Compare
This adds the mutants for the mod file in the sender. I am breaking the mutation coverage up for the sender file by file so there is not a huge PR touching everything as we can add coverage one file at a time.
By using plain if statements we can test these logic blocks with mutants ensuring some better coverage on the send mod.rs file.
| Some((Amount::from_sat(1000), None)), | ||
| true, | ||
| ); | ||
| assert_eq!(fee_contribution.err(), Some(InternalBuildSenderError::AmbiguousChangeOutput)); |
There was a problem hiding this comment.
In the future I think this syntax is simpler:
| assert_eq!(fee_contribution.err(), Some(InternalBuildSenderError::AmbiguousChangeOutput)); | |
| assert_eq!(fee_contribution, Err(InternalBuildSenderError::AmbiguousChangeOutput)); |
This adds the mutants for the mod file in the sender.
This is the first part of the sender to be covered by mutation testing. Once the the sender has complete mutation coverage we can look at finalizing #539