Skip to content

Commit fa0a4d6

Browse files
author
MarcoFalke
committed
test: remove assert_blockchain_height
1 parent b401b09 commit fa0a4d6

File tree

1 file changed

+8
-22
lines changed

1 file changed

+8
-22
lines changed

test/functional/feature_assumevalid.py

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@
2929
block 200. node2 will reject block 102 since it's assumed valid, but it
3030
isn't buried by at least two weeks' work.
3131
"""
32-
import time
3332

34-
from test_framework.blocktools import (create_block, create_coinbase)
33+
from test_framework.blocktools import (
34+
create_block,
35+
create_coinbase,
36+
)
3537
from test_framework.key import ECKey
3638
from test_framework.messages import (
3739
CBlockHeader,
@@ -79,24 +81,6 @@ def send_blocks_until_disconnected(self, p2p_conn):
7981
assert not p2p_conn.is_connected
8082
break
8183

82-
def assert_blockchain_height(self, node, height):
83-
"""Wait until the blockchain is no longer advancing and verify it's reached the expected height."""
84-
last_height = node.getblock(node.getbestblockhash())['height']
85-
timeout = 10
86-
while True:
87-
time.sleep(0.25)
88-
current_height = node.getblock(node.getbestblockhash())['height']
89-
if current_height != last_height:
90-
last_height = current_height
91-
if timeout < 0:
92-
assert False, "blockchain too short after timeout: %d" % current_height
93-
timeout -= 0.25
94-
continue
95-
elif current_height > height:
96-
assert False, "blockchain too long: %d" % current_height
97-
elif current_height == height:
98-
break
99-
10084
def run_test(self):
10185
p2p0 = self.nodes[0].add_p2p_connection(BaseNode())
10286

@@ -177,7 +161,8 @@ def run_test(self):
177161

178162
# Send blocks to node0. Block 102 will be rejected.
179163
self.send_blocks_until_disconnected(p2p0)
180-
self.assert_blockchain_height(self.nodes[0], 101)
164+
self.wait_until(lambda: self.nodes[0].getblockcount() >= 101)
165+
assert_equal(self.nodes[0].getblockcount(), 101)
181166

182167
# Send all blocks to node1. All blocks will be accepted.
183168
for i in range(2202):
@@ -188,7 +173,8 @@ def run_test(self):
188173

189174
# Send blocks to node2. Block 102 will be rejected.
190175
self.send_blocks_until_disconnected(p2p2)
191-
self.assert_blockchain_height(self.nodes[2], 101)
176+
self.wait_until(lambda: self.nodes[2].getblockcount() >= 101)
177+
assert_equal(self.nodes[2].getblockcount(), 101)
192178

193179

194180
if __name__ == '__main__':

0 commit comments

Comments
 (0)