Changeset View
Changeset View
Standalone View
Standalone View
test/functional/blockchain.py
Show All 16 Lines | |||||
Tests correspond to code in rpc/blockchain.cpp. | Tests correspond to code in rpc/blockchain.cpp. | ||||
""" | """ | ||||
from decimal import Decimal | from decimal import Decimal | ||||
import http.client | import http.client | ||||
import subprocess | import subprocess | ||||
from test_framework.test_framework import BitcoinTestFramework | from test_framework.test_framework import ( | ||||
BitcoinTestFramework, BITCOIND_PROC_WAIT_TIMEOUT) | |||||
from test_framework.util import ( | from test_framework.util import ( | ||||
assert_equal, | assert_equal, | ||||
assert_raises, | assert_raises, | ||||
assert_raises_jsonrpc, | assert_raises_jsonrpc, | ||||
assert_is_hex_string, | assert_is_hex_string, | ||||
assert_is_hash_string, | assert_is_hash_string, | ||||
bitcoind_processes, | |||||
BITCOIND_PROC_WAIT_TIMEOUT, | |||||
) | ) | ||||
class BlockchainTest(BitcoinTestFramework): | class BlockchainTest(BitcoinTestFramework): | ||||
def __init__(self): | def __init__(self): | ||||
super().__init__() | super().__init__() | ||||
self.setup_clean_chain = False | self.setup_clean_chain = False | ||||
self.num_nodes = 1 | self.num_nodes = 1 | ||||
▲ Show 20 Lines • Show All 121 Lines • ▼ Show 20 Lines | def _test_getnetworkhashps(self): | ||||
assert abs(hashes_per_second * 300 - 1) < 0.0001 | assert abs(hashes_per_second * 300 - 1) < 0.0001 | ||||
def _test_stopatheight(self): | def _test_stopatheight(self): | ||||
assert_equal(self.nodes[0].getblockcount(), 200) | assert_equal(self.nodes[0].getblockcount(), 200) | ||||
self.nodes[0].generate(6) | self.nodes[0].generate(6) | ||||
assert_equal(self.nodes[0].getblockcount(), 206) | assert_equal(self.nodes[0].getblockcount(), 206) | ||||
self.log.debug('Node should not stop at this height') | self.log.debug('Node should not stop at this height') | ||||
assert_raises(subprocess.TimeoutExpired, | assert_raises(subprocess.TimeoutExpired, | ||||
lambda: bitcoind_processes[0].wait(timeout=3)) | lambda: self.bitcoind_processes[0].wait(timeout=3)) | ||||
try: | try: | ||||
self.nodes[0].generate(1) | self.nodes[0].generate(1) | ||||
except (ConnectionError, http.client.BadStatusLine): | except (ConnectionError, http.client.BadStatusLine): | ||||
pass # The node already shut down before response | pass # The node already shut down before response | ||||
self.log.debug('Node should stop at this height...') | self.log.debug('Node should stop at this height...') | ||||
bitcoind_processes[0].wait(timeout=BITCOIND_PROC_WAIT_TIMEOUT) | self.bitcoind_processes[0].wait(timeout=BITCOIND_PROC_WAIT_TIMEOUT) | ||||
self.nodes[0] = self.start_node(0, self.options.tmpdir) | self.nodes[0] = self.start_node(0, self.options.tmpdir) | ||||
assert_equal(self.nodes[0].getblockcount(), 207) | assert_equal(self.nodes[0].getblockcount(), 207) | ||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
BlockchainTest().main() | BlockchainTest().main() |