From 0c2139a3f160d1d443460e4c5928109a6ab8cd11 Mon Sep 17 00:00:00 2001 From: Sebastian Falbesoner Date: Mon, 31 May 2021 19:18:04 +0200 Subject: [PATCH 1/3] test: fix typo in feature_cltv.py (s/ctlv/cltv/) --- test/functional/feature_cltv.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/functional/feature_cltv.py b/test/functional/feature_cltv.py index d25aaa070da..1f8e3e66459 100755 --- a/test/functional/feature_cltv.py +++ b/test/functional/feature_cltv.py @@ -111,17 +111,17 @@ class BIP65Test(BitcoinTestFramework): self.log.info("Test that invalid-according-to-CLTV transactions can still appear in a block") # create one invalid tx per CLTV failure reason (5 in total) and collect them - invalid_ctlv_txs = [] + invalid_cltv_txs = [] for i in range(5): spendtx = wallet.create_self_transfer(from_node=self.nodes[0])['tx'] spendtx = cltv_invalidate(self.nodes[0], spendtx, i) - invalid_ctlv_txs.append(spendtx) + invalid_cltv_txs.append(spendtx) tip = self.nodes[0].getbestblockhash() block_time = self.nodes[0].getblockheader(tip)['mediantime'] + 1 block = create_block(int(tip, 16), create_coinbase(CLTV_HEIGHT - 1), block_time) block.nVersion = 3 - block.vtx.extend(invalid_ctlv_txs) + block.vtx.extend(invalid_cltv_txs) block.hashMerkleRoot = block.calc_merkle_root() block.solve() From 9ab2ce0a6673acc7ee0f85158fc087fce0fc7dd8 Mon Sep 17 00:00:00 2001 From: Sebastian Falbesoner Date: Mon, 31 May 2021 19:29:05 +0200 Subject: [PATCH 2/3] test: drop unused node parameters in feature_cltv.py The following functions had a parameter "node" that is unsused and hence can be removed: - cltv_modify_tx() - cltv_invalidate() - cltv_validate() --- test/functional/feature_cltv.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/test/functional/feature_cltv.py b/test/functional/feature_cltv.py index 1f8e3e66459..b1adb37bc4f 100755 --- a/test/functional/feature_cltv.py +++ b/test/functional/feature_cltv.py @@ -37,7 +37,7 @@ CLTV_HEIGHT = 1351 # Helper function to modify a transaction by # 1) prepending a given script to the scriptSig of vin 0 and # 2) (optionally) modify the nSequence of vin 0 and the tx's nLockTime -def cltv_modify_tx(node, tx, prepend_scriptsig, nsequence=None, nlocktime=None): +def cltv_modify_tx(tx, prepend_scriptsig, nsequence=None, nlocktime=None): assert_equal(len(tx.vin), 1) if nsequence is not None: tx.vin[0].nSequence = nsequence @@ -48,7 +48,7 @@ def cltv_modify_tx(node, tx, prepend_scriptsig, nsequence=None, nlocktime=None): return tx -def cltv_invalidate(node, tx, failure_reason): +def cltv_invalidate(tx, failure_reason): # Modify the signature in vin 0 and nSequence/nLockTime of the tx to fail CLTV # # According to BIP65, OP_CHECKLOCKTIMEVERIFY can fail due the following reasons: @@ -69,14 +69,14 @@ def cltv_invalidate(node, tx, failure_reason): [[CScriptNum(500), OP_CHECKLOCKTIMEVERIFY, OP_DROP], 0xffffffff, 500], ][failure_reason] - return cltv_modify_tx(node, tx, prepend_scriptsig=scheme[0], nsequence=scheme[1], nlocktime=scheme[2]) + return cltv_modify_tx(tx, prepend_scriptsig=scheme[0], nsequence=scheme[1], nlocktime=scheme[2]) -def cltv_validate(node, tx, height): +def cltv_validate(tx, height): # Modify the signature in vin 0 and nSequence/nLockTime of the tx to pass CLTV scheme = [[CScriptNum(height), OP_CHECKLOCKTIMEVERIFY, OP_DROP], 0, height] - return cltv_modify_tx(node, tx, prepend_scriptsig=scheme[0], nsequence=scheme[1], nlocktime=scheme[2]) + return cltv_modify_tx(tx, prepend_scriptsig=scheme[0], nsequence=scheme[1], nlocktime=scheme[2]) class BIP65Test(BitcoinTestFramework): @@ -114,7 +114,7 @@ class BIP65Test(BitcoinTestFramework): invalid_cltv_txs = [] for i in range(5): spendtx = wallet.create_self_transfer(from_node=self.nodes[0])['tx'] - spendtx = cltv_invalidate(self.nodes[0], spendtx, i) + spendtx = cltv_invalidate(spendtx, i) invalid_cltv_txs.append(spendtx) tip = self.nodes[0].getbestblockhash() @@ -149,7 +149,7 @@ class BIP65Test(BitcoinTestFramework): # create and test one invalid tx per CLTV failure reason (5 in total) for i in range(5): spendtx = wallet.create_self_transfer(from_node=self.nodes[0])['tx'] - spendtx = cltv_invalidate(self.nodes[0], spendtx, i) + spendtx = cltv_invalidate(spendtx, i) expected_cltv_reject_reason = [ "non-mandatory-script-verify-flag (Operation not valid with the current stack size)", @@ -182,7 +182,7 @@ class BIP65Test(BitcoinTestFramework): peer.sync_with_ping() self.log.info("Test that a version 4 block with a valid-according-to-CLTV transaction is accepted") - spendtx = cltv_validate(self.nodes[0], spendtx, CLTV_HEIGHT - 1) + spendtx = cltv_validate(spendtx, CLTV_HEIGHT - 1) block.vtx.pop(1) block.vtx.append(spendtx) From 7e32fde912b3924fdb27ec1f658ac11fcf160b3e Mon Sep 17 00:00:00 2001 From: Sebastian Falbesoner Date: Mon, 31 May 2021 19:44:02 +0200 Subject: [PATCH 3/3] test: feature_cltv.py: don't return tx copies in modification functions The functions cltv_modify_tx(), cltv_invalidate() and cltv_validate() all modify the passed transaction in-place, i.e. there is no need to return a copy. --- test/functional/feature_cltv.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/test/functional/feature_cltv.py b/test/functional/feature_cltv.py index b1adb37bc4f..10d2072dba0 100755 --- a/test/functional/feature_cltv.py +++ b/test/functional/feature_cltv.py @@ -45,7 +45,6 @@ def cltv_modify_tx(tx, prepend_scriptsig, nsequence=None, nlocktime=None): tx.vin[0].scriptSig = CScript(prepend_scriptsig + list(CScript(tx.vin[0].scriptSig))) tx.rehash() - return tx def cltv_invalidate(tx, failure_reason): @@ -69,14 +68,14 @@ def cltv_invalidate(tx, failure_reason): [[CScriptNum(500), OP_CHECKLOCKTIMEVERIFY, OP_DROP], 0xffffffff, 500], ][failure_reason] - return cltv_modify_tx(tx, prepend_scriptsig=scheme[0], nsequence=scheme[1], nlocktime=scheme[2]) + cltv_modify_tx(tx, prepend_scriptsig=scheme[0], nsequence=scheme[1], nlocktime=scheme[2]) def cltv_validate(tx, height): # Modify the signature in vin 0 and nSequence/nLockTime of the tx to pass CLTV scheme = [[CScriptNum(height), OP_CHECKLOCKTIMEVERIFY, OP_DROP], 0, height] - return cltv_modify_tx(tx, prepend_scriptsig=scheme[0], nsequence=scheme[1], nlocktime=scheme[2]) + cltv_modify_tx(tx, prepend_scriptsig=scheme[0], nsequence=scheme[1], nlocktime=scheme[2]) class BIP65Test(BitcoinTestFramework): @@ -114,7 +113,7 @@ class BIP65Test(BitcoinTestFramework): invalid_cltv_txs = [] for i in range(5): spendtx = wallet.create_self_transfer(from_node=self.nodes[0])['tx'] - spendtx = cltv_invalidate(spendtx, i) + cltv_invalidate(spendtx, i) invalid_cltv_txs.append(spendtx) tip = self.nodes[0].getbestblockhash() @@ -149,7 +148,7 @@ class BIP65Test(BitcoinTestFramework): # create and test one invalid tx per CLTV failure reason (5 in total) for i in range(5): spendtx = wallet.create_self_transfer(from_node=self.nodes[0])['tx'] - spendtx = cltv_invalidate(spendtx, i) + cltv_invalidate(spendtx, i) expected_cltv_reject_reason = [ "non-mandatory-script-verify-flag (Operation not valid with the current stack size)", @@ -182,7 +181,7 @@ class BIP65Test(BitcoinTestFramework): peer.sync_with_ping() self.log.info("Test that a version 4 block with a valid-according-to-CLTV transaction is accepted") - spendtx = cltv_validate(spendtx, CLTV_HEIGHT - 1) + cltv_validate(spendtx, CLTV_HEIGHT - 1) block.vtx.pop(1) block.vtx.append(spendtx)