scripted-diff: Use the C++11 keyword nullptr to denote the pointer literal instead...
[bitcoinplatinum.git] / test / functional / bip65-cltv.py
blobddf932c74606b4cb1c1f2942d1b41863cd416b58
1 #!/usr/bin/env python3
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):
11 def __init__(self):
12 super().__init__()
13 self.num_nodes = 3
14 self.setup_clean_chain = False
15 self.extra_args = [[], ["-blockversion=3"], ["-blockversion=4"]]
17 def setup_network(self):
18 self.setup_nodes()
19 connect_nodes(self.nodes[1], 0)
20 connect_nodes(self.nodes[2], 0)
21 self.sync_all()
23 def run_test(self):
24 cnt = self.nodes[0].getblockcount()
26 # Mine some old-version blocks
27 self.nodes[1].generate(200)
28 cnt += 100
29 self.sync_all()
30 if (self.nodes[0].getblockcount() != cnt + 100):
31 raise AssertionError("Failed to mine 100 version=3 blocks")
33 # Mine 750 new-version blocks
34 for i in range(15):
35 self.nodes[2].generate(50)
36 self.sync_all()
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)
44 self.sync_all()
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
51 for i in range(2):
52 self.nodes[2].generate(99)
53 self.sync_all()
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)
59 self.sync_all()
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)
65 self.sync_all()
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)
71 self.sync_all()
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)
77 self.sync_all()
78 if (self.nodes[0].getblockcount() != cnt + 1052):
79 raise AssertionError("Failed to mine a version=4 block")
81 if __name__ == '__main__':
82 BIP65Test().main()