aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAndrew Chow <achow101-github@achow101.com>2022-07-28 17:23:11 -0400
committerAndrew Chow <achow101-github@achow101.com>2022-07-28 17:34:28 -0400
commit317ef0368b40732526fe08e966192bbebe8c4447 (patch)
tree7d50b37a22497a8508c6d78714f79ade9421f34a /test
parent41205bf442254d17bc7885f3b2693749da714a0e (diff)
parent4e616d20c9e92b5118a07d4a4b8562fffc66e767 (diff)
downloadbitcoin-317ef0368b40732526fe08e966192bbebe8c4447.tar.xz
Merge bitcoin/bitcoin#25670: test: check that combining PSBTs with different txs fails
4e616d20c9e92b5118a07d4a4b8562fffc66e767 test: check that combining PSBTs with different txs fails (Sebastian Falbesoner) 2a428c79897761579efc990aaf810b0eb3e572b6 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 https://github.com/bitcoin/bitcoin/pull/25670/commits/4e616d20c9e92b5118a07d4a4b8562fffc66e767 achow101: ACK 4e616d20c9e92b5118a07d4a4b8562fffc66e767 Tree-SHA512: 45b2b224b13b44ad69ae62e4bc20f74cab32770cf8127b026ec47a7520f7253148fdbf1fad612afece59e45a6738bef9a351ae87ea98dc83d095cc78f6db0318
Diffstat (limited to 'test')
-rwxr-xr-xtest/functional/rpc_psbt.py10
-rw-r--r--test/functional/test_framework/psbt.py8
2 files changed, 14 insertions, 4 deletions
diff --git a/test/functional/rpc_psbt.py b/test/functional/rpc_psbt.py
index a6566f152f..23a581469e 100755
--- a/test/functional/rpc_psbt.py
+++ b/test/functional/rpc_psbt.py
@@ -820,6 +820,16 @@ class PSBTTest(BitcoinTestFramework):
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()
diff --git a/test/functional/test_framework/psbt.py b/test/functional/test_framework/psbt.py
index ad3fe29b62..68945e7e84 100644
--- a/test/functional/test_framework/psbt.py
+++ b/test/functional/test_framework/psbt.py
@@ -96,10 +96,10 @@ class PSBTMap:
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):