Last active
November 29, 2016 22:16
-
-
Save dgenr8/e5788e0f6309367dbd5202246ada152f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python2 | |
# Copyright (c) 2014-2015 The Bitcoin Core developers | |
# Copyright (c) 2015-2016 The Bitcoin Unlimited developers | |
# Distributed under the MIT software license, see the accompanying | |
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | |
# Exercise the getchaintips API. We introduce a network split, work | |
# on chains of different lengths, and join the network together again. | |
# This gives us two tips, verify that it works. | |
import time | |
import random | |
from test_framework.test_framework import ComparisonTestFramework | |
from test_framework.util import assert_equal | |
from test_framework.util import * | |
import pdb | |
class BURestartTest(ComparisonTestFramework): | |
def run_test(self): | |
self.nodes[1].setminingmaxblock(1000) | |
self.nodes[1].setexcessiveblock(1000, 1) | |
connect_nodes_bi(self.nodes, 0, 1) | |
# Generate some money | |
self.nodes[0].generate(101) | |
sync_blocks(self.nodes) | |
# Mine an excessive block. Node 1 should activate it | |
addr = self.nodes[1].getnewaddress() | |
for i in range(0,20): | |
self.nodes[0].sendtoaddress(addr, 1.0) | |
self.nodes[0].generate(1) | |
time.sleep(2) #give blocks a chance to fully propagate | |
counts = [ x.getblockcount() for x in self.nodes[0:2] ] | |
assert_equal(counts, [102,101]) | |
# Mine a block on top. Node 1 should now accept the chain as not excessive | |
self.nodes[0].generate(1) | |
time.sleep(2) #give blocks a chance to fully propagate | |
counts = [ x.getblockcount() for x in self.nodes[0:2] ] | |
assert_equal(counts, [103,103]) | |
# Stop | |
stop_nodes(self.nodes) | |
wait_bitcoinds() | |
# Restart, but with AD=2. Node 1 should no longer accept the chain. | |
self.nodes = start_nodes( | |
self.num_nodes, self.options.tmpdir, | |
extra_args=[['-blockmaxsize=1000', '-excessiveblocksize=1000', '-excessiveacceptdepth=2', '-debug', '-whitelist=127.0.0.1']] * self.num_nodes, | |
binary=[self.options.testbinary] + | |
[self.options.refbinary]*(self.num_nodes-1)) | |
connect_nodes_bi(self.nodes, 0, 1) | |
counts = [ x.getblockcount() for x in self.nodes[0:2] ] | |
assert_equal(counts, [103,101]) | |
# Mine another block. Now node 1 should accept the chain again | |
self.nodes[0].generate(1) | |
time.sleep(2) #give blocks a chance to fully propagate | |
counts = [ x.getblockcount() for x in self.nodes[0:2] ] | |
assert_equal(counts, [104,104]) | |
if __name__ == '__main__': | |
BURestartTest().main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment