mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-09-01 07:01:35 +02:00
tests: Test PSBT sighash type mismatch
This commit is contained in:
@@ -27,6 +27,7 @@ from test_framework.psbt import (
|
||||
PSBT_GLOBAL_UNSIGNED_TX,
|
||||
PSBT_IN_RIPEMD160,
|
||||
PSBT_IN_SHA256,
|
||||
PSBT_IN_SIGHASH_TYPE,
|
||||
PSBT_IN_HASH160,
|
||||
PSBT_IN_HASH256,
|
||||
PSBT_IN_MUSIG2_PARTIAL_SIG,
|
||||
@@ -37,7 +38,7 @@ from test_framework.psbt import (
|
||||
PSBT_OUT_MUSIG2_PARTICIPANT_PUBKEYS,
|
||||
PSBT_OUT_TAP_TREE,
|
||||
)
|
||||
from test_framework.script import CScript, OP_TRUE
|
||||
from test_framework.script import CScript, OP_TRUE, SIGHASH_ALL, SIGHASH_ANYONECANPAY
|
||||
from test_framework.script_util import MIN_STANDARD_TX_NONWITNESS_SIZE
|
||||
from test_framework.test_framework import BitcoinTestFramework
|
||||
from test_framework.util import (
|
||||
@@ -272,6 +273,34 @@ class PSBTTest(BitcoinTestFramework):
|
||||
assert "participant_pubkeys" in out_participant_pks
|
||||
assert_equal(out_participant_pks["participant_pubkeys"], [out_pubkey1.hex(), out_pubkey2.hex()])
|
||||
|
||||
def test_sighash_mismatch(self):
|
||||
self.log.info("Test sighash type mismatches")
|
||||
self.nodes[0].createwallet("sighash_mismatch")
|
||||
wallet = self.nodes[0].get_wallet_rpc("sighash_mismatch")
|
||||
def_wallet = self.nodes[0].get_wallet_rpc(self.default_wallet_name)
|
||||
|
||||
addr = wallet.getnewaddress(address_type="bech32")
|
||||
def_wallet.sendtoaddress(addr, 5)
|
||||
self.generate(self.nodes[0], 6)
|
||||
|
||||
# Make a PSBT
|
||||
psbt = wallet.walletcreatefundedpsbt([], [{def_wallet.getnewaddress(): 1}])["psbt"]
|
||||
|
||||
# Modify the PSBT and insert a sighash field for ALL|ANYONECANPAY on input 0
|
||||
mod_psbt = PSBT.from_base64(psbt)
|
||||
mod_psbt.i[0].map[PSBT_IN_SIGHASH_TYPE] = (SIGHASH_ALL | SIGHASH_ANYONECANPAY).to_bytes(4, byteorder="little")
|
||||
psbt = mod_psbt.to_base64()
|
||||
|
||||
# Mismatching sighash type fails, including when no type is specified
|
||||
for sighash in ["DEFAULT", "ALL", "NONE", "SINGLE", "NONE|ANYONECANPAY", "SINGLE|ANYONECANPAY", None]:
|
||||
assert_raises_rpc_error(-22, "Specified sighash value does not match value stored in PSBT", wallet.walletprocesspsbt, psbt, True, sighash)
|
||||
|
||||
# Matching sighash type succeeds
|
||||
proc = wallet.walletprocesspsbt(psbt, True, "ALL|ANYONECANPAY")
|
||||
assert_equal(proc["complete"], True)
|
||||
|
||||
wallet.unloadwallet()
|
||||
|
||||
def assert_change_type(self, psbtx, expected_type):
|
||||
"""Assert that the given PSBT has a change output with the given type."""
|
||||
|
||||
@@ -1109,6 +1138,7 @@ class PSBTTest(BitcoinTestFramework):
|
||||
self.log.info("Test descriptorprocesspsbt raises if an invalid sighashtype is passed")
|
||||
assert_raises_rpc_error(-8, "'all' is not a valid sighash parameter.", self.nodes[2].descriptorprocesspsbt, psbt, [descriptor], sighashtype="all")
|
||||
|
||||
self.test_sighash_mismatch()
|
||||
|
||||
if __name__ == '__main__':
|
||||
PSBTTest(__file__).main()
|
||||
|
Reference in New Issue
Block a user