@@ -236,7 +236,7 @@ def run_test(self):
236
236
# Keep a place to store utxo's that can be used in later tests
237
237
self .utxo = []
238
238
239
- self .log . info ( "Starting tests before segwit lock in:" )
239
+ self .segwit_status = 'defined'
240
240
241
241
self .test_non_witness_transaction ()
242
242
self .test_unnecessary_witness_before_segwit_activation ()
@@ -251,7 +251,6 @@ def run_test(self):
251
251
sync_blocks (self .nodes )
252
252
253
253
# At lockin, nothing should change.
254
- self .log .info ("Testing behavior post lockin, pre-activation" )
255
254
self .advance_to_segwit_lockin ()
256
255
257
256
# Retest unnecessary witnesses
@@ -263,7 +262,6 @@ def run_test(self):
263
262
sync_blocks (self .nodes )
264
263
265
264
# Now activate segwit
266
- self .log .info ("Testing behavior after segwit activation" )
267
265
self .advance_to_segwit_active ()
268
266
269
267
sync_blocks (self .nodes )
@@ -296,10 +294,14 @@ def run_test(self):
296
294
def subtest (func ): # noqa: N805
297
295
"""Wraps the subtests for logging and state assertions."""
298
296
def func_wrapper (self , * args , ** kwargs ):
299
- self .log .info ("Subtest: {}" .format (func .__name__ ))
297
+ self .log .info ("Subtest: {} (Segwit status = {})" .format (func .__name__ , self .segwit_status ))
298
+ # Assert segwit status is as expected
299
+ assert_equal (get_bip9_status (self .nodes [0 ], 'segwit' )['status' ], self .segwit_status )
300
300
func (self , * args , ** kwargs )
301
301
# Each subtest should leave some utxos for the next subtest
302
302
assert self .utxo
303
+ # Assert segwit status is as expected at end of subtest
304
+ assert_equal (get_bip9_status (self .nodes [0 ], 'segwit' )['status' ], self .segwit_status )
303
305
304
306
return func_wrapper
305
307
@@ -338,8 +340,6 @@ def test_non_witness_transaction(self):
338
340
def test_unnecessary_witness_before_segwit_activation (self ):
339
341
"""Verify that blocks with witnesses are rejected before activation."""
340
342
341
- assert (get_bip9_status (self .nodes [0 ], 'segwit' )['status' ] != 'active' )
342
-
343
343
tx = CTransaction ()
344
344
tx .vin .append (CTxIn (COutPoint (self .utxo [0 ].sha256 , self .utxo [0 ].n ), b"" ))
345
345
tx .vout .append (CTxOut (self .utxo [0 ].nValue - 1000 , CScript ([OP_TRUE ])))
@@ -551,11 +551,10 @@ def advance_to_segwit_started(self):
551
551
height = self .nodes [0 ].getblockcount ()
552
552
# Will need to rewrite the tests here if we are past the first period
553
553
assert (height < VB_PERIOD - 1 )
554
- # Genesis block is 'defined'.
555
- assert_equal (get_bip9_status (self .nodes [0 ], 'segwit' )['status' ], 'defined' )
556
554
# Advance to end of period, status should now be 'started'
557
555
self .nodes [0 ].generate (VB_PERIOD - height - 1 )
558
556
assert_equal (get_bip9_status (self .nodes [0 ], 'segwit' )['status' ], 'started' )
557
+ self .segwit_status = 'started'
559
558
560
559
@subtest
561
560
def test_getblocktemplate_before_lockin (self ):
@@ -611,14 +610,14 @@ def advance_to_segwit_lockin(self):
611
610
# signalling blocks, rather than just at the right period boundary.
612
611
613
612
height = self .nodes [0 ].getblockcount ()
614
- assert_equal (get_bip9_status (self .nodes [0 ], 'segwit' )['status' ], 'started' )
615
613
# Advance to end of period, and verify lock-in happens at the end
616
614
self .nodes [0 ].generate (VB_PERIOD - 1 )
617
615
height = self .nodes [0 ].getblockcount ()
618
616
assert ((height % VB_PERIOD ) == VB_PERIOD - 2 )
619
617
assert_equal (get_bip9_status (self .nodes [0 ], 'segwit' )['status' ], 'started' )
620
618
self .nodes [0 ].generate (1 )
621
619
assert_equal (get_bip9_status (self .nodes [0 ], 'segwit' )['status' ], 'locked_in' )
620
+ self .segwit_status = 'locked_in'
622
621
623
622
@subtest
624
623
def test_witness_tx_relay_before_segwit_activation (self ):
@@ -746,12 +745,12 @@ def advance_to_segwit_active(self):
746
745
# TODO: we could verify that activation only happens at the right threshold
747
746
# of signalling blocks, rather than just at the right period boundary.
748
747
749
- assert_equal (get_bip9_status (self .nodes [0 ], 'segwit' )['status' ], 'locked_in' )
750
748
height = self .nodes [0 ].getblockcount ()
751
749
self .nodes [0 ].generate (VB_PERIOD - (height % VB_PERIOD ) - 2 )
752
750
assert_equal (get_bip9_status (self .nodes [0 ], 'segwit' )['status' ], 'locked_in' )
753
751
self .nodes [0 ].generate (1 )
754
752
assert_equal (get_bip9_status (self .nodes [0 ], 'segwit' )['status' ], 'active' )
753
+ self .segwit_status = 'active'
755
754
756
755
@subtest
757
756
def test_p2sh_witness (self , segwit_activated ):
0 commit comments