mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-02 09:46:52 -05:00
test: refactor: replace OP_1/OP_TRUE magic numbers by constants
This commit is contained in:
parent
df5d783aef
commit
e57c0eb865
2 changed files with 16 additions and 7 deletions
|
@ -15,9 +15,14 @@ becomes valid.
|
|||
import copy
|
||||
import time
|
||||
|
||||
from test_framework.blocktools import create_block, create_coinbase, create_tx_with_script
|
||||
from test_framework.blocktools import (
|
||||
create_block,
|
||||
create_coinbase,
|
||||
create_tx_with_script,
|
||||
)
|
||||
from test_framework.messages import COIN
|
||||
from test_framework.p2p import P2PDataStore
|
||||
from test_framework.script import OP_TRUE
|
||||
from test_framework.test_framework import BitcoinTestFramework
|
||||
from test_framework.util import assert_equal
|
||||
|
||||
|
@ -66,9 +71,8 @@ class InvalidBlockRequestTest(BitcoinTestFramework):
|
|||
# For more information on merkle-root malleability see src/consensus/merkle.cpp.
|
||||
self.log.info("Test merkle root malleability.")
|
||||
|
||||
# b'0x51' is OP_TRUE
|
||||
tx1 = create_tx_with_script(block1.vtx[0], 0, script_sig=b'\x51', amount=50 * COIN)
|
||||
tx2 = create_tx_with_script(tx1, 0, script_sig=b'\x51', amount=50 * COIN)
|
||||
tx1 = create_tx_with_script(block1.vtx[0], 0, script_sig=bytes([OP_TRUE]), amount=50 * COIN)
|
||||
tx2 = create_tx_with_script(tx1, 0, script_sig=bytes([OP_TRUE]), amount=50 * COIN)
|
||||
block2 = create_block(tip, create_coinbase(height), block_time, txlist=[tx1, tx2])
|
||||
block_time += 1
|
||||
block2.solve()
|
||||
|
@ -115,7 +119,7 @@ class InvalidBlockRequestTest(BitcoinTestFramework):
|
|||
|
||||
# Complete testing of CVE-2018-17144, by checking for the inflation bug.
|
||||
# Create a block that spends the output of a tx in a previous block.
|
||||
tx3 = create_tx_with_script(tx2, 0, script_sig=b'\x51', amount=50 * COIN)
|
||||
tx3 = create_tx_with_script(tx2, 0, script_sig=bytes([OP_TRUE]), amount=50 * COIN)
|
||||
tx3.vin.append(tx3.vin[0]) # Duplicates input
|
||||
tx3.rehash()
|
||||
block4 = create_block(tip, create_coinbase(height), block_time, txlist=[tx3])
|
||||
|
|
|
@ -10,7 +10,12 @@ from decimal import Decimal
|
|||
from test_framework.test_framework import BitcoinTestFramework
|
||||
from test_framework.util import assert_equal
|
||||
from test_framework.descriptors import descsum_create
|
||||
from test_framework.script import (CScript, OP_CHECKSIG, taproot_construct)
|
||||
from test_framework.script import (
|
||||
CScript,
|
||||
OP_1,
|
||||
OP_CHECKSIG,
|
||||
taproot_construct,
|
||||
)
|
||||
from test_framework.segwit_addr import encode_segwit_address
|
||||
|
||||
# xprvs/xpubs, and m/* derived x-only pubkeys (created using independent implementation)
|
||||
|
@ -165,7 +170,7 @@ def pk(hex_key):
|
|||
def compute_taproot_address(pubkey, scripts):
|
||||
"""Compute the address for a taproot output with given inner key and scripts."""
|
||||
tap = taproot_construct(pubkey, scripts)
|
||||
assert tap.scriptPubKey[0] == 0x51
|
||||
assert tap.scriptPubKey[0] == OP_1
|
||||
assert tap.scriptPubKey[1] == 0x20
|
||||
return encode_segwit_address("bcrt", 1, tap.scriptPubKey[2:])
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue