mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-10 10:52:31 -05:00
test: check that _all_ invalid-CLTV txs are rejected after BIP65 activation
This commit is contained in:
parent
dbc1981474
commit
b01cd9471f
1 changed files with 35 additions and 24 deletions
|
@ -154,14 +154,24 @@ class BIP65Test(BitcoinTestFramework):
|
||||||
assert_equal(int(self.nodes[0].getbestblockhash(), 16), tip)
|
assert_equal(int(self.nodes[0].getbestblockhash(), 16), tip)
|
||||||
peer.sync_with_ping()
|
peer.sync_with_ping()
|
||||||
|
|
||||||
self.log.info("Test that invalid-according-to-cltv transactions cannot appear in a block")
|
self.log.info("Test that invalid-according-to-CLTV transactions cannot appear in a block")
|
||||||
block.nVersion = 4
|
block.nVersion = 4
|
||||||
|
block.vtx.append(CTransaction()) # dummy tx after coinbase that will be replaced later
|
||||||
|
|
||||||
spendtx = create_transaction(self.nodes[0], self.coinbase_txids[10],
|
# create and test one invalid tx per CLTV failure reason (5 in total)
|
||||||
|
for i in range(5):
|
||||||
|
spendtx = create_transaction(self.nodes[0], self.coinbase_txids[10+i],
|
||||||
self.nodeaddress, amount=1.0)
|
self.nodeaddress, amount=1.0)
|
||||||
spendtx = cltv_invalidate(self.nodes[0], spendtx, 1)
|
spendtx = cltv_invalidate(self.nodes[0], spendtx, i)
|
||||||
spendtx.rehash()
|
spendtx.rehash()
|
||||||
|
|
||||||
|
expected_cltv_reject_reason = [
|
||||||
|
"non-mandatory-script-verify-flag (Operation not valid with the current stack size)",
|
||||||
|
"non-mandatory-script-verify-flag (Negative locktime)",
|
||||||
|
"non-mandatory-script-verify-flag (Locktime requirement not satisfied)",
|
||||||
|
"non-mandatory-script-verify-flag (Locktime requirement not satisfied)",
|
||||||
|
"non-mandatory-script-verify-flag (Locktime requirement not satisfied)",
|
||||||
|
][i]
|
||||||
# First we show that this tx is valid except for CLTV by getting it
|
# First we show that this tx is valid except for CLTV by getting it
|
||||||
# rejected from the mempool for exactly that reason.
|
# rejected from the mempool for exactly that reason.
|
||||||
assert_equal(
|
assert_equal(
|
||||||
|
@ -169,17 +179,18 @@ class BIP65Test(BitcoinTestFramework):
|
||||||
'txid': spendtx.hash,
|
'txid': spendtx.hash,
|
||||||
'wtxid': spendtx.getwtxid(),
|
'wtxid': spendtx.getwtxid(),
|
||||||
'allowed': False,
|
'allowed': False,
|
||||||
'reject-reason': 'non-mandatory-script-verify-flag (Negative locktime)',
|
'reject-reason': expected_cltv_reject_reason,
|
||||||
}],
|
}],
|
||||||
self.nodes[0].testmempoolaccept(rawtxs=[spendtx.serialize().hex()], maxfeerate=0),
|
self.nodes[0].testmempoolaccept(rawtxs=[spendtx.serialize().hex()], maxfeerate=0),
|
||||||
)
|
)
|
||||||
|
|
||||||
# Now we verify that a block with this transaction is also invalid.
|
# Now we verify that a block with this transaction is also invalid.
|
||||||
block.vtx.append(spendtx)
|
block.vtx[1] = spendtx
|
||||||
block.hashMerkleRoot = block.calc_merkle_root()
|
block.hashMerkleRoot = block.calc_merkle_root()
|
||||||
block.solve()
|
block.solve()
|
||||||
|
|
||||||
with self.nodes[0].assert_debug_log(expected_msgs=['CheckInputScripts on {} failed with non-mandatory-script-verify-flag (Negative locktime)'.format(block.vtx[-1].hash)]):
|
with self.nodes[0].assert_debug_log(expected_msgs=['CheckInputScripts on {} failed with {}'.format(
|
||||||
|
block.vtx[-1].hash, expected_cltv_reject_reason)]):
|
||||||
peer.send_and_ping(msg_block(block))
|
peer.send_and_ping(msg_block(block))
|
||||||
assert_equal(int(self.nodes[0].getbestblockhash(), 16), tip)
|
assert_equal(int(self.nodes[0].getbestblockhash(), 16), tip)
|
||||||
peer.sync_with_ping()
|
peer.sync_with_ping()
|
||||||
|
|
Loading…
Add table
Reference in a new issue