Skip to content

Commit 0b9ed3f

Browse files
author
MarcoFalke
committed
Merge bitcoin/bitcoin#22113: test: minor cleanups in feature_cltv.py
7e32fde test: feature_cltv.py: don't return tx copies in modification functions (Sebastian Falbesoner) 9ab2ce0 test: drop unused node parameters in feature_cltv.py (Sebastian Falbesoner) 0c2139a test: fix typo in feature_cltv.py (s/ctlv/cltv/) (Sebastian Falbesoner) Pull request description: This tiny PR cleans up the test `feature_cltv.py` in the following ways: * fixes a typo (s/ctlv/cltv/); compared to CHECKLOCKTIMEVERIFY, CHECKTIMELOCKVERIFY probably also sounds good and you [even get some search results for it](https://www.google.com/search?q=%22CHECKTIMELOCKVERIFY%22), but it's still wrong ;) * drops the unused "node" parameters from the tx modification functions * don't return a copy from the tx modification functions; it's modified in-place, hence a copy is not needed and `cltv_validate(tx, ...)` looks more natural than `tx = cltv_validate(tx, ...)` ACKs for top commit: MarcoFalke: review ACK 7e32fde 📼 Tree-SHA512: d2e6230977442f6a511d0f7c99431a44ad3a423647f4f327ce2ce8efe78bf9616c0d2093f5e3c3550f690dcb3f625ddf53227505c01ced70227425f249c25364
2 parents f63fc53 + 7e32fde commit 0b9ed3f

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

test/functional/feature_cltv.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,17 @@
3737
# Helper function to modify a transaction by
3838
# 1) prepending a given script to the scriptSig of vin 0 and
3939
# 2) (optionally) modify the nSequence of vin 0 and the tx's nLockTime
40-
def cltv_modify_tx(node, tx, prepend_scriptsig, nsequence=None, nlocktime=None):
40+
def cltv_modify_tx(tx, prepend_scriptsig, nsequence=None, nlocktime=None):
4141
assert_equal(len(tx.vin), 1)
4242
if nsequence is not None:
4343
tx.vin[0].nSequence = nsequence
4444
tx.nLockTime = nlocktime
4545

4646
tx.vin[0].scriptSig = CScript(prepend_scriptsig + list(CScript(tx.vin[0].scriptSig)))
4747
tx.rehash()
48-
return tx
4948

5049

51-
def cltv_invalidate(node, tx, failure_reason):
50+
def cltv_invalidate(tx, failure_reason):
5251
# Modify the signature in vin 0 and nSequence/nLockTime of the tx to fail CLTV
5352
#
5453
# According to BIP65, OP_CHECKLOCKTIMEVERIFY can fail due the following reasons:
@@ -69,14 +68,14 @@ def cltv_invalidate(node, tx, failure_reason):
6968
[[CScriptNum(500), OP_CHECKLOCKTIMEVERIFY, OP_DROP], 0xffffffff, 500],
7069
][failure_reason]
7170

72-
return cltv_modify_tx(node, tx, prepend_scriptsig=scheme[0], nsequence=scheme[1], nlocktime=scheme[2])
71+
cltv_modify_tx(tx, prepend_scriptsig=scheme[0], nsequence=scheme[1], nlocktime=scheme[2])
7372

7473

75-
def cltv_validate(node, tx, height):
74+
def cltv_validate(tx, height):
7675
# Modify the signature in vin 0 and nSequence/nLockTime of the tx to pass CLTV
7776
scheme = [[CScriptNum(height), OP_CHECKLOCKTIMEVERIFY, OP_DROP], 0, height]
7877

79-
return cltv_modify_tx(node, tx, prepend_scriptsig=scheme[0], nsequence=scheme[1], nlocktime=scheme[2])
78+
cltv_modify_tx(tx, prepend_scriptsig=scheme[0], nsequence=scheme[1], nlocktime=scheme[2])
8079

8180

8281
class BIP65Test(BitcoinTestFramework):
@@ -111,17 +110,17 @@ def run_test(self):
111110
self.log.info("Test that invalid-according-to-CLTV transactions can still appear in a block")
112111

113112
# create one invalid tx per CLTV failure reason (5 in total) and collect them
114-
invalid_ctlv_txs = []
113+
invalid_cltv_txs = []
115114
for i in range(5):
116115
spendtx = wallet.create_self_transfer(from_node=self.nodes[0])['tx']
117-
spendtx = cltv_invalidate(self.nodes[0], spendtx, i)
118-
invalid_ctlv_txs.append(spendtx)
116+
cltv_invalidate(spendtx, i)
117+
invalid_cltv_txs.append(spendtx)
119118

120119
tip = self.nodes[0].getbestblockhash()
121120
block_time = self.nodes[0].getblockheader(tip)['mediantime'] + 1
122121
block = create_block(int(tip, 16), create_coinbase(CLTV_HEIGHT - 1), block_time)
123122
block.nVersion = 3
124-
block.vtx.extend(invalid_ctlv_txs)
123+
block.vtx.extend(invalid_cltv_txs)
125124
block.hashMerkleRoot = block.calc_merkle_root()
126125
block.solve()
127126

@@ -149,7 +148,7 @@ def run_test(self):
149148
# create and test one invalid tx per CLTV failure reason (5 in total)
150149
for i in range(5):
151150
spendtx = wallet.create_self_transfer(from_node=self.nodes[0])['tx']
152-
spendtx = cltv_invalidate(self.nodes[0], spendtx, i)
151+
cltv_invalidate(spendtx, i)
153152

154153
expected_cltv_reject_reason = [
155154
"non-mandatory-script-verify-flag (Operation not valid with the current stack size)",
@@ -182,7 +181,7 @@ def run_test(self):
182181
peer.sync_with_ping()
183182

184183
self.log.info("Test that a version 4 block with a valid-according-to-CLTV transaction is accepted")
185-
spendtx = cltv_validate(self.nodes[0], spendtx, CLTV_HEIGHT - 1)
184+
cltv_validate(spendtx, CLTV_HEIGHT - 1)
186185

187186
block.vtx.pop(1)
188187
block.vtx.append(spendtx)

0 commit comments

Comments
 (0)