Merge #21117: test: remove assert_blockchain_height

fa0a4d6c605b8ed47796f68068d6273bef7fcaef test: remove assert_blockchain_height (MarcoFalke)

Pull request description:

  This simplifies the code and solves intermittent timeouts caused by commit 0d39b5848a7a341cd2b958336861cdd4098e2616.

  E.g. https://cirrus-ci.com/task/5196092369272832?command=ci#L3126

  ```
   test  2021-02-08T12:27:56.275000Z TestFramework (ERROR): Assertion failed
                                     Traceback (most recent call last):
                                       File "/tmp/cirrus-ci-build/ci/scratch/build/bitcoin-x86_64-pc-linux-gnu/test/functional/test_framework/test_framework.py", line 127, in main
                                         self.run_test()
                                       File "/tmp/cirrus-ci-build/ci/scratch/build/bitcoin-x86_64-pc-linux-gnu/test/functional/feature_assumevalid.py", line 180, in run_test
                                         self.assert_blockchain_height(self.nodes[0], 101)
                                       File "/tmp/cirrus-ci-build/ci/scratch/build/bitcoin-x86_64-pc-linux-gnu/test/functional/feature_assumevalid.py", line 92, in assert_blockchain_height
                                         assert False, "blockchain too short after timeout: %d" % current_height
                                     AssertionError: blockchain too short after timeout: 101

ACKs for top commit:
  glozow:
    ACK fa0a4d6c60

Tree-SHA512: 3859b0c1581c21f03c775f119204cc3a219e5d86346883634886f6da46feaf254b9c6c49c1ec4581ffe409cdf05f6e91ec38c3976c3daf4a9e67f96ddc1e0dce
This commit is contained in:
MarcoFalke 2021-02-09 07:43:39 +01:00 committed by pasta
parent 63885189ae
commit 5d42d044df
No known key found for this signature in database
GPG Key ID: 52527BEDABE87984

View File

@ -29,9 +29,12 @@ Start three nodes:
block 200. node2 will reject block 102 since it's assumed valid, but it block 200. node2 will reject block 102 since it's assumed valid, but it
isn't buried by at least two weeks' work. isn't buried by at least two weeks' work.
""" """
import time
from test_framework.blocktools import (COINBASE_MATURITY,create_block, create_coinbase) from test_framework.blocktools import (
COINBASE_MATURITY,
create_block,
create_coinbase,
)
from test_framework.key import ECKey from test_framework.key import ECKey
from test_framework.messages import ( from test_framework.messages import (
CBlockHeader, CBlockHeader,
@ -45,7 +48,7 @@ from test_framework.messages import (
from test_framework.mininode import P2PInterface from test_framework.mininode import P2PInterface
from test_framework.script import (CScript, OP_TRUE) from test_framework.script import (CScript, OP_TRUE)
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import (assert_equal, set_node_times) from test_framework.util import (assert_equal, set_node_times, wait_until)
class BaseNode(P2PInterface): class BaseNode(P2PInterface):
@ -80,24 +83,6 @@ class AssumeValidTest(BitcoinTestFramework):
assert not p2p_conn.is_connected assert not p2p_conn.is_connected
break break
def assert_blockchain_height(self, node, height):
"""Wait until the blockchain is no longer advancing and verify it's reached the expected height."""
last_height = node.getblock(node.getbestblockhash())['height']
timeout = 10
while True:
time.sleep(0.25)
current_height = node.getblock(node.getbestblockhash())['height']
if current_height != last_height:
last_height = current_height
if timeout < 0:
assert False, "blockchain too short after timeout: %d" % current_height
timeout -= 0.25
continue
elif current_height > height:
assert False, "blockchain too long: %d" % current_height
elif current_height == height:
break
def run_test(self): def run_test(self):
p2p0 = self.nodes[0].add_p2p_connection(BaseNode()) p2p0 = self.nodes[0].add_p2p_connection(BaseNode())
@ -187,7 +172,8 @@ class AssumeValidTest(BitcoinTestFramework):
# Send blocks to node0. Block 102 will be rejected. # Send blocks to node0. Block 102 will be rejected.
self.send_blocks_until_disconnected(p2p0) self.send_blocks_until_disconnected(p2p0)
self.assert_blockchain_height(self.nodes[0], COINBASE_MATURITY + 1) wait_until(lambda: self.nodes[0].getblockcount() >= COINBASE_MATURITY + 1)
assert_equal(self.nodes[0].getblockcount(), COINBASE_MATURITY + 1)
# Send 200 blocks to node1. All blocks, including block 102, will be accepted. # Send 200 blocks to node1. All blocks, including block 102, will be accepted.
for i in range(200): for i in range(200):
@ -198,7 +184,8 @@ class AssumeValidTest(BitcoinTestFramework):
# Send blocks to node2. Block 102 will be rejected. # Send blocks to node2. Block 102 will be rejected.
self.send_blocks_until_disconnected(p2p2) self.send_blocks_until_disconnected(p2p2)
self.assert_blockchain_height(self.nodes[2], COINBASE_MATURITY + 1) wait_until(lambda: self.nodes[2].getblockcount() >= COINBASE_MATURITY + 1)
assert_equal(self.nodes[2].getblockcount(), COINBASE_MATURITY + 1)
if __name__ == '__main__': if __name__ == '__main__':