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>
This commit is contained in:
Gavin Andresen
2014-10-24 15:13:03 -04:00
8 changed files with 210 additions and 134 deletions

View File

@@ -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_chain(self):
print("Initializing test directory "+self.options.tmpdir)
initialize_chain(self.options.tmpdir)
def setup_network(self, tmp_directory):
nodes = start_nodes(2, tmp_directory)
connect_nodes(nodes[1], 0)
sync_blocks(nodes)
return nodes
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)