29
29
block 200. node2 will reject block 102 since it's assumed valid, but it
30
30
isn't buried by at least two weeks' work.
31
31
"""
32
- import time
33
32
34
- from test_framework .blocktools import (create_block , create_coinbase )
33
+ from test_framework .blocktools import (
34
+ create_block ,
35
+ create_coinbase ,
36
+ )
35
37
from test_framework .key import ECKey
36
38
from test_framework .messages import (
37
39
CBlockHeader ,
@@ -79,24 +81,6 @@ def send_blocks_until_disconnected(self, p2p_conn):
79
81
assert not p2p_conn .is_connected
80
82
break
81
83
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
-
100
84
def run_test (self ):
101
85
p2p0 = self .nodes [0 ].add_p2p_connection (BaseNode ())
102
86
@@ -177,7 +161,8 @@ def run_test(self):
177
161
178
162
# Send blocks to node0. Block 102 will be rejected.
179
163
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 )
181
166
182
167
# Send all blocks to node1. All blocks will be accepted.
183
168
for i in range (2202 ):
@@ -188,7 +173,8 @@ def run_test(self):
188
173
189
174
# Send blocks to node2. Block 102 will be rejected.
190
175
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 )
192
178
193
179
194
180
if __name__ == '__main__' :
0 commit comments