Skip to content

test: check that combining PSBTs with different txs fails - #25670

Merged
achow101 merged 2 commits into
bitcoin:masterfrom
theStack:202207-test-add_combinepsbts_fail_test
Jul 28, 2022
Merged

achow101 merged 2 commits into
bitcoin:masterfrom
theStack:202207-test-add_combinepsbts_fail_test

Conversation

@theStack

Copy link
Copy Markdown
Contributor

This PR adds missing test coverage for the combinepsbt RPC, in the case of combining two PSBTs with different transactions:

bitcoin/src/psbt.cpp

Lines 24 to 27 in b8067cd

// Prohibited to merge two PSBTs over different transactions
if (tx->GetHash() != psbt.tx->GetHash()) {
return false;
}

The calling function CombinePSBTs checks for the false return value and then returns the transaction error string PSBT_MISMATCH:

bitcoin/src/psbt.cpp

Lines 433 to 435 in b8067cd

if (!out.Merge(*it)) {
return TransactionError::PSBT_MISMATCH;
}

case TransactionError::PSBT_MISMATCH:
return Untranslated("PSBTs not compatible (different transactions)");

@fanquake fanquake added the Tests label Jul 21, 2022
@theStack
theStack force-pushed the 202207-test-add_combinepsbts_fail_test branch from d79d846 to b4f3322 Compare July 21, 2022 20:29
@theStack

Copy link
Copy Markdown
Contributor Author

Force-pushed a different variant of the first commit (extending the PSBT ctor), avoiding mutable objects as default parameters due to the following linter complaint:

A mutable list or dict seems to be used as default parameter value:

test/functional/test_framework/psbt.py:    def __init__(self, g=PSBTMap(), i=[], o=[]):

This is how mutable list and dict default parameter values behave:

>>> def f(i, j=[], k={}):
...     j.append(i)
...     k[i] = True
...     return j, k
...
>>> f(1)
([1], {1: True})
>>> f(1)
([1, 1], {1: True})
>>> f(2)
([1, 1, 2], {1: True, 2: True})

The intended behaviour was likely:

>>> def f(i, j=None, k=None):
...     if j is None:
...         j = []
...     if k is None:
...         k = {}
...     j.append(i)
...     k[i] = True
...     return j, k
...
>>> f(1)
([1], {1: True})
>>> f(1)
([1], {1: True})
>>> f(2)
([2], {2: True})

@fanquake
fanquake requested review from achow101 and instagibbs July 22, 2022 07:48

@instagibbs instagibbs left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ACK b4f332275c593d5c8f454f3e2b7f5d491ef4f520

Comment thread test/functional/rpc_psbt.py Resolved
Comment thread test/functional/rpc_psbt.py Resolved
Comment thread test/functional/rpc_psbt.py Resolved
This will allow to create simple PSBTs as short one-liners, without the
need to have three individual assignments (globals, inputs, outputs).
@theStack
theStack force-pushed the 202207-test-add_combinepsbts_fail_test branch from b4f3322 to 16a0b28 Compare July 23, 2022 07:02
@theStack

Copy link
Copy Markdown
Contributor Author

Force-pushed with changes as suggested by @instagibbs (named arguments for PSBT ctor, adding call for success case of combining two identical PSBTs).

@theStack
theStack force-pushed the 202207-test-add_combinepsbts_fail_test branch from 16a0b28 to 4e616d2 Compare July 23, 2022 07:09
@fanquake
fanquake requested a review from instagibbs July 25, 2022 15:13
@instagibbs

Copy link
Copy Markdown
Member

reACK 4e616d2

@achow101

Copy link
Copy Markdown
Member

ACK 4e616d2

@achow101
achow101 merged commit 317ef03 into bitcoin:master Jul 28, 2022
@bitcoin bitcoin locked and limited conversation to collaborators Jul 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants