Skip to content

Commit e133264

Browse files
committed
Add test for PSBT input verification
1 parent d256992 commit e133264

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

test/functional/rpc_psbt.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@
2727
PSBT_IN_SHA256,
2828
PSBT_IN_HASH160,
2929
PSBT_IN_HASH256,
30+
PSBT_IN_WITNESS_UTXO,
3031
PSBT_OUT_TAP_TREE,
3132
)
33+
from test_framework.script import CScript, OP_TRUE
3234
from test_framework.test_framework import BitcoinTestFramework
3335
from test_framework.util import (
3436
assert_approx,
@@ -852,6 +854,18 @@ def test_psbt_input_keys(psbt_input, keys):
852854
assert_raises_rpc_error(-8, "PSBTs not compatible (different transactions)", self.nodes[0].combinepsbt, [psbt1, psbt2])
853855
assert_equal(self.nodes[0].combinepsbt([psbt1, psbt1]), psbt1)
854856

857+
self.log.info("Test that PSBT inputs are being checked via script execution")
858+
acs_prevout = CTxOut(nValue=0, scriptPubKey=CScript([OP_TRUE]))
859+
tx = CTransaction()
860+
tx.vin = [CTxIn(outpoint=COutPoint(hash=int('dd' * 32, 16), n=0), scriptSig=b"")]
861+
tx.vout = [CTxOut(nValue=0, scriptPubKey=b"")]
862+
psbt = PSBT()
863+
psbt.g = PSBTMap({PSBT_GLOBAL_UNSIGNED_TX: tx.serialize()})
864+
psbt.i = [PSBTMap({bytes([PSBT_IN_WITNESS_UTXO]) : acs_prevout.serialize()})]
865+
psbt.o = [PSBTMap()]
866+
assert_equal(self.nodes[0].finalizepsbt(psbt.to_base64()),
867+
{'hex': '0200000001dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd0000000000000000000100000000000000000000000000', 'complete': True})
868+
855869

856870
if __name__ == '__main__':
857871
PSBTTest().main()

0 commit comments

Comments
 (0)