7575 assert_equal ,
7676 bytes_to_hex_str ,
7777 connect_nodes ,
78+ disconnect_nodes ,
7879 get_bip9_status ,
7980 hex_str_to_bytes ,
8081 sync_blocks ,
@@ -236,37 +237,30 @@ def run_test(self):
236237 # Keep a place to store utxo's that can be used in later tests
237238 self .utxo = []
238239
240+ # Segwit status 'defined'
239241 self .segwit_status = 'defined'
240242
241243 self .test_non_witness_transaction ()
242244 self .test_unnecessary_witness_before_segwit_activation ()
243245 self .test_v0_outputs_arent_spendable ()
244246 self .test_block_relay ()
245-
246- # Advance to segwit being 'started'
247247 self .advance_to_segwit_started ()
248- sync_blocks (self .nodes )
249- self .test_getblocktemplate_before_lockin ()
250248
251- sync_blocks ( self . nodes )
249+ # Segwit status 'started'
252250
253- # At lockin, nothing should change.
251+ self . test_getblocktemplate_before_lockin ()
254252 self .advance_to_segwit_lockin ()
255253
256- # Retest unnecessary witnesses
254+ # Segwit status 'locked_in'
255+
257256 self .test_unnecessary_witness_before_segwit_activation ()
258257 self .test_witness_tx_relay_before_segwit_activation ()
259258 self .test_block_relay ()
260259 self .test_standardness_v0 ()
261-
262- sync_blocks (self .nodes )
263-
264- # Now activate segwit
265260 self .advance_to_segwit_active ()
266261
267- sync_blocks ( self . nodes )
262+ # Segwit status 'active'
268263
269- # Test P2SH witness handling again
270264 self .test_p2sh_witness ()
271265 self .test_witness_commitments ()
272266 self .test_block_malleability ()
@@ -285,7 +279,6 @@ def run_test(self):
285279 self .test_signature_version_1 ()
286280 self .test_non_standard_witness_blinding ()
287281 self .test_non_standard_witness ()
288- sync_blocks (self .nodes )
289282 self .test_upgrade_after_activation ()
290283 self .test_witness_sigops ()
291284
@@ -300,6 +293,7 @@ def func_wrapper(self, *args, **kwargs):
300293 func (self , * args , ** kwargs )
301294 # Each subtest should leave some utxos for the next subtest
302295 assert self .utxo
296+ sync_blocks (self .nodes )
303297 # Assert segwit status is as expected at end of subtest
304298 assert_equal (get_bip9_status (self .nodes [0 ], 'segwit' )['status' ], self .segwit_status )
305299
@@ -368,8 +362,6 @@ def test_unnecessary_witness_before_segwit_activation(self):
368362 self .test_node .sync_with_ping ()
369363 assert_equal (self .nodes [0 ].getbestblockhash (), block .hash )
370364
371- sync_blocks (self .nodes )
372-
373365 # Update our utxo list; we spent the first entry.
374366 self .utxo .pop (0 )
375367 self .utxo .append (UTXO (tx .sha256 , 0 , tx .vout [0 ].nValue ))
@@ -482,6 +474,11 @@ def test_v0_outputs_arent_spendable(self):
482474 witness, and so can't be spent before segwit activation (the point at which
483475 blocks are permitted to contain witnesses)."""
484476
477+ # node2 doesn't need to be connected for this test.
478+ # (If it's connected, node0 may propogate an invalid block to it over
479+ # compact blocks and the nodes would have inconsistent tips.)
480+ disconnect_nodes (self .nodes [0 ], 2 )
481+
485482 # Create two outputs, a p2wsh and p2sh-p2wsh
486483 witness_program = CScript ([OP_TRUE ])
487484 witness_hash = sha256 (witness_program )
@@ -542,6 +539,8 @@ def test_v0_outputs_arent_spendable(self):
542539 # TODO: support multiple acceptable reject reasons.
543540 test_witness_block (self .nodes [0 ], self .test_node , block , accepted = False , with_witness = False )
544541
542+ connect_nodes (self .nodes [0 ], 2 )
543+
545544 self .utxo .pop (0 )
546545 self .utxo .append (UTXO (txid , 2 , value ))
547546
@@ -1964,9 +1963,6 @@ def test_non_standard_witness(self):
19641963 def test_upgrade_after_activation (self ):
19651964 """Test the behavior of starting up a segwit-aware node after the softfork has activated."""
19661965
1967- # Make sure the nodes are all up
1968- sync_blocks (self .nodes )
1969-
19701966 # Restart with the new binary
19711967 self .stop_node (2 )
19721968 self .start_node (2 , extra_args = ["-vbparams=segwit:0:999999999999" ])
0 commit comments