@@ -101,6 +101,23 @@ def __init__(self, sha256, n, value):
101
101
self .n = n
102
102
self .nValue = value
103
103
104
+
105
+ def subtest (func ):
106
+ """Wraps the subtests for logging and state assertions."""
107
+ def func_wrapper (self , * args , ** kwargs ):
108
+ self .log .info ("Subtest: {} (Segwit active = {})" .format (func .__name__ , self .segwit_active ))
109
+ # Assert segwit status is as expected
110
+ assert_equal (softfork_active (self .nodes [0 ], 'segwit' ), self .segwit_active )
111
+ func (self , * args , ** kwargs )
112
+ # Each subtest should leave some utxos for the next subtest
113
+ assert self .utxo
114
+ self .sync_blocks ()
115
+ # Assert segwit status is as expected at end of subtest
116
+ assert_equal (softfork_active (self .nodes [0 ], 'segwit' ), self .segwit_active )
117
+
118
+ return func_wrapper
119
+
120
+
104
121
def sign_p2pk_witness_input (script , tx_to , in_idx , hashtype , value , key ):
105
122
"""Add signature for a P2PK witness script."""
106
123
tx_hash = SegwitV0SignatureHash (script , tx_to , in_idx , hashtype , value )
@@ -280,22 +297,7 @@ def run_test(self):
280
297
281
298
# Individual tests
282
299
283
- def subtest (func ): # noqa: N805
284
- """Wraps the subtests for logging and state assertions."""
285
- def func_wrapper (self , * args , ** kwargs ):
286
- self .log .info ("Subtest: {} (Segwit active = {})" .format (func .__name__ , self .segwit_active ))
287
- # Assert segwit status is as expected
288
- assert_equal (softfork_active (self .nodes [0 ], 'segwit' ), self .segwit_active )
289
- func (self , * args , ** kwargs )
290
- # Each subtest should leave some utxos for the next subtest
291
- assert self .utxo
292
- self .sync_blocks ()
293
- # Assert segwit status is as expected at end of subtest
294
- assert_equal (softfork_active (self .nodes [0 ], 'segwit' ), self .segwit_active )
295
-
296
- return func_wrapper
297
-
298
- @subtest # type: ignore
300
+ @subtest
299
301
def test_non_witness_transaction (self ):
300
302
"""See if sending a regular transaction works, and create a utxo to use in later tests."""
301
303
# Mine a block with an anyone-can-spend coinbase,
@@ -324,7 +326,7 @@ def test_non_witness_transaction(self):
324
326
self .utxo .append (UTXO (tx .sha256 , 0 , 49 * 100000000 ))
325
327
self .generate (self .nodes [0 ], 1 )
326
328
327
- @subtest # type: ignore
329
+ @subtest
328
330
def test_unnecessary_witness_before_segwit_activation (self ):
329
331
"""Verify that blocks with witnesses are rejected before activation."""
330
332
@@ -355,7 +357,7 @@ def test_unnecessary_witness_before_segwit_activation(self):
355
357
self .utxo .pop (0 )
356
358
self .utxo .append (UTXO (tx .sha256 , 0 , tx .vout [0 ].nValue ))
357
359
358
- @subtest # type: ignore
360
+ @subtest
359
361
def test_block_relay (self ):
360
362
"""Test that block requests to NODE_WITNESS peer are with MSG_WITNESS_FLAG.
361
363
@@ -444,7 +446,7 @@ def test_block_relay(self):
444
446
self .old_node .announce_tx_and_wait_for_getdata (block4 .vtx [0 ])
445
447
assert block4 .sha256 not in self .old_node .getdataset
446
448
447
- @subtest # type: ignore
449
+ @subtest
448
450
def test_v0_outputs_arent_spendable (self ):
449
451
"""Test that v0 outputs aren't spendable before segwit activation.
450
452
@@ -516,7 +518,7 @@ def test_v0_outputs_arent_spendable(self):
516
518
self .utxo .pop (0 )
517
519
self .utxo .append (UTXO (txid , 2 , value ))
518
520
519
- @subtest # type: ignore
521
+ @subtest
520
522
def test_witness_tx_relay_before_segwit_activation (self ):
521
523
522
524
# Generate a transaction that doesn't require a witness, but send it
@@ -558,7 +560,7 @@ def test_witness_tx_relay_before_segwit_activation(self):
558
560
self .utxo .pop (0 )
559
561
self .utxo .append (UTXO (tx_hash , 0 , tx_value ))
560
562
561
- @subtest # type: ignore
563
+ @subtest
562
564
def test_standardness_v0 (self ):
563
565
"""Test V0 txout standardness.
564
566
@@ -656,7 +658,7 @@ def test_standardness_v0(self):
656
658
self .utxo .append (UTXO (tx3 .sha256 , 0 , tx3 .vout [0 ].nValue ))
657
659
assert_equal (len (self .nodes [1 ].getrawmempool ()), 0 )
658
660
659
- @subtest # type: ignore
661
+ @subtest
660
662
def advance_to_segwit_active (self ):
661
663
"""Mine enough blocks to activate segwit."""
662
664
assert not softfork_active (self .nodes [0 ], 'segwit' )
@@ -667,7 +669,7 @@ def advance_to_segwit_active(self):
667
669
assert softfork_active (self .nodes [0 ], 'segwit' )
668
670
self .segwit_active = True
669
671
670
- @subtest # type: ignore
672
+ @subtest
671
673
def test_p2sh_witness (self ):
672
674
"""Test P2SH wrapped witness programs."""
673
675
@@ -734,7 +736,7 @@ def test_p2sh_witness(self):
734
736
self .utxo .pop (0 )
735
737
self .utxo .append (UTXO (spend_tx .sha256 , 0 , spend_tx .vout [0 ].nValue ))
736
738
737
- @subtest # type: ignore
739
+ @subtest
738
740
def test_witness_commitments (self ):
739
741
"""Test witness commitments.
740
742
@@ -823,7 +825,7 @@ def test_witness_commitments(self):
823
825
self .utxo .pop (0 )
824
826
self .utxo .append (UTXO (tx3 .sha256 , 0 , tx3 .vout [0 ].nValue ))
825
827
826
- @subtest # type: ignore
828
+ @subtest
827
829
def test_block_malleability (self ):
828
830
829
831
# Make sure that a block that has too big a virtual size
@@ -863,7 +865,7 @@ def test_block_malleability(self):
863
865
block .vtx [0 ].wit .vtxinwit [0 ].scriptWitness .stack = [ser_uint256 (0 )]
864
866
test_witness_block (self .nodes [0 ], self .test_node , block , accepted = True )
865
867
866
- @subtest # type: ignore
868
+ @subtest
867
869
def test_witness_block_size (self ):
868
870
# TODO: Test that non-witness carrying blocks can't exceed 1MB
869
871
# Skipping this test for now; this is covered in feature_block.py
@@ -938,7 +940,7 @@ def test_witness_block_size(self):
938
940
self .utxo .pop (0 )
939
941
self .utxo .append (UTXO (block .vtx [- 1 ].sha256 , 0 , block .vtx [- 1 ].vout [0 ].nValue ))
940
942
941
- @subtest # type: ignore
943
+ @subtest
942
944
def test_submit_block (self ):
943
945
"""Test that submitblock adds the nonce automatically when possible."""
944
946
block = self .build_next_block ()
@@ -974,7 +976,7 @@ def test_submit_block(self):
974
976
# Tip should not advance!
975
977
assert self .nodes [0 ].getbestblockhash () != block_2 .hash
976
978
977
- @subtest # type: ignore
979
+ @subtest
978
980
def test_extra_witness_data (self ):
979
981
"""Test extra witness data in a transaction."""
980
982
@@ -1049,7 +1051,7 @@ def test_extra_witness_data(self):
1049
1051
self .utxo .pop (0 )
1050
1052
self .utxo .append (UTXO (tx2 .sha256 , 0 , tx2 .vout [0 ].nValue ))
1051
1053
1052
- @subtest # type: ignore
1054
+ @subtest
1053
1055
def test_max_witness_push_length (self ):
1054
1056
"""Test that witness stack can only allow up to 520 byte pushes."""
1055
1057
@@ -1086,7 +1088,7 @@ def test_max_witness_push_length(self):
1086
1088
self .utxo .pop ()
1087
1089
self .utxo .append (UTXO (tx2 .sha256 , 0 , tx2 .vout [0 ].nValue ))
1088
1090
1089
- @subtest # type: ignore
1091
+ @subtest
1090
1092
def test_max_witness_script_length (self ):
1091
1093
"""Test that witness outputs greater than 10kB can't be spent."""
1092
1094
@@ -1133,7 +1135,7 @@ def test_max_witness_script_length(self):
1133
1135
self .utxo .pop ()
1134
1136
self .utxo .append (UTXO (tx2 .sha256 , 0 , tx2 .vout [0 ].nValue ))
1135
1137
1136
- @subtest # type: ignore
1138
+ @subtest
1137
1139
def test_witness_input_length (self ):
1138
1140
"""Test that vin length must match vtxinwit length."""
1139
1141
@@ -1217,7 +1219,7 @@ def serialize_with_witness(self):
1217
1219
self .utxo .pop ()
1218
1220
self .utxo .append (UTXO (tx2 .sha256 , 0 , tx2 .vout [0 ].nValue ))
1219
1221
1220
- @subtest # type: ignore
1222
+ @subtest
1221
1223
def test_tx_relay_after_segwit_activation (self ):
1222
1224
"""Test transaction relay after segwit activation.
1223
1225
@@ -1309,7 +1311,7 @@ def test_tx_relay_after_segwit_activation(self):
1309
1311
self .utxo .pop (0 )
1310
1312
self .utxo .append (UTXO (tx3 .sha256 , 0 , tx3 .vout [0 ].nValue ))
1311
1313
1312
- @subtest # type: ignore
1314
+ @subtest
1313
1315
def test_segwit_versions (self ):
1314
1316
"""Test validity of future segwit version transactions.
1315
1317
@@ -1403,7 +1405,7 @@ def test_segwit_versions(self):
1403
1405
# Add utxo to our list
1404
1406
self .utxo .append (UTXO (tx3 .sha256 , 0 , tx3 .vout [0 ].nValue ))
1405
1407
1406
- @subtest # type: ignore
1408
+ @subtest
1407
1409
def test_premature_coinbase_witness_spend (self ):
1408
1410
1409
1411
block = self .build_next_block ()
@@ -1437,7 +1439,7 @@ def test_premature_coinbase_witness_spend(self):
1437
1439
test_witness_block (self .nodes [0 ], self .test_node , block2 , accepted = True )
1438
1440
self .sync_blocks ()
1439
1441
1440
- @subtest # type: ignore
1442
+ @subtest
1441
1443
def test_uncompressed_pubkey (self ):
1442
1444
"""Test uncompressed pubkey validity in segwit transactions.
1443
1445
@@ -1540,7 +1542,7 @@ def test_uncompressed_pubkey(self):
1540
1542
test_witness_block (self .nodes [0 ], self .test_node , block , accepted = True )
1541
1543
self .utxo .append (UTXO (tx5 .sha256 , 0 , tx5 .vout [0 ].nValue ))
1542
1544
1543
- @subtest # type: ignore
1545
+ @subtest
1544
1546
def test_signature_version_1 (self ):
1545
1547
1546
1548
key = ECKey ()
@@ -1726,7 +1728,7 @@ def test_signature_version_1(self):
1726
1728
for i in range (len (tx .vout )):
1727
1729
self .utxo .append (UTXO (tx .sha256 , i , tx .vout [i ].nValue ))
1728
1730
1729
- @subtest # type: ignore
1731
+ @subtest
1730
1732
def test_non_standard_witness_blinding (self ):
1731
1733
"""Test behavior of unnecessary witnesses in transactions does not blind the node for the transaction"""
1732
1734
@@ -1779,7 +1781,7 @@ def test_non_standard_witness_blinding(self):
1779
1781
self .utxo .pop (0 )
1780
1782
self .utxo .append (UTXO (tx3 .sha256 , 0 , tx3 .vout [0 ].nValue ))
1781
1783
1782
- @subtest # type: ignore
1784
+ @subtest
1783
1785
def test_non_standard_witness (self ):
1784
1786
"""Test detection of non-standard P2WSH witness"""
1785
1787
pad = chr (1 ).encode ('latin-1' )
@@ -1878,7 +1880,7 @@ def test_non_standard_witness(self):
1878
1880
1879
1881
self .utxo .pop (0 )
1880
1882
1881
- @subtest # type: ignore
1883
+ @subtest
1882
1884
def test_witness_sigops (self ):
1883
1885
"""Test sigop counting is correct inside witnesses."""
1884
1886
@@ -1980,7 +1982,7 @@ def test_witness_sigops(self):
1980
1982
self .utxo .pop (0 )
1981
1983
self .utxo .append (UTXO (tx2 .sha256 , 0 , tx2 .vout [0 ].nValue ))
1982
1984
1983
- @subtest # type: ignore
1985
+ @subtest
1984
1986
def test_superfluous_witness (self ):
1985
1987
# Serialization of tx that puts witness flag to 3 always
1986
1988
def serialize_with_bogus_witness (tx ):
@@ -2024,7 +2026,7 @@ def serialize(self):
2024
2026
with self .nodes [0 ].assert_debug_log (['Unknown transaction optional data' ]):
2025
2027
self .test_node .send_and_ping (msg_bogus_tx (tx ))
2026
2028
2027
- @subtest # type: ignore
2029
+ @subtest
2028
2030
def test_wtxid_relay (self ):
2029
2031
# Use brand new nodes to avoid contamination from earlier tests
2030
2032
self .wtx_node = self .nodes [0 ].add_p2p_connection (TestP2PConn (wtxidrelay = True ), services = P2P_SERVICES )
0 commit comments