2 # Copyright (c) 2015-2016 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 """Test the CHECKLOCKTIMEVERIFY (BIP65) soft-fork logic."""
7 from test_framework
.test_framework
import BitcoinTestFramework
8 from test_framework
.util
import *
10 class BIP65Test(BitcoinTestFramework
):
14 self
.setup_clean_chain
= False
15 self
.extra_args
= [[], ["-blockversion=3"], ["-blockversion=4"]]
17 def setup_network(self
):
19 connect_nodes(self
.nodes
[1], 0)
20 connect_nodes(self
.nodes
[2], 0)
24 cnt
= self
.nodes
[0].getblockcount()
26 # Mine some old-version blocks
27 self
.nodes
[1].generate(200)
30 if (self
.nodes
[0].getblockcount() != cnt
+ 100):
31 raise AssertionError("Failed to mine 100 version=3 blocks")
33 # Mine 750 new-version blocks
35 self
.nodes
[2].generate(50)
37 if (self
.nodes
[0].getblockcount() != cnt
+ 850):
38 raise AssertionError("Failed to mine 750 version=4 blocks")
40 # TODO: check that new CHECKLOCKTIMEVERIFY rules are not enforced
42 # Mine 1 new-version block
43 self
.nodes
[2].generate(1)
45 if (self
.nodes
[0].getblockcount() != cnt
+ 851):
46 raise AssertionError("Failed to mine a version=4 blocks")
48 # TODO: check that new CHECKLOCKTIMEVERIFY rules are enforced
50 # Mine 198 new-version blocks
52 self
.nodes
[2].generate(99)
54 if (self
.nodes
[0].getblockcount() != cnt
+ 1049):
55 raise AssertionError("Failed to mine 198 version=4 blocks")
57 # Mine 1 old-version block
58 self
.nodes
[1].generate(1)
60 if (self
.nodes
[0].getblockcount() != cnt
+ 1050):
61 raise AssertionError("Failed to mine a version=3 block after 949 version=4 blocks")
63 # Mine 1 new-version blocks
64 self
.nodes
[2].generate(1)
66 if (self
.nodes
[0].getblockcount() != cnt
+ 1051):
67 raise AssertionError("Failed to mine a version=4 block")
69 # Mine 1 old-version blocks. This should fail
70 assert_raises_jsonrpc(-1,"CreateNewBlock: TestBlockValidity failed: bad-version(0x00000003)", self
.nodes
[1].generate
, 1)
72 if (self
.nodes
[0].getblockcount() != cnt
+ 1051):
73 raise AssertionError("Accepted a version=3 block after 950 version=4 blocks")
75 # Mine 1 new-version blocks
76 self
.nodes
[2].generate(1)
78 if (self
.nodes
[0].getblockcount() != cnt
+ 1052):
79 raise AssertionError("Failed to mine a version=4 block")
81 if __name__
== '__main__':