Skip to content

Commit b01cd94

Browse files
committed
test: check that _all_ invalid-CLTV txs are rejected after BIP65 activation
1 parent dbc1981 commit b01cd94

File tree

1 file changed

+37
-26
lines changed

1 file changed

+37
-26
lines changed

test/functional/feature_cltv.py

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -154,35 +154,46 @@ def run_test(self):
154154
assert_equal(int(self.nodes[0].getbestblockhash(), 16), tip)
155155
peer.sync_with_ping()
156156

157-
self.log.info("Test that invalid-according-to-cltv transactions cannot appear in a block")
157+
self.log.info("Test that invalid-according-to-CLTV transactions cannot appear in a block")
158158
block.nVersion = 4
159+
block.vtx.append(CTransaction()) # dummy tx after coinbase that will be replaced later
159160

160-
spendtx = create_transaction(self.nodes[0], self.coinbase_txids[10],
161-
self.nodeaddress, amount=1.0)
162-
spendtx = cltv_invalidate(self.nodes[0], spendtx, 1)
163-
spendtx.rehash()
164-
165-
# First we show that this tx is valid except for CLTV by getting it
166-
# rejected from the mempool for exactly that reason.
167-
assert_equal(
168-
[{
169-
'txid': spendtx.hash,
170-
'wtxid': spendtx.getwtxid(),
171-
'allowed': False,
172-
'reject-reason': 'non-mandatory-script-verify-flag (Negative locktime)',
173-
}],
174-
self.nodes[0].testmempoolaccept(rawtxs=[spendtx.serialize().hex()], maxfeerate=0),
175-
)
176-
177-
# Now we verify that a block with this transaction is also invalid.
178-
block.vtx.append(spendtx)
179-
block.hashMerkleRoot = block.calc_merkle_root()
180-
block.solve()
161+
# create and test one invalid tx per CLTV failure reason (5 in total)
162+
for i in range(5):
163+
spendtx = create_transaction(self.nodes[0], self.coinbase_txids[10+i],
164+
self.nodeaddress, amount=1.0)
165+
spendtx = cltv_invalidate(self.nodes[0], spendtx, i)
166+
spendtx.rehash()
181167

182-
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)]):
183-
peer.send_and_ping(msg_block(block))
184-
assert_equal(int(self.nodes[0].getbestblockhash(), 16), tip)
185-
peer.sync_with_ping()
168+
expected_cltv_reject_reason = [
169+
"non-mandatory-script-verify-flag (Operation not valid with the current stack size)",
170+
"non-mandatory-script-verify-flag (Negative locktime)",
171+
"non-mandatory-script-verify-flag (Locktime requirement not satisfied)",
172+
"non-mandatory-script-verify-flag (Locktime requirement not satisfied)",
173+
"non-mandatory-script-verify-flag (Locktime requirement not satisfied)",
174+
][i]
175+
# First we show that this tx is valid except for CLTV by getting it
176+
# rejected from the mempool for exactly that reason.
177+
assert_equal(
178+
[{
179+
'txid': spendtx.hash,
180+
'wtxid': spendtx.getwtxid(),
181+
'allowed': False,
182+
'reject-reason': expected_cltv_reject_reason,
183+
}],
184+
self.nodes[0].testmempoolaccept(rawtxs=[spendtx.serialize().hex()], maxfeerate=0),
185+
)
186+
187+
# Now we verify that a block with this transaction is also invalid.
188+
block.vtx[1] = spendtx
189+
block.hashMerkleRoot = block.calc_merkle_root()
190+
block.solve()
191+
192+
with self.nodes[0].assert_debug_log(expected_msgs=['CheckInputScripts on {} failed with {}'.format(
193+
block.vtx[-1].hash, expected_cltv_reject_reason)]):
194+
peer.send_and_ping(msg_block(block))
195+
assert_equal(int(self.nodes[0].getbestblockhash(), 16), tip)
196+
peer.sync_with_ping()
186197

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

0 commit comments

Comments
 (0)