Skip to content

Commit 317ef03

Browse files
committed
Merge bitcoin/bitcoin#25670: test: check that combining PSBTs with different 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
2 parents 41205bf + 4e616d2 commit 317ef03

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

test/functional/rpc_psbt.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,16 @@ def test_psbt_input_keys(psbt_input, keys):
820820
assert hash.hex() in res_input[preimage_key]
821821
assert_equal(res_input[preimage_key][hash.hex()], preimage.hex())
822822

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

824834
if __name__ == '__main__':
825835
PSBTTest().main()

test/functional/test_framework/psbt.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,10 @@ def serialize(self):
9696
class PSBT:
9797
"""Class for serializing and deserializing PSBTs"""
9898

99-
def __init__(self):
100-
self.g = PSBTMap()
101-
self.i = []
102-
self.o = []
99+
def __init__(self, *, g=None, i=None, o=None):
100+
self.g = g if g is not None else PSBTMap()
101+
self.i = i if i is not None else []
102+
self.o = o if o is not None else []
103103
self.tx = None
104104

105105
def deserialize(self, f):

0 commit comments

Comments
 (0)