mirror of
https://github.com/bitcoin/bitcoin.git
synced 2024-11-20 10:38:42 +01:00
Merge bitcoin/bitcoin#22113: test: minor cleanups in feature_cltv.py
7e32fde912
test: feature_cltv.py: don't return tx copies in modification functions (Sebastian Falbesoner)9ab2ce0a66
test: drop unused node parameters in feature_cltv.py (Sebastian Falbesoner)0c2139a3f1
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 ACK7e32fde912
📼 Tree-SHA512: d2e6230977442f6a511d0f7c99431a44ad3a423647f4f327ce2ce8efe78bf9616c0d2093f5e3c3550f690dcb3f625ddf53227505c01ced70227425f249c25364
This commit is contained in:
commit
0b9ed3f6e7
@ -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
|
||||
@ -45,10 +45,9 @@ def cltv_modify_tx(node, 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(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 +68,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])
|
||||
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])
|
||||
cltv_modify_tx(tx, prepend_scriptsig=scheme[0], nsequence=scheme[1], nlocktime=scheme[2])
|
||||
|
||||
|
||||
class BIP65Test(BitcoinTestFramework):
|
||||
@ -111,17 +110,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)
|
||||
cltv_invalidate(spendtx, i)
|
||||
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()
|
||||
|
||||
@ -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(self.nodes[0], 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(self.nodes[0], spendtx, CLTV_HEIGHT - 1)
|
||||
cltv_validate(spendtx, CLTV_HEIGHT - 1)
|
||||
|
||||
block.vtx.pop(1)
|
||||
block.vtx.append(spendtx)
|
||||
|
Loading…
Reference in New Issue
Block a user