Skip to content

Commit 25711c2

Browse files
committed
[tests] p2p_segwit: log and assert segwit status in subtest wrapper.
1 parent 6839863 commit 25711c2

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

test/functional/p2p_segwit.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ def run_test(self):
236236
# Keep a place to store utxo's that can be used in later tests
237237
self.utxo = []
238238

239-
self.log.info("Starting tests before segwit lock in:")
239+
self.segwit_status = 'defined'
240240

241241
self.test_non_witness_transaction()
242242
self.test_unnecessary_witness_before_segwit_activation()
@@ -251,7 +251,6 @@ def run_test(self):
251251
sync_blocks(self.nodes)
252252

253253
# At lockin, nothing should change.
254-
self.log.info("Testing behavior post lockin, pre-activation")
255254
self.advance_to_segwit_lockin()
256255

257256
# Retest unnecessary witnesses
@@ -263,7 +262,6 @@ def run_test(self):
263262
sync_blocks(self.nodes)
264263

265264
# Now activate segwit
266-
self.log.info("Testing behavior after segwit activation")
267265
self.advance_to_segwit_active()
268266

269267
sync_blocks(self.nodes)
@@ -296,10 +294,14 @@ def run_test(self):
296294
def subtest(func): # noqa: N805
297295
"""Wraps the subtests for logging and state assertions."""
298296
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)
300300
func(self, *args, **kwargs)
301301
# Each subtest should leave some utxos for the next subtest
302302
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)
303305

304306
return func_wrapper
305307

@@ -338,8 +340,6 @@ def test_non_witness_transaction(self):
338340
def test_unnecessary_witness_before_segwit_activation(self):
339341
"""Verify that blocks with witnesses are rejected before activation."""
340342

341-
assert(get_bip9_status(self.nodes[0], 'segwit')['status'] != 'active')
342-
343343
tx = CTransaction()
344344
tx.vin.append(CTxIn(COutPoint(self.utxo[0].sha256, self.utxo[0].n), b""))
345345
tx.vout.append(CTxOut(self.utxo[0].nValue - 1000, CScript([OP_TRUE])))
@@ -551,11 +551,10 @@ def advance_to_segwit_started(self):
551551
height = self.nodes[0].getblockcount()
552552
# Will need to rewrite the tests here if we are past the first period
553553
assert(height < VB_PERIOD - 1)
554-
# Genesis block is 'defined'.
555-
assert_equal(get_bip9_status(self.nodes[0], 'segwit')['status'], 'defined')
556554
# Advance to end of period, status should now be 'started'
557555
self.nodes[0].generate(VB_PERIOD - height - 1)
558556
assert_equal(get_bip9_status(self.nodes[0], 'segwit')['status'], 'started')
557+
self.segwit_status = 'started'
559558

560559
@subtest
561560
def test_getblocktemplate_before_lockin(self):
@@ -611,14 +610,14 @@ def advance_to_segwit_lockin(self):
611610
# signalling blocks, rather than just at the right period boundary.
612611

613612
height = self.nodes[0].getblockcount()
614-
assert_equal(get_bip9_status(self.nodes[0], 'segwit')['status'], 'started')
615613
# Advance to end of period, and verify lock-in happens at the end
616614
self.nodes[0].generate(VB_PERIOD - 1)
617615
height = self.nodes[0].getblockcount()
618616
assert((height % VB_PERIOD) == VB_PERIOD - 2)
619617
assert_equal(get_bip9_status(self.nodes[0], 'segwit')['status'], 'started')
620618
self.nodes[0].generate(1)
621619
assert_equal(get_bip9_status(self.nodes[0], 'segwit')['status'], 'locked_in')
620+
self.segwit_status = 'locked_in'
622621

623622
@subtest
624623
def test_witness_tx_relay_before_segwit_activation(self):
@@ -746,12 +745,12 @@ def advance_to_segwit_active(self):
746745
# TODO: we could verify that activation only happens at the right threshold
747746
# of signalling blocks, rather than just at the right period boundary.
748747

749-
assert_equal(get_bip9_status(self.nodes[0], 'segwit')['status'], 'locked_in')
750748
height = self.nodes[0].getblockcount()
751749
self.nodes[0].generate(VB_PERIOD - (height % VB_PERIOD) - 2)
752750
assert_equal(get_bip9_status(self.nodes[0], 'segwit')['status'], 'locked_in')
753751
self.nodes[0].generate(1)
754752
assert_equal(get_bip9_status(self.nodes[0], 'segwit')['status'], 'active')
753+
self.segwit_status = 'active'
755754

756755
@subtest
757756
def test_p2sh_witness(self, segwit_activated):

0 commit comments

Comments
 (0)