Skip to content

Commit e1d4a12

Browse files
committed
test: simplify and document NULLDUMMY-invalidation helper
The function `trueDummy` in feature_nulldummy.py is currently more complicated than it needs to be. Rather than converting the scriptSig to a CScript and looping through it to build a new scriptSig with the modified push, simply directly replace the push of null (OP_0) with a push of one (OP_TRUE/OP_1). Note that on master, actually an element with the value of 0x51 is pushed (0x0151...) -- this was very likely not intended, as 0x51 is the script op-code for OP_TRUE, and also the function's name suggests that the "true" value shall be pushed.
1 parent c9dd5c8 commit e1d4a12

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

test/functional/feature_nulldummy.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@
2222
create_transaction,
2323
)
2424
from test_framework.messages import CTransaction
25-
from test_framework.script import CScript
25+
from test_framework.script import (
26+
OP_0,
27+
OP_TRUE,
28+
)
2629
from test_framework.test_framework import BitcoinTestFramework
2730
from test_framework.util import (
2831
assert_equal,
@@ -33,15 +36,10 @@
3336

3437

3538
def trueDummy(tx):
36-
scriptSig = CScript(tx.vin[0].scriptSig)
37-
newscript = []
38-
for i in scriptSig:
39-
if len(newscript) == 0:
40-
assert len(i) == 0
41-
newscript.append(b'\x51')
42-
else:
43-
newscript.append(i)
44-
tx.vin[0].scriptSig = CScript(newscript)
39+
"""Transform a NULLDUMMY compliant tx (i.e. scriptSig starts with OP_0)
40+
to be non-NULLDUMMY compliant by replacing the dummy with OP_TRUE"""
41+
assert_equal(tx.vin[0].scriptSig[0], OP_0)
42+
tx.vin[0].scriptSig = bytes([OP_TRUE]) + tx.vin[0].scriptSig[1:]
4543
tx.rehash()
4644

4745

0 commit comments

Comments
 (0)