Receiver<Monitor> integration tests for different script patterns and sender behaviors#1211
Conversation
Pull Request Test Coverage Report for Build 19999836616Details
💛 - Coveralls |
arminsabouri
left a comment
There was a problem hiding this comment.
I appreciate you keeping these commits clean! Did a first pass, approach looks good. Hand a handful of pointers for reducing the code changes in this PR and a few nits.
payjoin/tests/integration.rs
Outdated
| |_| { | ||
| panic!("We should never check outpoints since the payjoin tx has been broadcasted") | ||
| |outpoint| { | ||
| match address_type { |
There was a problem hiding this comment.
Do we need a match on address type?
There was a problem hiding this comment.
It is an additional validation for the order of operations in the check_payment function. Since it should return Success if the TXID is found, this closure should never be run. This validates that that is the case.
There was a problem hiding this comment.
I understand now, thanks. We could use a comment to explain this. Same thing for getting the tx via txid. e.g "non-segwit inputs will have a different txid after sender signs"
38a4a1e to
2b0d2db
Compare
payjoin/tests/integration.rs
Outdated
| |_| { | ||
| panic!("We should never check outpoints since the payjoin tx has been broadcasted") | ||
| |outpoint| { | ||
| match address_type { |
There was a problem hiding this comment.
I understand now, thanks. We could use a comment to explain this. Same thing for getting the tx via txid. e.g "non-segwit inputs will have a different txid after sender signs"
payjoin/tests/integration.rs
Outdated
| // broadcasting the fallback transaction (both of which the receiver is aware of) | ||
| // instead they broadcast another transaction which spends the senders outputs in a | ||
| // transaction the receiver has not seen before. | ||
| let double_spend_tx = extract_pj_tx(&sender, double_spend_psbt)?; |
There was a problem hiding this comment.
Unrelated to this PR but extract_pj_tx should probably be renamed to sign_and_finalize_psbt
payjoin/tests/integration.rs
Outdated
| // transaction the receiver has not seen before, but using the outpoint which the | ||
| // sender included in the original proposal. | ||
| let mut double_spend_tx = psbt.clone().unsigned_tx; | ||
| double_spend_tx.output[0].value -= Amount::from_sat(1); |
There was a problem hiding this comment.
I am not sure this is actually emulating a double spend. This is the fallback tx with the output value slightly adjusted -- kinda emulating a RBF on a fallback tx. I was expecting a tx spending the same inputs to entirely different outputs. However, I still think there is some merit behind this test. If the sender does RBF the fallback, the receiver can still pick it up. In that case we may want to rename this test to something like: "RBF'd fallback" or "Output adjusted fallback".
There was a problem hiding this comment.
In the current Monitor implementation, if the sender does RBF on a non-segwit fallback transaction, the receiver will pick it up as a double-spend (which I thought what double-spend in the context of a Payjoin session was while writing the PR 😅)
With that in mind, I do not think the source code is ready for this test at the moment. Or we can put a big TODO next to it to and keep it active so that it tests the eventual fix or re-design under #1214.
2b0d2db to
2d9d5d5
Compare
2d9d5d5 to
c14b2c1
Compare
arminsabouri
left a comment
There was a problem hiding this comment.
cACK c14b2c1
Great work reducing the boilerplate and code de-duplication.
| panic!("psbt should exist"); | ||
| }; | ||
|
|
||
| let broadcasted_transaction = match sender_final_action { |
There was a problem hiding this comment.
Nit:
| let broadcasted_transaction = match sender_final_action { | |
| let tx_to_broadcast = match sender_final_action { |
spacebear21
left a comment
There was a problem hiding this comment.
ACK c14b2c1, nice work on the SenderFinalAction refactor!
Pull Request Checklist
Please confirm the following before requesting review:
AI
in the body of this PR.
Closes #1137.
Overview
This PR adds:
Receiver<Monitor>and thecheck_paymentfunction.Note that this PR does not implement tests for other wallet types or double-spend attack due to #1214. When the non-segwit monitoring is finalized, there should be more integration test scenarios to cover them.