@@ -0,0 +1,1872 @@
+#!/usr/bin/env python2%0A# Copyright (c) 2014 The Bitcoin Core developers%0A# Distributed under the MIT software license, see the accompanying%0A# file COPYING or http://www.opensource.org/licenses/mit-license.php.%0A%0A#%0A# Test InvalidateBlock code%0A#%0A%0Afrom test_framework import BitcoinTestFramework%0Afrom bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException%0Afrom util import *%0A%0Aclass InvalidateTest(BitcoinTestFramework):%0A    %0A        %0A    def setup_chain(self):%0A        print(%22Initializing test directory %22+self.options.tmpdir)%0A        initialize_chain_clean(self.options.tmpdir, 2)%0A                 %0A    def setup_network(self):%0A        self.nodes = %5B%5D%0A        self.is_network_split = False %0A        self.nodes.append(start_node(0, self.options.tmpdir, %5B%22-debug%22%5D))%0A        self.nodes.append(start_node(1, self.options.tmpdir, %5B%22-debug%22%5D))%0A        %0A    def run_test(self):%0A        print %22Mine 4 blocks on Node 0%22%0A        self.nodes%5B0%5D.setgenerate(True, 4)%0A        assert(self.nodes%5B0%5D.getblockcount() == 4)%0A        besthash = self.nodes%5B0%5D.getbestblockhash()%0A%0A        print %22Mine competing 6 blocks on Node 1%22%0A        self.nodes%5B1%5D.setgenerate(True, 6)%0A        assert(self.nodes%5B1%5D.getblockcount() == 6)%0A%0A        print %22Connect nodes to force a reorg%22%0A        connect_nodes_bi(self.nodes,0,1)%0A        sync_blocks(self.nodes)%0A        assert(self.nodes%5B0%5D.getblockcount() == 6)%0A        badhash = self.nodes%5B1%5D.getblockhash(2)%0A%0A        print %22Invalidate block 2 on node 0 and verify we reorg to node 0's original chain%22%0A        self.nodes%5B0%5D.invalidateblock(badhash)%0A        newheight = self.nodes%5B0%5D.getblockcount()%0A        newhash = self.nodes%5B0%5D.getbestblockhash()%0A        if (newheight != 4 or newhash != besthash):%0A            raise AssertionError(%22Wrong tip for node0, hash %25s, height %25d%22%25(newhash,newheight))%0A%0Aif __name__ == '__main__':%0A    InvalidateTest().main()%0A

add RPC test for InvalidateBlock