Skip to content

Commit

Permalink
Merge bitcoin/bitcoin#25670: test: check that combining PSBTs with di…
Browse files Browse the repository at this point in the history
…fferent txs fails

4e616d2 test: check that combining PSBTs with different txs fails (Sebastian Falbesoner)
2a428c7 test: support passing PSBTMaps directly to PSBT ctor (Sebastian Falbesoner)

Pull request description:

  This PR adds missing test coverage for the `combinepsbt` RPC, in the case of combining two PSBTs with different transactions:
  https://github.com/bitcoin/bitcoin/blob/b8067cd435059eedb580975afc62c4e7a6f27321/src/psbt.cpp#L24-L27
  The calling function `CombinePSBTs` checks for the false return value and then returns the transaction error string `PSBT_MISMATCH`:
  https://github.com/bitcoin/bitcoin/blob/b8067cd435059eedb580975afc62c4e7a6f27321/src/psbt.cpp#L433-L435
  https://github.com/bitcoin/bitcoin/blob/b8067cd435059eedb580975afc62c4e7a6f27321/src/util/error.cpp#L30-L31

ACKs for top commit:
  instagibbs:
    reACK bitcoin/bitcoin@4e616d2
  achow101:
    ACK 4e616d2

Tree-SHA512: 45b2b224b13b44ad69ae62e4bc20f74cab32770cf8127b026ec47a7520f7253148fdbf1fad612afece59e45a6738bef9a351ae87ea98dc83d095cc78f6db0318
  • Loading branch information
achow101 committed Jul 28, 2022
2 parents 41205bf + 4e616d2 commit 317ef03
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
10 changes: 10 additions & 0 deletions test/functional/rpc_psbt.py
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,16 @@ def test_psbt_input_keys(psbt_input, keys):
assert hash.hex() in res_input[preimage_key]
assert_equal(res_input[preimage_key][hash.hex()], preimage.hex())

self.log.info("Test that combining PSBTs with different transactions fails")
tx = CTransaction()
tx.vin = [CTxIn(outpoint=COutPoint(hash=int('aa' * 32, 16), n=0), scriptSig=b"")]
tx.vout = [CTxOut(nValue=0, scriptPubKey=b"")]
psbt1 = PSBT(g=PSBTMap({PSBT_GLOBAL_UNSIGNED_TX: tx.serialize()}), i=[PSBTMap()], o=[PSBTMap()]).to_base64()
tx.vout[0].nValue += 1 # slightly modify tx
psbt2 = PSBT(g=PSBTMap({PSBT_GLOBAL_UNSIGNED_TX: tx.serialize()}), i=[PSBTMap()], o=[PSBTMap()]).to_base64()
assert_raises_rpc_error(-8, "PSBTs not compatible (different transactions)", self.nodes[0].combinepsbt, [psbt1, psbt2])
assert_equal(self.nodes[0].combinepsbt([psbt1, psbt1]), psbt1)


if __name__ == '__main__':
PSBTTest().main()
8 changes: 4 additions & 4 deletions test/functional/test_framework/psbt.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ def serialize(self):
class PSBT:
"""Class for serializing and deserializing PSBTs"""

def __init__(self):
self.g = PSBTMap()
self.i = []
self.o = []
def __init__(self, *, g=None, i=None, o=None):
self.g = g if g is not None else PSBTMap()
self.i = i if i is not None else []
self.o = o if o is not None else []
self.tx = None

def deserialize(self, f):
Expand Down

0 comments on commit 317ef03

Please sign in to comment.