Skip to content

Commit 2b7064e

Browse files
committed
[tests] Fix flake8 warnings in invalidblockrequest
1 parent 54b8c58 commit 2b7064e

File tree

1 file changed

+22
-29
lines changed

1 file changed

+22
-29
lines changed

test/functional/p2p_invalid_block.py

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,17 @@
1010
3) Invalid block with bad coinbase value should be rejected and not
1111
re-requested.
1212
"""
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
1913
import copy
2014
import time
2115

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
2422

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):
2724
def set_test_params(self):
2825
self.num_nodes = 1
2926
self.setup_clean_chain = True
@@ -39,11 +36,10 @@ def run_test(self):
3936
def get_tests(self):
4037
if self.tip is None:
4138
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")
4342

44-
'''
45-
Create a new block with an anyone-can-spend coinbase
46-
'''
4743
height = 1
4844
block = create_block(self.tip, create_coinbase(height), self.block_time)
4945
self.block_time += 1
@@ -54,9 +50,8 @@ def get_tests(self):
5450
height += 1
5551
yield TestInstance([[block, True]])
5652

57-
'''
58-
Now we need that block to mature so we can spend the coinbase.
59-
'''
53+
self.log.info("Mature the block.")
54+
6055
test = TestInstance(sync_every_block=False)
6156
for i in range(100):
6257
block = create_block(self.tip, create_coinbase(height), self.block_time)
@@ -67,13 +62,12 @@ def get_tests(self):
6762
height += 1
6863
yield test
6964

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.")
7771
block2 = create_block(self.tip, create_coinbase(height), self.block_time)
7872
self.block_time += 1
7973

@@ -98,13 +92,12 @@ def get_tests(self):
9892
yield TestInstance([[block2, RejectResult(16, b'bad-txns-duplicate')], [block2_orig, True]])
9993
height += 1
10094

101-
'''
102-
Make sure that a totally screwed up block is not valid.
103-
'''
95+
self.log.info("Test very broken block.")
96+
10497
block3 = create_block(self.tip, create_coinbase(height), self.block_time)
10598
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
108101
block3.vtx[0].calc_sha256()
109102
block3.hashMerkleRoot = block3.calc_merkle_root()
110103
block3.rehash()

0 commit comments

Comments
 (0)