|
| 1 | +#!/usr/bin/env python2 |
| 2 | +# Copyright (c) 2014 The Bitcoin Core developers |
| 3 | +# Distributed under the MIT software license, see the accompanying |
| 4 | +# file COPYING or http://www.opensource.org/licenses/mit-license.php. |
| 5 | + |
| 6 | +# |
| 7 | +# Test the BIP66 changeover logic |
| 8 | +# |
| 9 | + |
| 10 | +from test_framework import BitcoinTestFramework |
| 11 | +from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException |
| 12 | +from util import * |
| 13 | +import os |
| 14 | +import shutil |
| 15 | + |
| 16 | +class BIP66Test(BitcoinTestFramework): |
| 17 | + |
| 18 | + def setup_network(self): |
| 19 | + self.nodes = [] |
| 20 | + self.nodes.append(start_node(0, self.options.tmpdir, [])) |
| 21 | + self.nodes.append(start_node(1, self.options.tmpdir, ["-blockversion=2"])) |
| 22 | + self.nodes.append(start_node(2, self.options.tmpdir, ["-blockversion=3"])) |
| 23 | + connect_nodes(self.nodes[1], 0) |
| 24 | + connect_nodes(self.nodes[2], 0) |
| 25 | + self.is_network_split = False |
| 26 | + self.sync_all() |
| 27 | + |
| 28 | + def run_test(self): |
| 29 | + cnt = self.nodes[0].getblockcount() |
| 30 | + |
| 31 | + # Mine some old-version blocks |
| 32 | + self.nodes[1].setgenerate(True, 100) |
| 33 | + self.sync_all() |
| 34 | + if (self.nodes[0].getblockcount() != cnt + 100): |
| 35 | + raise AssertionError("Failed to mine 100 version=2 blocks") |
| 36 | + |
| 37 | + # Mine 750 new-version blocks |
| 38 | + for i in xrange(15): |
| 39 | + self.nodes[2].setgenerate(True, 50) |
| 40 | + self.sync_all() |
| 41 | + if (self.nodes[0].getblockcount() != cnt + 850): |
| 42 | + raise AssertionError("Failed to mine 750 version=3 blocks") |
| 43 | + |
| 44 | + # TODO: check that new DERSIG rules are not enforced |
| 45 | + |
| 46 | + # Mine 1 new-version block |
| 47 | + self.nodes[2].setgenerate(True, 1) |
| 48 | + self.sync_all() |
| 49 | + if (self.nodes[0].getblockcount() != cnt + 851): |
| 50 | + raise AssertionFailure("Failed to mine a version=3 blocks") |
| 51 | + |
| 52 | + # TODO: check that new DERSIG rules are enforced |
| 53 | + |
| 54 | + # Mine 198 new-version blocks |
| 55 | + for i in xrange(2): |
| 56 | + self.nodes[2].setgenerate(True, 99) |
| 57 | + self.sync_all() |
| 58 | + if (self.nodes[0].getblockcount() != cnt + 1049): |
| 59 | + raise AssertionError("Failed to mine 198 version=3 blocks") |
| 60 | + |
| 61 | + # Mine 1 old-version block |
| 62 | + self.nodes[1].setgenerate(True, 1) |
| 63 | + self.sync_all() |
| 64 | + if (self.nodes[0].getblockcount() != cnt + 1050): |
| 65 | + raise AssertionError("Failed to mine a version=2 block after 949 version=3 blocks") |
| 66 | + |
| 67 | + # Mine 1 new-version blocks |
| 68 | + self.nodes[2].setgenerate(True, 1) |
| 69 | + self.sync_all() |
| 70 | + if (self.nodes[0].getblockcount() != cnt + 1051): |
| 71 | + raise AssertionError("Failed to mine a version=3 block") |
| 72 | + |
| 73 | + # Mine 1 old-version blocks |
| 74 | + try: |
| 75 | + self.nodes[1].setgenerate(True, 1) |
| 76 | + raise AssertionError("Succeeded to mine a version=2 block after 950 version=3 blocks") |
| 77 | + except JSONRPCException: |
| 78 | + pass |
| 79 | + self.sync_all() |
| 80 | + if (self.nodes[0].getblockcount() != cnt + 1051): |
| 81 | + raise AssertionError("Accepted a version=2 block after 950 version=3 blocks") |
| 82 | + |
| 83 | + # Mine 1 new-version blocks |
| 84 | + self.nodes[2].setgenerate(True, 1) |
| 85 | + self.sync_all() |
| 86 | + if (self.nodes[0].getblockcount() != cnt + 1052): |
| 87 | + raise AssertionError("Failed to mine a version=3 block") |
| 88 | + |
| 89 | +if __name__ == '__main__': |
| 90 | + BIP66Test().main() |
0 commit comments