mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-06-29 18:20:58 +02:00
test: use script_util helpers for creating P2SH scripts
This commit is contained in:
@ -62,8 +62,6 @@ from test_framework.script import (
|
||||
OP_DROP,
|
||||
OP_ELSE,
|
||||
OP_ENDIF,
|
||||
OP_EQUAL,
|
||||
OP_HASH160,
|
||||
OP_IF,
|
||||
OP_RETURN,
|
||||
OP_TRUE,
|
||||
@ -77,6 +75,7 @@ from test_framework.script import (
|
||||
)
|
||||
from test_framework.script_util import (
|
||||
keyhash_to_p2pkh_script,
|
||||
script_to_p2sh_script,
|
||||
)
|
||||
from test_framework.test_framework import BitcoinTestFramework
|
||||
from test_framework.util import (
|
||||
@ -491,9 +490,7 @@ class SegWitTest(BitcoinTestFramework):
|
||||
witness_program = CScript([OP_TRUE])
|
||||
witness_hash = sha256(witness_program)
|
||||
script_pubkey = CScript([OP_0, witness_hash])
|
||||
|
||||
p2sh_pubkey = hash160(script_pubkey)
|
||||
p2sh_script_pubkey = CScript([OP_HASH160, p2sh_pubkey, OP_EQUAL])
|
||||
p2sh_script_pubkey = script_to_p2sh_script(script_pubkey)
|
||||
|
||||
value = self.utxo[0].nValue // 3
|
||||
|
||||
@ -630,9 +627,7 @@ class SegWitTest(BitcoinTestFramework):
|
||||
witness_program = CScript([OP_TRUE])
|
||||
witness_hash = sha256(witness_program)
|
||||
script_pubkey = CScript([OP_0, witness_hash])
|
||||
|
||||
p2sh_pubkey = hash160(witness_program)
|
||||
p2sh_script_pubkey = CScript([OP_HASH160, p2sh_pubkey, OP_EQUAL])
|
||||
p2sh_script_pubkey = script_to_p2sh_script(witness_program)
|
||||
|
||||
# First prepare a p2sh output (so that spending it will pass standardness)
|
||||
p2sh_tx = CTransaction()
|
||||
@ -739,8 +734,7 @@ class SegWitTest(BitcoinTestFramework):
|
||||
witness_program = CScript([OP_DROP, OP_TRUE])
|
||||
witness_hash = sha256(witness_program)
|
||||
p2wsh_pubkey = CScript([OP_0, witness_hash])
|
||||
p2sh_witness_hash = hash160(p2wsh_pubkey)
|
||||
script_pubkey = CScript([OP_HASH160, p2sh_witness_hash, OP_EQUAL])
|
||||
script_pubkey = script_to_p2sh_script(p2wsh_pubkey)
|
||||
script_sig = CScript([p2wsh_pubkey]) # a push of the redeem script
|
||||
|
||||
# Fund the P2SH output
|
||||
@ -1328,9 +1322,8 @@ class SegWitTest(BitcoinTestFramework):
|
||||
|
||||
# Add too-large for IsStandard witness and check that it does not enter reject filter
|
||||
p2sh_program = CScript([OP_TRUE])
|
||||
p2sh_pubkey = hash160(p2sh_program)
|
||||
witness_program2 = CScript([b'a' * 400000])
|
||||
tx3.vout.append(CTxOut(tx2.vout[0].nValue - 1000, CScript([OP_HASH160, p2sh_pubkey, OP_EQUAL])))
|
||||
tx3.vout.append(CTxOut(tx2.vout[0].nValue - 1000, script_to_p2sh_script(p2sh_program)))
|
||||
tx3.wit.vtxinwit[0].scriptWitness.stack = [witness_program2]
|
||||
tx3.rehash()
|
||||
|
||||
@ -1564,8 +1557,7 @@ class SegWitTest(BitcoinTestFramework):
|
||||
# Test 2: P2WSH
|
||||
# Try to spend the P2WSH output created in last test.
|
||||
# Send it to a P2SH(P2WSH) output, which we'll use in the next test.
|
||||
p2sh_witness_hash = hash160(script_wsh)
|
||||
script_p2sh = CScript([OP_HASH160, p2sh_witness_hash, OP_EQUAL])
|
||||
script_p2sh = script_to_p2sh_script(script_wsh)
|
||||
script_sig = CScript([script_wsh])
|
||||
|
||||
tx3 = CTransaction()
|
||||
@ -1803,8 +1795,7 @@ class SegWitTest(BitcoinTestFramework):
|
||||
# rules (an anyone-can-spend OP_TRUE would be rejected, if not wrapped
|
||||
# in P2SH).
|
||||
p2sh_program = CScript([OP_TRUE])
|
||||
p2sh_pubkey = hash160(p2sh_program)
|
||||
script_pubkey = CScript([OP_HASH160, p2sh_pubkey, OP_EQUAL])
|
||||
script_pubkey = script_to_p2sh_script(p2sh_program)
|
||||
|
||||
# Now check that unnecessary witnesses can't be used to blind a node
|
||||
# to a transaction, eg by violating standardness checks.
|
||||
@ -1870,10 +1861,9 @@ class SegWitTest(BitcoinTestFramework):
|
||||
outputvalue = (self.utxo[0].nValue - 1000) // (len(scripts) * 2)
|
||||
for i in scripts:
|
||||
p2wsh = CScript([OP_0, sha256(i)])
|
||||
p2sh = hash160(p2wsh)
|
||||
p2wsh_scripts.append(p2wsh)
|
||||
tx.vout.append(CTxOut(outputvalue, p2wsh))
|
||||
tx.vout.append(CTxOut(outputvalue, CScript([OP_HASH160, p2sh, OP_EQUAL])))
|
||||
tx.vout.append(CTxOut(outputvalue, script_to_p2sh_script(p2wsh)))
|
||||
tx.rehash()
|
||||
txid = tx.sha256
|
||||
test_transaction_acceptance(self.nodes[0], self.test_node, tx, with_witness=False, accepted=True)
|
||||
|
Reference in New Issue
Block a user