Skip to content

Commit 55e8050

Browse files
committed
[tests] p2p_segwit: remove unnecessary arguments from subtests.
1 parent 25711c2 commit 55e8050

File tree

1 file changed

+23
-28
lines changed

1 file changed

+23
-28
lines changed

test/functional/p2p_segwit.py

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ def run_test(self):
241241
self.test_non_witness_transaction()
242242
self.test_unnecessary_witness_before_segwit_activation()
243243
self.test_v0_outputs_arent_spendable()
244-
self.test_block_relay(segwit_activated=False)
244+
self.test_block_relay()
245245

246246
# Advance to segwit being 'started'
247247
self.advance_to_segwit_started()
@@ -256,8 +256,8 @@ def run_test(self):
256256
# Retest unnecessary witnesses
257257
self.test_unnecessary_witness_before_segwit_activation()
258258
self.test_witness_tx_relay_before_segwit_activation()
259-
self.test_block_relay(segwit_activated=False)
260-
self.test_standardness_v0(segwit_activated=False)
259+
self.test_block_relay()
260+
self.test_standardness_v0()
261261

262262
sync_blocks(self.nodes)
263263

@@ -267,7 +267,7 @@ def run_test(self):
267267
sync_blocks(self.nodes)
268268

269269
# Test P2SH witness handling again
270-
self.test_p2sh_witness(segwit_activated=True)
270+
self.test_p2sh_witness()
271271
self.test_witness_commitments()
272272
self.test_block_malleability()
273273
self.test_witness_block_size()
@@ -276,17 +276,17 @@ def run_test(self):
276276
self.test_max_witness_push_length()
277277
self.test_max_witness_program_length()
278278
self.test_witness_input_length()
279-
self.test_block_relay(segwit_activated=True)
279+
self.test_block_relay()
280280
self.test_tx_relay_after_segwit_activation()
281-
self.test_standardness_v0(segwit_activated=True)
281+
self.test_standardness_v0()
282282
self.test_segwit_versions()
283283
self.test_premature_coinbase_witness_spend()
284284
self.test_uncompressed_pubkey()
285285
self.test_signature_version_1()
286286
self.test_non_standard_witness_blinding()
287287
self.test_non_standard_witness()
288288
sync_blocks(self.nodes)
289-
self.test_upgrade_after_activation(node_id=2)
289+
self.test_upgrade_after_activation()
290290
self.test_witness_sigops()
291291

292292
# Individual tests
@@ -375,7 +375,7 @@ def test_unnecessary_witness_before_segwit_activation(self):
375375
self.utxo.append(UTXO(tx.sha256, 0, tx.vout[0].nValue))
376376

377377
@subtest
378-
def test_block_relay(self, segwit_activated):
378+
def test_block_relay(self):
379379
"""Test that block requests to NODE_WITNESS peer are with MSG_WITNESS_FLAG.
380380
381381
This is true regardless of segwit activation.
@@ -409,7 +409,7 @@ def test_block_relay(self, segwit_activated):
409409

410410
# Check that we can getdata for witness blocks or regular blocks,
411411
# and the right thing happens.
412-
if not segwit_activated:
412+
if self.segwit_status != 'active':
413413
# Before activation, we should be able to request old blocks with
414414
# or without witness, and they should be the same.
415415
chain_height = self.nodes[0].getblockcount()
@@ -662,7 +662,7 @@ def test_witness_tx_relay_before_segwit_activation(self):
662662
self.utxo.append(UTXO(tx_hash, 0, tx_value))
663663

664664
@subtest
665-
def test_standardness_v0(self, segwit_activated):
665+
def test_standardness_v0(self):
666666
"""Test V0 txout standardness.
667667
668668
V0 segwit outputs and inputs are always standard.
@@ -721,7 +721,7 @@ def test_standardness_v0(self, segwit_activated):
721721
tx3.wit.vtxinwit.append(CTxInWitness())
722722
tx3.wit.vtxinwit[0].scriptWitness.stack = [witness_program]
723723
tx3.rehash()
724-
if not segwit_activated:
724+
if self.segwit_status != 'active':
725725
# Just check mempool acceptance, but don't add the transaction to the mempool, since witness is disallowed
726726
# in blocks and the tx is impossible to mine right now.
727727
assert_equal(self.nodes[0].testmempoolaccept([bytes_to_hex_str(tx3.serialize_with_witness())]), [{'txid': tx3.hash, 'allowed': True}])
@@ -753,7 +753,7 @@ def advance_to_segwit_active(self):
753753
self.segwit_status = 'active'
754754

755755
@subtest
756-
def test_p2sh_witness(self, segwit_activated):
756+
def test_p2sh_witness(self):
757757
"""Test P2SH wrapped witness programs."""
758758

759759
# Prepare the p2sh-wrapped witness output
@@ -774,7 +774,7 @@ def test_p2sh_witness(self, segwit_activated):
774774
test_transaction_acceptance(self.nodes[0].rpc, self.test_node, tx, with_witness=False, accepted=True)
775775
block = self.build_next_block()
776776
self.update_witness_block_with_transactions(block, [tx])
777-
test_witness_block(self.nodes[0].rpc, self.test_node, block, accepted=True, with_witness=segwit_activated)
777+
test_witness_block(self.nodes[0].rpc, self.test_node, block, accepted=True, with_witness=True)
778778
sync_blocks(self.nodes)
779779

780780
# Now test attempts to spend the output.
@@ -803,18 +803,15 @@ def test_p2sh_witness(self, segwit_activated):
803803
spend_tx.wit.vtxinwit[0].scriptWitness.stack = [b'a', witness_program]
804804

805805
# Verify mempool acceptance
806-
test_transaction_acceptance(self.nodes[0].rpc, self.test_node, spend_tx, with_witness=True, accepted=segwit_activated)
806+
test_transaction_acceptance(self.nodes[0].rpc, self.test_node, spend_tx, with_witness=True, accepted=True)
807807
block = self.build_next_block()
808808
self.update_witness_block_with_transactions(block, [spend_tx])
809809

810810
# If we're after activation, then sending this with witnesses should be valid.
811811
# This no longer works before activation, because SCRIPT_VERIFY_WITNESS
812812
# is always set.
813813
# TODO: rewrite this test to make clear that it only works after activation.
814-
if segwit_activated:
815-
test_witness_block(self.nodes[0].rpc, self.test_node, block, accepted=True)
816-
else:
817-
test_witness_block(self.nodes[0].rpc, self.test_node, block, accepted=True, with_witness=False)
814+
test_witness_block(self.nodes[0].rpc, self.test_node, block, accepted=True)
818815

819816
# Update self.utxo
820817
self.utxo.pop(0)
@@ -1964,30 +1961,28 @@ def test_non_standard_witness(self):
19641961
self.utxo.pop(0)
19651962

19661963
@subtest
1967-
def test_upgrade_after_activation(self, node_id):
1964+
def test_upgrade_after_activation(self):
19681965
"""Test the behavior of starting up a segwit-aware node after the softfork has activated."""
19691966

1970-
assert(node_id != 0) # node0 is assumed to be a segwit-active bitcoind
1971-
19721967
# Make sure the nodes are all up
19731968
sync_blocks(self.nodes)
19741969

19751970
# Restart with the new binary
1976-
self.stop_node(node_id)
1977-
self.start_node(node_id, extra_args=["-vbparams=segwit:0:999999999999"])
1978-
connect_nodes(self.nodes[0], node_id)
1971+
self.stop_node(2)
1972+
self.start_node(2, extra_args=["-vbparams=segwit:0:999999999999"])
1973+
connect_nodes(self.nodes[0], 2)
19791974

19801975
sync_blocks(self.nodes)
19811976

19821977
# Make sure that this peer thinks segwit has activated.
1983-
assert(get_bip9_status(self.nodes[node_id], 'segwit')['status'] == "active")
1978+
assert(get_bip9_status(self.nodes[2], 'segwit')['status'] == "active")
19841979

19851980
# Make sure this peer's blocks match those of node0.
1986-
height = self.nodes[node_id].getblockcount()
1981+
height = self.nodes[2].getblockcount()
19871982
while height >= 0:
1988-
block_hash = self.nodes[node_id].getblockhash(height)
1983+
block_hash = self.nodes[2].getblockhash(height)
19891984
assert_equal(block_hash, self.nodes[0].getblockhash(height))
1990-
assert_equal(self.nodes[0].getblock(block_hash), self.nodes[node_id].getblock(block_hash))
1985+
assert_equal(self.nodes[0].getblock(block_hash), self.nodes[2].getblock(block_hash))
19911986
height -= 1
19921987

19931988
@subtest

0 commit comments

Comments
 (0)