add test for -walletrejectlongchains
[bitcoinplatinum.git] / qa / rpc-tests / bip65-cltv.py
blobbaa77b92a05bbfb69551245021bf9248bf2708c2
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.
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):
14 def __init__(self):
15 super().__init__()
16 self.num_nodes = 3
17 self.setup_clean_chain = False
19 def setup_network(self):
20 self.nodes = []
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
27 self.sync_all()
29 def run_test(self):
30 cnt = self.nodes[0].getblockcount()
32 # Mine some old-version blocks
33 self.nodes[1].generate(200)
34 cnt += 100
35 self.sync_all()
36 if (self.nodes[0].getblockcount() != cnt + 100):
37 raise AssertionError("Failed to mine 100 version=3 blocks")
39 # Mine 750 new-version blocks
40 for i in range(15):
41 self.nodes[2].generate(50)
42 self.sync_all()
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)
50 self.sync_all()
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
57 for i in range(2):
58 self.nodes[2].generate(99)
59 self.sync_all()
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)
65 self.sync_all()
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)
71 self.sync_all()
72 if (self.nodes[0].getblockcount() != cnt + 1051):
73 raise AssertionError("Failed to mine a version=4 block")
75 # Mine 1 old-version blocks
76 try:
77 self.nodes[1].generate(1)
78 raise AssertionError("Succeeded to mine a version=3 block after 950 version=4 blocks")
79 except JSONRPCException:
80 pass
81 self.sync_all()
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)
87 self.sync_all()
88 if (self.nodes[0].getblockcount() != cnt + 1052):
89 raise AssertionError("Failed to mine a version=4 block")
91 if __name__ == '__main__':
92 BIP65Test().main()