Skip to content

Replace OutputSubstitutionDisabled string context with sub variants#590

Merged
DanGould merged 1 commit intopayjoin:masterfrom
benalleng:pjos-error-variants
Mar 24, 2025
Merged

Replace OutputSubstitutionDisabled string context with sub variants#590
DanGould merged 1 commit intopayjoin:masterfrom
benalleng:pjos-error-variants

Conversation

@benalleng
Copy link
Collaborator

@benalleng benalleng commented Mar 18, 2025

InternalOutputSubstitutionError::OutputSubstitutionDisabled accepts a string context within the error but seeing as there are only two possible error variants here it makes sense to just create two new InternalOutputSubstitutionError variants to put these errors into.

In the second commit I just created some additional test coverage to catch some untested functions and cases.

closes #588

@coveralls
Copy link
Collaborator

coveralls commented Mar 18, 2025

Pull Request Test Coverage Report for Build 14041036962

Details

  • 82 of 88 (93.18%) changed or added relevant lines in 3 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.5%) to 80.898%

Changes Missing Coverage Covered Lines Changed/Added Lines %
payjoin/src/receive/v1/mod.rs 81 83 97.59%
payjoin/src/receive/error.rs 0 4 0.0%
Totals Coverage Status
Change from base Build 14002185069: 0.5%
Covered Lines: 4938
Relevant Lines: 6104

💛 - Coveralls

@benalleng benalleng changed the title Replace OutputSubstitutionDisabled string variants with sub variants Replace OutputSubstitutionDisabled string context with sub variants Mar 18, 2025
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.

Great opportunity to add a unit test for each variant here!

Comment on lines 273 to 274
OutputValueError,
OutputScriptPubkeyError,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
OutputValueError,
OutputScriptPubkeyError,
DecreasedValue,
ChangedScriptPubkey,

@DanGould
Copy link
Contributor

Is there any great advantage to subvariants instead of 2 OutputSelectionError variants? I can't think of any, and this complexity is not insignificant

@benalleng benalleng force-pushed the pjos-error-variants branch 7 times, most recently from cf27c96 to 6ad1cbb Compare March 24, 2025 14:51
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.

The second commit seems unrelated to the goal of this PR so likely belongs in a separate PR for easier/independent review.

}

#[test]
fn test_pjos_disabled_decrease_amount() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think test_pjos_disabled_decrease_amount, test_pjos_disabled_increase_amount, test_pjos_disabled_script_pubkey could be combined into a single unit test: test_pjos_disabled since it's testing the same functionality just different edge cases. It will avoid some unnecessary repetition setting up the test conditions and keep related logic together.

@benalleng benalleng force-pushed the pjos-error-variants branch 3 times, most recently from 9adcda5 to 9eac27a Compare March 24, 2025 16:47
InternalOutputSubstitutionError::OutputSubstitutionDisabled accepts a string
context within the error but seeing as there are only two possible error variants
here it makes more sense to create separate error contexts to put these errors into.
@benalleng benalleng force-pushed the pjos-error-variants branch from 9eac27a to 6bd53d8 Compare March 24, 2025 16:50
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.

ACK 6bd53d8

use rand::SeedableRng;

use super::*;
pub const QUERY_PARAMS: &str = "maxadditionalfeecontribution=182&additionalfeeoutputindex=0";
Copy link
Contributor

Choose a reason for hiding this comment

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

These are now defined in payjoin-test-utils, but could be added in a follow up

Comment on lines +793 to 795
pub(crate) fn proposal_from_test_vector() -> Result<UncheckedProposal, BoxError> {
let pairs = url::form_urlencoded::parse(QUERY_PARAMS.as_bytes());
let params = Params::from_query_pairs(pairs, &[1])?;
Ok(UncheckedProposal { psbt: bitcoin::Psbt::from_str(ORIGINAL_PSBT)?, params })
}
Copy link
Contributor

Choose a reason for hiding this comment

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

It may be appropriate to host this entire function in payjoin-test-utils, but this could be done with your additional tests

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I will give it a try in that upcoming PR 👍

@DanGould DanGould merged commit 8c2a6b5 into payjoin:master Mar 24, 2025
7 checks passed
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.

Why are there multiple InternalOutputSubstitutionError::OutputSubstitutionDisabled(& str) variants?

4 participants