2015-01-20 22:39:19 +01:00
|
|
|
#!/usr/bin/env python2
|
2015-12-13 14:51:43 +01:00
|
|
|
# Copyright (c) 2014-2015 The Bitcoin Core developers
|
2015-01-20 22:39:19 +01:00
|
|
|
# Distributed under the MIT software license, see the accompanying
|
|
|
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
|
|
|
#
|
|
|
|
# Test the BIP66 changeover logic
|
|
|
|
#
|
|
|
|
|
2015-05-02 12:53:35 +02:00
|
|
|
from test_framework.test_framework import BitcoinTestFramework
|
|
|
|
from test_framework.util import *
|
2015-01-20 22:39:19 +01:00
|
|
|
|
|
|
|
class BIP66Test(BitcoinTestFramework):
|
|
|
|
|
|
|
|
def setup_network(self):
|
|
|
|
self.nodes = []
|
|
|
|
self.nodes.append(start_node(0, self.options.tmpdir, []))
|
|
|
|
self.nodes.append(start_node(1, self.options.tmpdir, ["-blockversion=2"]))
|
|
|
|
self.nodes.append(start_node(2, self.options.tmpdir, ["-blockversion=3"]))
|
|
|
|
connect_nodes(self.nodes[1], 0)
|
|
|
|
connect_nodes(self.nodes[2], 0)
|
|
|
|
self.is_network_split = False
|
|
|
|
self.sync_all()
|
|
|
|
|
|
|
|
def run_test(self):
|
|
|
|
cnt = self.nodes[0].getblockcount()
|
|
|
|
|
|
|
|
# Mine some old-version blocks
|
2015-04-01 05:28:28 +02:00
|
|
|
self.nodes[1].generate(100)
|
2015-01-20 22:39:19 +01:00
|
|
|
self.sync_all()
|
|
|
|
if (self.nodes[0].getblockcount() != cnt + 100):
|
|
|
|
raise AssertionError("Failed to mine 100 version=2 blocks")
|
|
|
|
|
|
|
|
# Mine 750 new-version blocks
|
|
|
|
for i in xrange(15):
|
2015-04-01 05:28:28 +02:00
|
|
|
self.nodes[2].generate(50)
|
2015-01-20 22:39:19 +01:00
|
|
|
self.sync_all()
|
|
|
|
if (self.nodes[0].getblockcount() != cnt + 850):
|
|
|
|
raise AssertionError("Failed to mine 750 version=3 blocks")
|
|
|
|
|
|
|
|
# TODO: check that new DERSIG rules are not enforced
|
|
|
|
|
|
|
|
# Mine 1 new-version block
|
2015-04-01 05:28:28 +02:00
|
|
|
self.nodes[2].generate(1)
|
2015-01-20 22:39:19 +01:00
|
|
|
self.sync_all()
|
|
|
|
if (self.nodes[0].getblockcount() != cnt + 851):
|
2015-12-02 18:12:23 +01:00
|
|
|
raise AssertionError("Failed to mine a version=3 blocks")
|
2015-01-20 22:39:19 +01:00
|
|
|
|
|
|
|
# TODO: check that new DERSIG rules are enforced
|
|
|
|
|
|
|
|
# Mine 198 new-version blocks
|
|
|
|
for i in xrange(2):
|
2015-04-01 05:28:28 +02:00
|
|
|
self.nodes[2].generate(99)
|
2015-01-20 22:39:19 +01:00
|
|
|
self.sync_all()
|
|
|
|
if (self.nodes[0].getblockcount() != cnt + 1049):
|
|
|
|
raise AssertionError("Failed to mine 198 version=3 blocks")
|
|
|
|
|
|
|
|
# Mine 1 old-version block
|
2015-04-01 05:28:28 +02:00
|
|
|
self.nodes[1].generate(1)
|
2015-01-20 22:39:19 +01:00
|
|
|
self.sync_all()
|
|
|
|
if (self.nodes[0].getblockcount() != cnt + 1050):
|
|
|
|
raise AssertionError("Failed to mine a version=2 block after 949 version=3 blocks")
|
|
|
|
|
|
|
|
# Mine 1 new-version blocks
|
2015-04-01 05:28:28 +02:00
|
|
|
self.nodes[2].generate(1)
|
2015-01-20 22:39:19 +01:00
|
|
|
self.sync_all()
|
|
|
|
if (self.nodes[0].getblockcount() != cnt + 1051):
|
|
|
|
raise AssertionError("Failed to mine a version=3 block")
|
|
|
|
|
|
|
|
# Mine 1 old-version blocks
|
|
|
|
try:
|
2015-04-01 05:28:28 +02:00
|
|
|
self.nodes[1].generate(1)
|
2015-01-20 22:39:19 +01:00
|
|
|
raise AssertionError("Succeeded to mine a version=2 block after 950 version=3 blocks")
|
|
|
|
except JSONRPCException:
|
|
|
|
pass
|
|
|
|
self.sync_all()
|
|
|
|
if (self.nodes[0].getblockcount() != cnt + 1051):
|
|
|
|
raise AssertionError("Accepted a version=2 block after 950 version=3 blocks")
|
|
|
|
|
|
|
|
# Mine 1 new-version blocks
|
2015-04-01 05:28:28 +02:00
|
|
|
self.nodes[2].generate(1)
|
2015-01-20 22:39:19 +01:00
|
|
|
self.sync_all()
|
|
|
|
if (self.nodes[0].getblockcount() != cnt + 1052):
|
|
|
|
raise AssertionError("Failed to mine a version=3 block")
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
BIP66Test().main()
|