Changeset View
Changeset View
Standalone View
Standalone View
test/functional/rpc_blockchain.py
Show First 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | |||||
) | ) | ||||
class BlockchainTest(BitcoinTestFramework): | class BlockchainTest(BitcoinTestFramework): | ||||
def set_test_params(self): | def set_test_params(self): | ||||
self.num_nodes = 1 | self.num_nodes = 1 | ||||
def skip_test_if_missing_module(self): | |||||
self.skip_if_no_wallet() | |||||
def run_test(self): | def run_test(self): | ||||
# Set extra args with pruning after rescan is complete | # Set extra args with pruning after rescan is complete | ||||
self.restart_node(0, extra_args=['-stopatheight=207', '-prune=1']) | self.restart_node(0, extra_args=['-stopatheight=207', '-prune=1']) | ||||
self._test_getblockchaininfo() | self._test_getblockchaininfo() | ||||
self._test_getchaintxstats() | self._test_getchaintxstats() | ||||
self._test_gettxoutsetinfo() | self._test_gettxoutsetinfo() | ||||
self._test_getblockheader() | self._test_getblockheader() | ||||
self._test_getdifficulty() | self._test_getdifficulty() | ||||
self._test_getnetworkhashps() | self._test_getnetworkhashps() | ||||
self._test_stopatheight() | self._test_stopatheight() | ||||
self._test_getblock() | |||||
self._test_waitforblockheight() | self._test_waitforblockheight() | ||||
if self.is_wallet_compiled(): | |||||
self._test_getblock() | |||||
assert self.nodes[0].verifychain(4, 0) | assert self.nodes[0].verifychain(4, 0) | ||||
def _test_getblockchaininfo(self): | def _test_getblockchaininfo(self): | ||||
self.log.info("Test getblockchaininfo") | self.log.info("Test getblockchaininfo") | ||||
keys = [ | keys = [ | ||||
'bestblockhash', | 'bestblockhash', | ||||
'blocks', | 'blocks', | ||||
▲ Show 20 Lines • Show All 202 Lines • ▼ Show 20 Lines | class BlockchainTest(BitcoinTestFramework): | ||||
def _test_getnetworkhashps(self): | def _test_getnetworkhashps(self): | ||||
hashes_per_second = self.nodes[0].getnetworkhashps() | hashes_per_second = self.nodes[0].getnetworkhashps() | ||||
# This should be 2 hashes every 10 minutes or 1/300 | # This should be 2 hashes every 10 minutes or 1/300 | ||||
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].generatetoaddress( | ||||
6, self.nodes[0].get_deterministic_priv_key().address) | |||||
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: self.nodes[0].process.wait(timeout=3)) | lambda: self.nodes[0].process.wait(timeout=3)) | ||||
try: | try: | ||||
self.nodes[0].generate(1) | self.nodes[0].generatetoaddress( | ||||
1, self.nodes[0].get_deterministic_priv_key().address) | |||||
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...') | ||||
self.nodes[0].wait_until_stopped() | self.nodes[0].wait_until_stopped() | ||||
self.start_node(0) | self.start_node(0) | ||||
assert_equal(self.nodes[0].getblockcount(), 207) | assert_equal(self.nodes[0].getblockcount(), 207) | ||||
def _test_getblock(self): | def _test_getblock(self): | ||||
▲ Show 20 Lines • Show All 76 Lines • Show Last 20 Lines |