From 2a428c79897761579efc990aaf810b0eb3e572b6 Mon Sep 17 00:00:00 2001 From: Sebastian Falbesoner Date: Tue, 19 Jul 2022 15:00:20 +0200 Subject: [PATCH 1/2] test: support passing PSBTMaps directly to PSBT ctor This will allow to create simple PSBTs as short one-liners, without the need to have three individual assignments (globals, inputs, outputs). --- test/functional/test_framework/psbt.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 @@ 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): From 4e616d20c9e92b5118a07d4a4b8562fffc66e767 Mon Sep 17 00:00:00 2001 From: Sebastian Falbesoner Date: Tue, 19 Jul 2022 15:01:06 +0200 Subject: [PATCH 2/2] test: check that combining PSBTs with different txs fails --- test/functional/rpc_psbt.py | 10 ++++++++++ 1 file changed, 10 insertions(+) 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 @@ 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()