@@ -228,16 +228,17 @@ def run_test(self):
228
228
# self.std_node is for testing node1 (fRequireStandard=true)
229
229
self .std_node = self .nodes [1 ].add_p2p_connection (TestP2PConn (), services = NODE_NETWORK | NODE_WITNESS )
230
230
231
+ for conn in (self .test_node , self .old_node , self .std_node ):
232
+ conn .wait_for_verack ()
233
+
234
+ assert self .test_node .nServices & NODE_WITNESS != 0
235
+
231
236
# Keep a place to store utxo's that can be used in later tests
232
237
self .utxo = []
233
238
234
- # Test logic begins here
235
- self .test_node .wait_for_verack ()
236
-
237
239
self .log .info ("Starting tests before segwit lock in:" )
238
240
239
- self .test_witness_services () # Verifies NODE_WITNESS
240
- self .test_non_witness_transaction () # non-witness tx's are accepted
241
+ self .test_non_witness_transaction ()
241
242
self .test_unnecessary_witness_before_segwit_activation ()
242
243
self .test_v0_outputs_arent_spendable ()
243
244
self .test_block_relay (segwit_activated = False )
@@ -297,13 +298,11 @@ def subtest(func): # noqa: N805
297
298
def func_wrapper (self , * args , ** kwargs ):
298
299
self .log .info ("Subtest: {}" .format (func .__name__ ))
299
300
func (self , * args , ** kwargs )
301
+ # Each subtest should leave some utxos for the next subtest
302
+ assert self .utxo
300
303
301
304
return func_wrapper
302
305
303
- def test_witness_services (self ):
304
- self .log .info ("Verifying NODE_WITNESS service bit" )
305
- assert ((self .test_node .nServices & NODE_WITNESS ) != 0 )
306
-
307
306
@subtest
308
307
def test_non_witness_transaction (self ):
309
308
"""See if sending a regular transaction works, and create a utxo to use in later tests."""
@@ -339,9 +338,6 @@ def test_non_witness_transaction(self):
339
338
def test_unnecessary_witness_before_segwit_activation (self ):
340
339
"""Verify that blocks with witnesses are rejected before activation."""
341
340
342
- # For now, rely on earlier tests to have created at least one utxo for
343
- # us to use
344
- assert (len (self .utxo ) > 0 )
345
341
assert (get_bip9_status (self .nodes [0 ], 'segwit' )['status' ] != 'active' )
346
342
347
343
tx = CTransaction ()
@@ -486,8 +482,6 @@ def test_v0_outputs_arent_spendable(self):
486
482
witness, and so can't be spent before segwit activation (the point at which
487
483
blocks are permitted to contain witnesses)."""
488
484
489
- assert len (self .utxo ), "self.utxo is empty"
490
-
491
485
# Create two outputs, a p2wsh and p2sh-p2wsh
492
486
witness_program = CScript ([OP_TRUE ])
493
487
witness_hash = sha256 (witness_program )
@@ -632,7 +626,6 @@ def test_witness_tx_relay_before_segwit_activation(self):
632
626
# Generate a transaction that doesn't require a witness, but send it
633
627
# with a witness. Should be rejected for premature-witness, but should
634
628
# not be added to recently rejected list.
635
- assert (len (self .utxo ))
636
629
tx = CTransaction ()
637
630
tx .vin .append (CTxIn (COutPoint (self .utxo [0 ].sha256 , self .utxo [0 ].n ), b"" ))
638
631
tx .vout .append (CTxOut (self .utxo [0 ].nValue - 1000 , CScript ([OP_TRUE , OP_DROP ] * 15 + [OP_TRUE ])))
@@ -676,8 +669,6 @@ def test_standardness_v0(self, segwit_activated):
676
669
V0 segwit outputs and inputs are always standard.
677
670
V0 segwit inputs may only be mined after activation, but not before."""
678
671
679
- assert (len (self .utxo ))
680
-
681
672
witness_program = CScript ([OP_TRUE ])
682
673
witness_hash = sha256 (witness_program )
683
674
script_pubkey = CScript ([OP_0 , witness_hash ])
@@ -766,8 +757,6 @@ def advance_to_segwit_active(self):
766
757
def test_p2sh_witness (self , segwit_activated ):
767
758
"""Test P2SH wrapped witness programs."""
768
759
769
- assert (len (self .utxo ))
770
-
771
760
# Prepare the p2sh-wrapped witness output
772
761
witness_program = CScript ([OP_DROP , OP_TRUE ])
773
762
witness_hash = sha256 (witness_program )
@@ -861,7 +850,6 @@ def test_witness_commitments(self):
861
850
test_witness_block (self .nodes [0 ].rpc , self .test_node , block_2 , accepted = True )
862
851
863
852
# Now test commitments with actual transactions
864
- assert (len (self .utxo ) > 0 )
865
853
tx = CTransaction ()
866
854
tx .vin .append (CTxIn (COutPoint (self .utxo [0 ].sha256 , self .utxo [0 ].n ), b"" ))
867
855
@@ -1081,8 +1069,6 @@ def test_submit_block(self):
1081
1069
def test_extra_witness_data (self ):
1082
1070
"""Test extra witness data in a transaction."""
1083
1071
1084
- assert (len (self .utxo ) > 0 )
1085
-
1086
1072
block = self .build_next_block ()
1087
1073
1088
1074
witness_program = CScript ([OP_DROP , OP_TRUE ])
@@ -1157,7 +1143,6 @@ def test_max_witness_push_length(self):
1157
1143
"""Test that witness stack can only allow up to 520 byte pushes."""
1158
1144
1159
1145
MAX_SCRIPT_ELEMENT_SIZE = 520
1160
- assert (len (self .utxo ))
1161
1146
1162
1147
block = self .build_next_block ()
1163
1148
@@ -1196,7 +1181,6 @@ def test_max_witness_push_length(self):
1196
1181
def test_max_witness_program_length (self ):
1197
1182
"""Test that witness outputs greater than 10kB can't be spent."""
1198
1183
1199
- assert (len (self .utxo ))
1200
1184
MAX_PROGRAM_LENGTH = 10000
1201
1185
1202
1186
# This program is 19 max pushes (9937 bytes), then 64 more opcode-bytes.
@@ -1245,8 +1229,6 @@ def test_max_witness_program_length(self):
1245
1229
def test_witness_input_length (self ):
1246
1230
"""Test that vin length must match vtxinwit length."""
1247
1231
1248
- assert (len (self .utxo ))
1249
-
1250
1232
witness_program = CScript ([OP_DROP , OP_TRUE ])
1251
1233
witness_hash = sha256 (witness_program )
1252
1234
script_pubkey = CScript ([OP_0 , witness_hash ])
@@ -1337,7 +1319,6 @@ def test_tx_relay_after_segwit_activation(self):
1337
1319
# Generate a transaction that doesn't require a witness, but send it
1338
1320
# with a witness. Should be rejected because we can't use a witness
1339
1321
# when spending a non-witness output.
1340
- assert (len (self .utxo ))
1341
1322
tx = CTransaction ()
1342
1323
tx .vin .append (CTxIn (COutPoint (self .utxo [0 ].sha256 , self .utxo [0 ].n ), b"" ))
1343
1324
tx .vout .append (CTxOut (self .utxo [0 ].nValue - 1000 , CScript ([OP_TRUE , OP_DROP ] * 15 + [OP_TRUE ])))
@@ -1426,7 +1407,6 @@ def test_segwit_versions(self):
1426
1407
Future segwit version transactions are non-standard, but valid in blocks.
1427
1408
Can run this before and after segwit activation."""
1428
1409
1429
- assert (len (self .utxo ))
1430
1410
num_tests = 17 # will test OP_0, OP1, ..., OP_16
1431
1411
if (len (self .utxo ) < num_tests ):
1432
1412
tx = CTransaction ()
@@ -1557,7 +1537,6 @@ def test_uncompressed_pubkey(self):
1557
1537
pubkey = CPubKey (key .get_pubkey ())
1558
1538
assert_equal (len (pubkey ), 65 ) # This should be an uncompressed pubkey
1559
1539
1560
- assert (len (self .utxo ) > 0 )
1561
1540
utxo = self .utxo .pop (0 )
1562
1541
1563
1542
# Test 1: P2WPKH
@@ -1661,7 +1640,6 @@ def test_signature_version_1(self):
1661
1640
script_pubkey = CScript ([OP_0 , witness_hash ])
1662
1641
1663
1642
# First create a witness output for use in the tests.
1664
- assert (len (self .utxo ))
1665
1643
tx = CTransaction ()
1666
1644
tx .vin .append (CTxIn (COutPoint (self .utxo [0 ].sha256 , self .utxo [0 ].n ), b"" ))
1667
1645
tx .vout .append (CTxOut (self .utxo [0 ].nValue - 1000 , script_pubkey ))
@@ -1835,7 +1813,6 @@ def test_signature_version_1(self):
1835
1813
@subtest
1836
1814
def test_non_standard_witness_blinding (self ):
1837
1815
"""Test behavior of unnecessary witnesses in transactions does not blind the node for the transaction"""
1838
- assert (len (self .utxo ) > 0 )
1839
1816
1840
1817
# Create a p2sh output -- this is so we can pass the standardness
1841
1818
# rules (an anyone-can-spend OP_TRUE would be rejected, if not wrapped
@@ -1901,7 +1878,6 @@ def test_non_standard_witness(self):
1901
1878
1902
1879
p2wsh_scripts = []
1903
1880
1904
- assert (len (self .utxo ))
1905
1881
tx = CTransaction ()
1906
1882
tx .vin .append (CTxIn (COutPoint (self .utxo [0 ].sha256 , self .utxo [0 ].n ), b"" ))
1907
1883
@@ -2019,8 +1995,6 @@ def test_upgrade_after_activation(self, node_id):
2019
1995
def test_witness_sigops (self ):
2020
1996
"""Test sigop counting is correct inside witnesses."""
2021
1997
2022
- assert (len (self .utxo ))
2023
-
2024
1998
# Keep this under MAX_OPS_PER_SCRIPT (201)
2025
1999
witness_program = CScript ([OP_TRUE , OP_IF , OP_TRUE , OP_ELSE ] + [OP_CHECKMULTISIG ] * 5 + [OP_CHECKSIG ] * 193 + [OP_ENDIF ])
2026
2000
witness_hash = sha256 (witness_program )
0 commit comments