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.
7 # Test the CHECKLOCKTIMEVERIFY (BIP65) soft-fork logic
10 from test_framework
.test_framework
import BitcoinTestFramework
11 from test_framework
.util
import *
13 class BIP65Test(BitcoinTestFramework
):
17 self
.setup_clean_chain
= False
19 def setup_network(self
):
21 self
.nodes
.append(start_node(0, self
.options
.tmpdir
, []))
22 self
.nodes
.append(start_node(1, self
.options
.tmpdir
, ["-blockversion=3"]))
23 self
.nodes
.append(start_node(2, self
.options
.tmpdir
, ["-blockversion=4"]))
24 connect_nodes(self
.nodes
[1], 0)
25 connect_nodes(self
.nodes
[2], 0)
26 self
.is_network_split
= False
30 cnt
= self
.nodes
[0].getblockcount()
32 # Mine some old-version blocks
33 self
.nodes
[1].generate(200)
36 if (self
.nodes
[0].getblockcount() != cnt
+ 100):
37 raise AssertionError("Failed to mine 100 version=3 blocks")
39 # Mine 750 new-version blocks
41 self
.nodes
[2].generate(50)
43 if (self
.nodes
[0].getblockcount() != cnt
+ 850):
44 raise AssertionError("Failed to mine 750 version=4 blocks")
46 # TODO: check that new CHECKLOCKTIMEVERIFY rules are not enforced
48 # Mine 1 new-version block
49 self
.nodes
[2].generate(1)
51 if (self
.nodes
[0].getblockcount() != cnt
+ 851):
52 raise AssertionError("Failed to mine a version=4 blocks")
54 # TODO: check that new CHECKLOCKTIMEVERIFY rules are enforced
56 # Mine 198 new-version blocks
58 self
.nodes
[2].generate(99)
60 if (self
.nodes
[0].getblockcount() != cnt
+ 1049):
61 raise AssertionError("Failed to mine 198 version=4 blocks")
63 # Mine 1 old-version block
64 self
.nodes
[1].generate(1)
66 if (self
.nodes
[0].getblockcount() != cnt
+ 1050):
67 raise AssertionError("Failed to mine a version=3 block after 949 version=4 blocks")
69 # Mine 1 new-version blocks
70 self
.nodes
[2].generate(1)
72 if (self
.nodes
[0].getblockcount() != cnt
+ 1051):
73 raise AssertionError("Failed to mine a version=4 block")
75 # Mine 1 old-version blocks
77 self
.nodes
[1].generate(1)
78 raise AssertionError("Succeeded to mine a version=3 block after 950 version=4 blocks")
79 except JSONRPCException
:
82 if (self
.nodes
[0].getblockcount() != cnt
+ 1051):
83 raise AssertionError("Accepted a version=3 block after 950 version=4 blocks")
85 # Mine 1 new-version blocks
86 self
.nodes
[2].generate(1)
88 if (self
.nodes
[0].getblockcount() != cnt
+ 1052):
89 raise AssertionError("Failed to mine a version=4 block")
91 if __name__
== '__main__':