1010
1111from test_framework .blocktools import create_coinbase , create_block , create_transaction
1212from test_framework .messages import CTransaction , msg_block , ToHex
13- from test_framework .mininode import mininode_lock , P2PInterface
13+ from test_framework .mininode import P2PInterface
1414from test_framework .script import CScript , OP_1NEGATE , OP_CHECKLOCKTIMEVERIFY , OP_DROP , CScriptNum
1515from test_framework .test_framework import BitcoinTestFramework
16- from test_framework .util import assert_equal , bytes_to_hex_str , hex_str_to_bytes , wait_until
16+ from test_framework .util import (
17+ assert_equal ,
18+ bytes_to_hex_str ,
19+ hex_str_to_bytes ,
20+ )
1721
1822from io import BytesIO
1923
@@ -51,10 +55,11 @@ def cltv_validate(node, tx, height):
5155 list (CScript (new_tx .vin [0 ].scriptSig )))
5256 return new_tx
5357
58+
5459class BIP65Test (BitcoinTestFramework ):
5560 def set_test_params (self ):
5661 self .num_nodes = 1
57- self .extra_args = [['-whitelist=127.0.0.1' ]]
62+ self .extra_args = [['-whitelist=127.0.0.1' , '-par=1' ]] # Use only one script thread to get the exact reject reason for testing
5863 self .setup_clean_chain = True
5964
6065 def run_test (self ):
@@ -88,15 +93,11 @@ def run_test(self):
8893 block = create_block (tip , create_coinbase (CLTV_HEIGHT ), block_time )
8994 block .nVersion = 3
9095 block .solve ()
91- self .nodes [0 ].p2p .send_and_ping (msg_block (block ))
92- assert_equal (int (self .nodes [0 ].getbestblockhash (), 16 ), tip )
9396
94- wait_until (lambda : "reject" in self .nodes [0 ].p2p .last_message .keys (), lock = mininode_lock )
95- with mininode_lock :
96- assert_equal (self .nodes [0 ].p2p .last_message ["reject" ].code , REJECT_OBSOLETE )
97- assert_equal (self .nodes [0 ].p2p .last_message ["reject" ].reason , b'bad-version(0x00000003)' )
98- assert_equal (self .nodes [0 ].p2p .last_message ["reject" ].data , block .sha256 )
99- del self .nodes [0 ].p2p .last_message ["reject" ]
97+ with self .nodes [0 ].assert_debug_log (expected_msgs = ['{}, bad-version(0x00000003)' .format (block .hash )]):
98+ self .nodes [0 ].p2p .send_and_ping (msg_block (block ))
99+ assert_equal (int (self .nodes [0 ].getbestblockhash (), 16 ), tip )
100+ self .nodes [0 ].p2p .sync_with_ping ()
100101
101102 self .log .info ("Test that invalid-according-to-cltv transactions cannot appear in a block" )
102103 block .nVersion = 4
@@ -118,18 +119,10 @@ def run_test(self):
118119 block .hashMerkleRoot = block .calc_merkle_root ()
119120 block .solve ()
120121
121- self .nodes [0 ].p2p .send_and_ping (msg_block (block ))
122- assert_equal (int (self .nodes [0 ].getbestblockhash (), 16 ), tip )
123-
124- wait_until (lambda : "reject" in self .nodes [0 ].p2p .last_message .keys (), lock = mininode_lock )
125- with mininode_lock :
126- assert self .nodes [0 ].p2p .last_message ["reject" ].code in [REJECT_INVALID , REJECT_NONSTANDARD ]
127- assert_equal (self .nodes [0 ].p2p .last_message ["reject" ].data , block .sha256 )
128- if self .nodes [0 ].p2p .last_message ["reject" ].code == REJECT_INVALID :
129- # Generic rejection when a block is invalid
130- assert_equal (self .nodes [0 ].p2p .last_message ["reject" ].reason , b'block-validation-failed' )
131- else :
132- assert b'Negative locktime' in self .nodes [0 ].p2p .last_message ["reject" ].reason
122+ with self .nodes [0 ].assert_debug_log (expected_msgs = ['CheckInputs on {} failed with non-mandatory-script-verify-flag (Negative locktime)' .format (block .vtx [- 1 ].hash )]):
123+ self .nodes [0 ].p2p .send_and_ping (msg_block (block ))
124+ assert_equal (int (self .nodes [0 ].getbestblockhash (), 16 ), tip )
125+ self .nodes [0 ].p2p .sync_with_ping ()
133126
134127 self .log .info ("Test that a version 4 block with a valid-according-to-CLTV transaction is accepted" )
135128 spendtx = cltv_validate (self .nodes [0 ], spendtx , CLTV_HEIGHT - 1 )
0 commit comments