Skip to content

Add additional tests for v2 send module#554

Merged
spacebear21 merged 1 commit intopayjoin:masterfrom
benalleng:send-v2-module-tests
Mar 13, 2025
Merged

Add additional tests for v2 send module#554
spacebear21 merged 1 commit intopayjoin:masterfrom
benalleng:send-v2-module-tests

Conversation

@benalleng
Copy link
Collaborator

@benalleng benalleng commented Feb 25, 2025

Relates to #539

This is an attempt to both add some additional test vectors and to create some headway on the tests deficiencies caught by cargo mutants ahead of time.
Currently missing is the test for process_response which I was unable to make significant progress on as I was not able to parse what I anticipated as expected values for the ohttp encapsulation/decapsulation. Ideally we should have a test for that added so I have created a TODO there.

I have tried my best to keep the tests in accordance with the design laid out in #487

Below is the cargo mutants output for send/v2/mod.rs as of df30f3b

Details
caught   payjoin/src/send/v2/mod.rs:203:5: replace serialize_v2_body -> Result<Vec<u8>, CreateRequestError> with Ok(vec![]) in 8.7s build + 1.1s test
caught   payjoin/src/send/v2/mod.rs:203:5: replace serialize_v2_body -> Result<Vec<u8>, CreateRequestError> with Ok(vec![1]) in 5.9s build + 1.1s test
***MISSED   payjoin/src/send/v2/mod.rs:146:45: replace > with == in Sender::extract_v2 in 10.2s build + 1.5s test
caught   payjoin/src/send/v2/mod.rs:203:5: replace serialize_v2_body -> Result<Vec<u8>, CreateRequestError> with Ok(vec![0]) in 8.5s build + 1.1s test
***MISSED   payjoin/src/send/v2/mod.rs:289:9: replace V2GetContext::process_response -> Result<Option<Psbt>, ResponseError> with Ok(None) in 8.6s build + 1.2s test
caught   payjoin/src/send/v2/mod.rs:146:45: replace > with < in Sender::extract_v2 in 66.0s build + 0.6s test
17 mutants tested in 1m 32s: 2 missed, 4 caught, 11 unviable

Note the 2 main improvements that can be made are for creating a test for process_response and catching the test_extract_v2_fails_when_expired slightly better

@coveralls
Copy link
Collaborator

coveralls commented Feb 25, 2025

Pull Request Test Coverage Report for Build 13789274853

Details

  • 88 of 90 (97.78%) changed or added relevant lines in 3 files are covered.
  • 4 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+0.5%) to 80.165%

Changes Missing Coverage Covered Lines Changed/Added Lines %
payjoin/src/send/v2/mod.rs 80 82 97.56%
Files with Coverage Reduction New Missed Lines %
payjoin/src/send/v2/mod.rs 1 96.59%
payjoin-test-utils/src/lib.rs 3 97.01%
Totals Coverage Status
Change from base Build 13751979319: 0.5%
Covered Lines: 4652
Relevant Lines: 5803

💛 - Coveralls

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.

Currently missing is the test for process_response which I was unable to make significant progress on as I was not able to parse what I anticipated as expected values for the ohttp encapsulation/decapsulation. Ideally we should have a test for that added so I have created a TODO there.

Since the response must come from the OHTTP relay, I think the only way to do this in a unit test would be to get a "real" OHTTP response from e.g. an integration test and all known parameters, and hardcode these into the unit test.

Until the test actually exists, we should remove the placeholder. Currently it results in a test "success" which is misleading since it doesn't actually test anything.

@benalleng
Copy link
Collaborator Author

benalleng commented Feb 26, 2025

Ok! Yeah I was exploring the do_v2_send_receive integration test but short of passing in a fixed response which is ~8000 bytes long I couldn't think of a way to realistically test this as it's all currently async tokio tests there.
I'll go ahead and remove the placeholder

@benalleng benalleng force-pushed the send-v2-module-tests branch from c68713f to 0dd746b Compare February 26, 2025 18:53
@benalleng benalleng changed the title Add tests for send v2 module Add additional tests for send v2 module Feb 26, 2025
@benalleng benalleng force-pushed the send-v2-module-tests branch 2 times, most recently from 88f1cba to 7df2f64 Compare February 26, 2025 23:22
@benalleng benalleng changed the title Add additional tests for send v2 module Add additional tests for v2 send module Feb 27, 2025
@benalleng benalleng force-pushed the send-v2-module-tests branch 2 times, most recently from f88b4d8 to 23bbd82 Compare March 4, 2025 15:16
@benalleng benalleng force-pushed the send-v2-module-tests branch from 23bbd82 to a81b432 Compare March 4, 2025 16:42
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 a81b432

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.

Nice additional coverage

ACK a81b432

Message matching must be replaced with variant matching upon #403

@benalleng benalleng force-pushed the send-v2-module-tests branch from a81b432 to 46f4642 Compare March 4, 2025 18:30
let sender = create_sender_context()?;
let ohttp_relay = EXAMPLE_URL.clone();
let result = sender.extract_v2(ohttp_relay);
assert!(result.is_ok(), "Expected Ok result, got: {:#?}", result.err());
Copy link

Choose a reason for hiding this comment

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

This is great! but I think unwrap() on the result is going to be more verbose, and better for debugging when the test does fail.

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 am doing my best to avoid .unwrap() in these tests just to keep in line with the remove unwrap even in tests issue I referenced at the beginning of this PR

Copy link
Collaborator

Choose a reason for hiding this comment

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

FWIW I think this line is equivalent to doing something likelet (request, context) = result.expect("result shoud be Ok"); - this avoids unwrap, saves a line, and provides a more verbose output on failure.

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.

@elnosh caught a real problem

@benalleng benalleng force-pushed the send-v2-module-tests branch 3 times, most recently from f7331ca to 728227d Compare March 7, 2025 17:50
This is an attempt to both add some additional test vectors and to create some
headway on the tests deficiencies caught by cargo mutants.

Currently missing is the test for process_response which I was unable to make
significant progress on as that test currently expects an actual response from
an ohttp relay. Until we can make any progress on that test I have left that
test absent for now.
@benalleng benalleng force-pushed the send-v2-module-tests branch from 728227d to 53db3f8 Compare March 11, 2025 13:30
@spacebear21 spacebear21 dismissed DanGould’s stale review March 13, 2025 01:26

Addressed in follow-up

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 53db3f8

@benalleng thank you very much for your diligent work on this PR, and thanks to all who reviewed and provided great feedback!

@spacebear21 spacebear21 merged commit 47cbbe9 into payjoin:master Mar 13, 2025
7 checks passed
@DanGould
Copy link
Contributor

Wow, great to see this merged this morning. Thanks Ben, Spacebear, and the many others who came to review 🔥

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.

7 participants