-
Notifications
You must be signed in to change notification settings - Fork 2
/
abc-rpc.py
executable file
·82 lines (67 loc) · 3.16 KB
/
abc-rpc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env python3
# Copyright (c) 2017 The Bitcoin developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
# Exercise the Bitcoin ABC RPC calls.
import time
import random
import re
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import (assert_equal, assert_raises_rpc_error)
from test_framework.cdefs import (ONE_MEGABYTE,
LEGACY_MAX_BLOCK_SIZE,
DEFAULT_MAX_BLOCK_SIZE)
class ABC_RPC_Test (BitcoinTestFramework):
def set_test_params(self):
self.num_nodes = 3
self.tip = None
self.setup_clean_chain = True
self.extra_args = [ [] for i in range(self.num_nodes)]
def check_subversion(self, pattern_str):
# Check that the subversion is set as expected
netinfo = self.nodes[0].getnetworkinfo()
subversion = netinfo['subversion']
pattern = re.compile(pattern_str)
assert(pattern.match(subversion))
def test_excessiveblock(self):
# Check that we start with DEFAULT_MAX_BLOCK_SIZE
getsize = self.nodes[0].getexcessiveblock()
ebs = getsize['excessiveBlockSize']
assert_equal(ebs, DEFAULT_MAX_BLOCK_SIZE)
# Check that setting to legacy size is ok
self.nodes[0].setexcessiveblock(LEGACY_MAX_BLOCK_SIZE + 1)
getsize = self.nodes[0].getexcessiveblock()
ebs = getsize['excessiveBlockSize']
assert_equal(ebs, LEGACY_MAX_BLOCK_SIZE + 1)
# Check that going below legacy size is not accepted
assert_raises_rpc_error(-8, "Invalid parameter, excessiveblock must be larger than %d" %
LEGACY_MAX_BLOCK_SIZE, self.nodes[0].setexcessiveblock, LEGACY_MAX_BLOCK_SIZE)
getsize = self.nodes[0].getexcessiveblock()
ebs = getsize['excessiveBlockSize']
assert_equal(ebs, LEGACY_MAX_BLOCK_SIZE + 1)
# Check setting to 2MB
self.nodes[0].setexcessiveblock(2 * ONE_MEGABYTE)
getsize = self.nodes[0].getexcessiveblock()
ebs = getsize['excessiveBlockSize']
assert_equal(ebs, 2 * ONE_MEGABYTE)
# Check for EB correctness in the subver string
self.check_subversion("/Copernicus:[\d\.]+\(.*\)/")
# Check setting to 13MB
self.nodes[0].setexcessiveblock(13 * ONE_MEGABYTE)
getsize = self.nodes[0].getexcessiveblock()
ebs = getsize['excessiveBlockSize']
assert_equal(ebs, 13 * ONE_MEGABYTE)
# Check for EB correctness in the subver string
self.check_subversion("/Copernicus:[\d\.]+\(.*\)/")
# Check setting to 13.14MB
self.nodes[0].setexcessiveblock(13140000)
getsize = self.nodes[0].getexcessiveblock()
ebs = getsize['excessiveBlockSize']
assert_equal(ebs, 13.14 * ONE_MEGABYTE)
# check for EB correctness in the subver string
self.check_subversion("/Copernicus:[\d\.]+\(.*\)/")
def run_test(self):
self.genesis_hash = int(self.nodes[0].getbestblockhash(), 16)
self.test_excessiveblock()
if __name__ == '__main__':
ABC_RPC_Test().main()