10
10
3) Invalid block with bad coinbase value should be rejected and not
11
11
re-requested.
12
12
"""
13
-
14
- from test_framework .test_framework import ComparisonTestFramework
15
- from test_framework .util import *
16
- from test_framework .comptool import TestManager , TestInstance , RejectResult
17
- from test_framework .blocktools import *
18
- from test_framework .mininode import network_thread_start
19
13
import copy
20
14
import time
21
15
22
- # Use the ComparisonTestFramework with 1 node: only use --testbinary.
23
- class InvalidBlockRequestTest (ComparisonTestFramework ):
16
+ from test_framework .blocktools import create_block , create_coinbase , create_transaction
17
+ from test_framework .comptool import RejectResult , TestInstance , TestManager
18
+ from test_framework .messages import COIN
19
+ from test_framework .mininode import network_thread_start
20
+ from test_framework .test_framework import ComparisonTestFramework
21
+ from test_framework .util import assert_equal
24
22
25
- ''' Can either run this test as 1 node with expected answers, or two and compare them.
26
- Change the "outcome" variable from each TestInstance object to only do the comparison. '''
23
+ class InvalidBlockRequestTest (ComparisonTestFramework ):
27
24
def set_test_params (self ):
28
25
self .num_nodes = 1
29
26
self .setup_clean_chain = True
@@ -39,11 +36,10 @@ def run_test(self):
39
36
def get_tests (self ):
40
37
if self .tip is None :
41
38
self .tip = int ("0x" + self .nodes [0 ].getbestblockhash (), 0 )
42
- self .block_time = int (time .time ())+ 1
39
+ self .block_time = int (time .time ()) + 1
40
+
41
+ self .log .info ("Create a new block with an anyone-can-spend coinbase" )
43
42
44
- '''
45
- Create a new block with an anyone-can-spend coinbase
46
- '''
47
43
height = 1
48
44
block = create_block (self .tip , create_coinbase (height ), self .block_time )
49
45
self .block_time += 1
@@ -54,9 +50,8 @@ def get_tests(self):
54
50
height += 1
55
51
yield TestInstance ([[block , True ]])
56
52
57
- '''
58
- Now we need that block to mature so we can spend the coinbase.
59
- '''
53
+ self .log .info ("Mature the block." )
54
+
60
55
test = TestInstance (sync_every_block = False )
61
56
for i in range (100 ):
62
57
block = create_block (self .tip , create_coinbase (height ), self .block_time )
@@ -67,13 +62,12 @@ def get_tests(self):
67
62
height += 1
68
63
yield test
69
64
70
- '''
71
- Now we use merkle-root malleability to generate an invalid block with
72
- same blockheader.
73
- Manufacture a block with 3 transactions (coinbase, spend of prior
74
- coinbase, spend of that spend). Duplicate the 3rd transaction to
75
- leave merkle root and blockheader unchanged but invalidate the block.
76
- '''
65
+ # Use merkle-root malleability to generate an invalid block with
66
+ # same blockheader.
67
+ # Manufacture a block with 3 transactions (coinbase, spend of prior
68
+ # coinbase, spend of that spend). Duplicate the 3rd transaction to
69
+ # leave merkle root and blockheader unchanged but invalidate the block.
70
+ self .log .info ("Test merkle root malleability." )
77
71
block2 = create_block (self .tip , create_coinbase (height ), self .block_time )
78
72
self .block_time += 1
79
73
@@ -98,13 +92,12 @@ def get_tests(self):
98
92
yield TestInstance ([[block2 , RejectResult (16 , b'bad-txns-duplicate' )], [block2_orig , True ]])
99
93
height += 1
100
94
101
- '''
102
- Make sure that a totally screwed up block is not valid.
103
- '''
95
+ self .log .info ("Test very broken block." )
96
+
104
97
block3 = create_block (self .tip , create_coinbase (height ), self .block_time )
105
98
self .block_time += 1
106
- block3 .vtx [0 ].vout [0 ].nValue = 100 * COIN # Too high!
107
- block3 .vtx [0 ].sha256 = None
99
+ block3 .vtx [0 ].vout [0 ].nValue = 100 * COIN # Too high!
100
+ block3 .vtx [0 ].sha256 = None
108
101
block3 .vtx [0 ].calc_sha256 ()
109
102
block3 .hashMerkleRoot = block3 .calc_merkle_root ()
110
103
block3 .rehash ()
0 commit comments