Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge bitcoin/bitcoin#19801: test: check for all possible OP_CLTV fai…
…l reasons in feature_cltv.py (BIP 65) b01cd94 test: check that _all_ invalid-CLTV txs are rejected after BIP65 activation (Sebastian Falbesoner) dbc1981 test: check that _all_ invalid-CLTV txs are allowed in a block pre-BIP65 (Sebastian Falbesoner) 8d0ce50 test: prepare cltv_invalidate to test all failure reasons in feature_cltv.py (Sebastian Falbesoner) ce994e1 test: add tx modfication helper function in feature_cltv.py (Sebastian Falbesoner) Pull request description: The functional test for [BIP65](https://github.com/bitcoin/bips/blob/master/bip-0065.mediawiki) / `OP_CHECKLOCKTIMEVERIFY` (`feature_cltv.py`) currently only tests one out of five conditions that lead to failure of the op-code -- by prepending the script `OP_1NEGATE OP_CHECKLOCKTIMEVERIFY OP_DROP` to a tx's first input's scriptSig, the case of "_the top item on the stack is less than 0_" is checked: https://github.com/bitcoin/bitcoin/blob/f8462a6d2794be728cf8550f45d19a354aae59cf/test/functional/feature_cltv.py#L26-L35 This PR adds the other cases (5 in total) by taking an integer argument to the function `cltv_invalidate` that is called in a loop instead of only once per testing scenario. Here is the full list of failure conditions and how they are tested (note that the scriptSig should still be valid before activation of BIP65, when `OP_CLTV` is simply a no-op): * _the stack is empty_ ➡️ prepending `OP_CHECKLOCKTIMEVERIFY` to scriptSig * _the top item on the stack is less than 0_ ➡️ prepending `OP_1NEGATE OP_CHECKLOCKTIMEVERIFY OP_DROP` to scriptSig * _the lock-time type (height vs. timestamp) of the top stack item and the nLockTime field are not the same_ ➡️ prepending `OPNum(1000) OP_CHECKLOCKTIMEVERIFY OP_DROP` to scriptSig ➡️ setting tx.vin[0].nSequence=0 and tx.nCheckTimeLock=1296688602 (genesis block timestamp) * _the top stack item is greater than the transaction's nLockTime field_ ➡️ prepending `OPNum(1000) OP_CHECKLOCKTIMEVERIFY OP_DROP` to scriptSig ➡️ setting tx.vin[0].nSequence=0 and tx.nCheckTimeLock=500 * _the nSequence field of the txin is 0xffffffff_ ➡️ prepending `OPNum(500) OP_CHECKLOCKTIMEVERIFY OP_DROP` to scriptSig ➡️ setting tx.vin[0].nSequence=0xffffffff and tx.nCheckTimeLock=500 The first commit creates a helper function for the tx modification and also includes some tidying up like turning single-line to multi-line Python imports where necessary and cleaning up some PEP8 warnings. The second commit prepares the invalidation function `cltv_invalidate` and the third and the fourth use it and check for the expected reject reason strings ("Operation not valid with the current stack size", "Negative locktime" and "Locktime requirement not satisfied"). ACKs for top commit: MarcoFalke: review ACK b01cd94 🐣 Tree-SHA512: dd82ae86e2bc4f3ab9bb1cfc9f04e4431b2b59c8aaf2a9f4b28654a1577e003fb43c500f99d76ff57e96262168e1cad7c1a0d71158e4b01063737e8f4be1e07d
- Loading branch information