forked from DogecoinEV-Foundation/DogecoinEV
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddnode.py
More file actions
67 lines (54 loc) · 2.24 KB
/
addnode.py
File metadata and controls
67 lines (54 loc) · 2.24 KB
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
#!/usr/bin/env python3
# Copyright (c) 2021-2022 The Dogecoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Addnode QA test.
# Tests the addnode command
"""
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import *
class AddnodeTest(BitcoinTestFramework):
def __init__(self):
super().__init__()
self.setup_clean_chain = True
self.num_nodes = 1
self.counter = 0
def setup_network(self, split=False):
self.nodes = []
self.nodes.append(start_node(0, self.options.tmpdir, []))
self.is_network_split=False
self.sync_all()
def get_next_dummy_address(self):
self.counter += 1
assert self.counter < 256 ** 2 # Don't allow the returned ip addresses to wrap.
return f"123.123.{self.counter // 256}.{self.counter % 256}:{10000 + self.counter}"
def run_test(self):
node = self.nodes[0]
# mine a block
node.generate(1)
# add one address
first_addr = self.get_next_dummy_address()
node.addnode(first_addr, 'add')
# try adding it again
try:
node.addnode(first_addr, 'add')
raise AssertionError("Must reject an existing addnode")
except JSONRPCException as e:
assert("Error: Unable to add node" in e.error["message"])
# add 799 valid addresses - must not throw an error
for i in range((8 * 100) - 1):
node.addnode(self.get_next_dummy_address(), 'add')
# add one more address
try:
node.addnode(self.get_next_dummy_address(), 'add')
raise AssertionError("Must reject when more than 800 addnode entries exist")
except JSONRPCException as e:
assert("Error: Unable to add node" in e.error["message"])
# try adding a large string domain
try:
node.addnode(f'{"manybigstr" * 25}.domain:10020', 'add')
raise AssertionError("Must reject large strings")
except JSONRPCException as e:
assert("Error: Node address is invalid" in e.error["message"])
if __name__ == '__main__':
AddnodeTest().main()