Skip to content

Instantly share code, notes, and snippets.

@dgenr8
Last active November 27, 2016 18:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dgenr8/4885632cdab541871f1b6b7cf3e1f483 to your computer and use it in GitHub Desktop.
Save dgenr8/4885632cdab541871f1b6b7cf3e1f483 to your computer and use it in GitHub Desktop.
#!/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 BitcoinTestFramework
from test_framework.util import assert_equal
from test_framework.util import *
import pdb
class BUChangeParamsTest (BitcoinTestFramework):
def run_test (self):
BitcoinTestFramework.run_test (self)
tips = self.nodes[0].getchaintips ()
assert_equal (len (tips), 1)
assert_equal (tips[0]['branchlen'], 0)
assert_equal (tips[0]['height'], 200)
assert_equal (tips[0]['status'], 'active')
self.nodes[1].setminingmaxblock(1000)
self.nodes[1].setexcessiveblock(1000, 2)
# Mine an excessive block. Node 1 should not accept 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, [201,200])
# Mine a block on top. Node 1 should still not accept it
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, [202,200])
# Change node 1 to AD=1. The assertion will fail if it doesn't accept the chain now
self.nodes[1].setexcessiveblock(1000, 1)
counts = [ x.getblockcount() for x in self.nodes ]
assert_equal(counts, [202,202])
if __name__ == '__main__':
BUChangeParamsTest ().main ()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment