Skip to content

Commit e57c0eb

Browse files
committed
test: refactor: replace OP_1/OP_TRUE magic numbers by constants
1 parent df5d783 commit e57c0eb

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

test/functional/p2p_invalid_block.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,14 @@
1515
import copy
1616
import time
1717

18-
from test_framework.blocktools import create_block, create_coinbase, create_tx_with_script
18+
from test_framework.blocktools import (
19+
create_block,
20+
create_coinbase,
21+
create_tx_with_script,
22+
)
1923
from test_framework.messages import COIN
2024
from test_framework.p2p import P2PDataStore
25+
from test_framework.script import OP_TRUE
2126
from test_framework.test_framework import BitcoinTestFramework
2227
from test_framework.util import assert_equal
2328

@@ -66,9 +71,8 @@ def run_test(self):
6671
# For more information on merkle-root malleability see src/consensus/merkle.cpp.
6772
self.log.info("Test merkle root malleability.")
6873

69-
# b'0x51' is OP_TRUE
70-
tx1 = create_tx_with_script(block1.vtx[0], 0, script_sig=b'\x51', amount=50 * COIN)
71-
tx2 = create_tx_with_script(tx1, 0, script_sig=b'\x51', amount=50 * COIN)
74+
tx1 = create_tx_with_script(block1.vtx[0], 0, script_sig=bytes([OP_TRUE]), amount=50 * COIN)
75+
tx2 = create_tx_with_script(tx1, 0, script_sig=bytes([OP_TRUE]), amount=50 * COIN)
7276
block2 = create_block(tip, create_coinbase(height), block_time, txlist=[tx1, tx2])
7377
block_time += 1
7478
block2.solve()
@@ -115,7 +119,7 @@ def run_test(self):
115119

116120
# Complete testing of CVE-2018-17144, by checking for the inflation bug.
117121
# Create a block that spends the output of a tx in a previous block.
118-
tx3 = create_tx_with_script(tx2, 0, script_sig=b'\x51', amount=50 * COIN)
122+
tx3 = create_tx_with_script(tx2, 0, script_sig=bytes([OP_TRUE]), amount=50 * COIN)
119123
tx3.vin.append(tx3.vin[0]) # Duplicates input
120124
tx3.rehash()
121125
block4 = create_block(tip, create_coinbase(height), block_time, txlist=[tx3])

test/functional/wallet_taproot.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@
1010
from test_framework.test_framework import BitcoinTestFramework
1111
from test_framework.util import assert_equal
1212
from test_framework.descriptors import descsum_create
13-
from test_framework.script import (CScript, OP_CHECKSIG, taproot_construct)
13+
from test_framework.script import (
14+
CScript,
15+
OP_1,
16+
OP_CHECKSIG,
17+
taproot_construct,
18+
)
1419
from test_framework.segwit_addr import encode_segwit_address
1520

1621
# xprvs/xpubs, and m/* derived x-only pubkeys (created using independent implementation)
@@ -165,7 +170,7 @@ def pk(hex_key):
165170
def compute_taproot_address(pubkey, scripts):
166171
"""Compute the address for a taproot output with given inner key and scripts."""
167172
tap = taproot_construct(pubkey, scripts)
168-
assert tap.scriptPubKey[0] == 0x51
173+
assert tap.scriptPubKey[0] == OP_1
169174
assert tap.scriptPubKey[1] == 0x20
170175
return encode_segwit_address("bcrt", 1, tap.scriptPubKey[2:])
171176

0 commit comments

Comments
 (0)