diff options
author | Gavin Andresen <gavinandresen@gmail.com> | 2014-10-24 15:13:03 -0400 |
---|---|---|
committer | Gavin Andresen <gavinandresen@gmail.com> | 2014-10-24 15:13:41 -0400 |
commit | e401a2c557ddd1f7cf66df2e62f3324e3b7bcd40 (patch) | |
tree | 9e8b536cc4cfbe1f1a636d3db52b0eb21882c2b6 /qa/rpc-tests/test_framework.py | |
parent | 505a9e1dae8eac680640e7b0dea3c0014351e519 (diff) | |
parent | 2290ed01bc1b4176a0c6b976707bf7dd6bc49f43 (diff) |
Merge pull request #5132
2290ed0 Work around #5113. (Daniel Kraft)
dcb9846 Extend getchaintips RPC test. (Daniel Kraft)
Signed-off-by: Gavin Andresen <gavinandresen@gmail.com>
Diffstat (limited to 'qa/rpc-tests/test_framework.py')
-rwxr-xr-x | qa/rpc-tests/test_framework.py | 71 |
1 files changed, 56 insertions, 15 deletions
diff --git a/qa/rpc-tests/test_framework.py b/qa/rpc-tests/test_framework.py index bd20d4c9fe..8c8453054d 100755 --- a/qa/rpc-tests/test_framework.py +++ b/qa/rpc-tests/test_framework.py @@ -21,22 +21,64 @@ from util import * class BitcoinTestFramework(object): # These may be over-ridden by subclasses: - def run_test(self, nodes): + def run_test(self): + for node in self.nodes: assert_equal(node.getblockcount(), 200) assert_equal(node.getbalance(), 25*50) def add_options(self, parser): pass - def setup_chain(self, tmp_directory): - print("Initializing test directory "+tmp_directory) - initialize_chain(tmp_directory) - - def setup_network(self, tmp_directory): - nodes = start_nodes(2, tmp_directory) - connect_nodes(nodes[1], 0) - sync_blocks(nodes) - return nodes + def setup_chain(self): + print("Initializing test directory "+self.options.tmpdir) + initialize_chain(self.options.tmpdir) + + def setup_network(self, split = False): + self.nodes = start_nodes(4, self.options.tmpdir) + + # Connect the nodes as a "chain". This allows us + # to split the network between nodes 1 and 2 to get + # two halves that can work on competing chains. + + # If we joined network halves, connect the nodes from the joint + # on outward. This ensures that chains are properly reorganised. + if not split: + connect_nodes_bi(self.nodes, 1, 2) + sync_blocks(self.nodes[1:2]) + sync_mempools(self.nodes[1:2]) + + connect_nodes_bi(self.nodes, 0, 1) + connect_nodes_bi(self.nodes, 2, 3) + self.is_network_split = split + self.sync_all() + + def split_network(self): + """ + Split the network of four nodes into nodes 0/1 and 2/3. + """ + assert not self.is_network_split + stop_nodes(self.nodes) + wait_bitcoinds() + self.setup_network(True) + + def sync_all(self): + if self.is_network_split: + sync_blocks(self.nodes[:1]) + sync_blocks(self.nodes[2:]) + sync_mempools(self.nodes[:1]) + sync_mempools(self.nodes[2:]) + else: + sync_blocks(self.nodes) + sync_mempools(self.nodes) + + def join_network(self): + """ + Join the (previously split) network halves together. + """ + assert self.is_network_split + stop_nodes(self.nodes) + wait_bitcoinds() + self.setup_network(False) def main(self): import optparse @@ -62,15 +104,14 @@ class BitcoinTestFramework(object): check_json_precision() success = False - nodes = [] try: if not os.path.isdir(self.options.tmpdir): os.makedirs(self.options.tmpdir) - self.setup_chain(self.options.tmpdir) + self.setup_chain() - nodes = self.setup_network(self.options.tmpdir) + self.setup_network() - self.run_test(nodes) + self.run_test() success = True @@ -86,7 +127,7 @@ class BitcoinTestFramework(object): if not self.options.nocleanup: print("Cleaning up") - stop_nodes(nodes) + stop_nodes(self.nodes) wait_bitcoinds() shutil.rmtree(self.options.tmpdir) |