Changeset View
Changeset View
Standalone View
Standalone View
test/functional/abc-parkedchain.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (c) 2018 The Bitcoin developers | # Copyright (c) 2018 The Bitcoin developers | ||||
# Distributed under the MIT software license, see the accompanying | # Distributed under the MIT software license, see the accompanying | ||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | # file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
"""Test the parckblock and unparkblock RPC calls.""" | """Test the parckblock and unparkblock RPC calls.""" | ||||
import os | import os | ||||
from test_framework.test_framework import BitcoinTestFramework | from test_framework.test_framework import BitcoinTestFramework | ||||
from test_framework.util import assert_equal, connect_nodes_bi, sync_blocks, wait_until | from test_framework.util import assert_equal, wait_until | ||||
class ParkedChainTest(BitcoinTestFramework): | class ParkedChainTest(BitcoinTestFramework): | ||||
def set_test_params(self): | def set_test_params(self): | ||||
self.num_nodes = 2 | self.num_nodes = 2 | ||||
self.extra_args = [["-noparkdeepreorg"], ["-maxreorgdepth=-1"]] | self.extra_args = [["-noparkdeepreorg"], ["-maxreorgdepth=-1"]] | ||||
# There should only be one chaintip, which is expected_tip | # There should only be one chaintip, which is expected_tip | ||||
▲ Show 20 Lines • Show All 103 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
# not updated, so the "parked" state remains. | # not updated, so the "parked" state remains. | ||||
self.only_valid_tip(tip, other_tip_status="parked") | self.only_valid_tip(tip, other_tip_status="parked") | ||||
node.unparkblock(bad_tip) | node.unparkblock(bad_tip) | ||||
self.only_valid_tip(tip, other_tip_status="invalid") | self.only_valid_tip(tip, other_tip_status="invalid") | ||||
node.reconsiderblock(bad_tip) | node.reconsiderblock(bad_tip) | ||||
self.only_valid_tip(good_tip) | self.only_valid_tip(good_tip) | ||||
# First, make sure both nodes are in sync. | # First, make sure both nodes are in sync. | ||||
parking_node = self.nodes[1] | def wait_for_tip(node, tip): | ||||
connect_nodes_bi(self.nodes[0], self.nodes[1]) | def check_tip(): | ||||
sync_blocks(self.nodes[0:2]) | return node.getbestblockhash() == tip | ||||
wait_until(check_tip) | |||||
parking_node = self.nodes[1] | |||||
wait_for_tip(parking_node, good_tip) | |||||
assert_equal(node.getbestblockhash(), parking_node.getbestblockhash()) | assert_equal(node.getbestblockhash(), parking_node.getbestblockhash()) | ||||
# Wait for node 1 to park the chain. | # Wait for node 1 to park the chain. | ||||
def wait_for_parked_block(block): | def wait_for_parked_block(block): | ||||
def check_block(): | def check_block(): | ||||
for tip in parking_node.getchaintips(): | for tip in parking_node.getchaintips(): | ||||
if tip["hash"] == block: | if tip["hash"] == block: | ||||
assert(tip["status"] != "active") | assert(tip["status"] != "active") | ||||
Show All 33 Lines |