Skip to content

Commit bc53752

Browse files
committed
Tests: Add simple test for getaddednodeinfo
* net.py test adds a node and sees if it's in the getaddednodeinfo call * flake8 fixes
1 parent 987a6c0 commit bc53752

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

test/functional/net.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
Tests correspond to code in rpc/net.cpp.
88
"""
99

10-
from decimal import Decimal
1110
import time
1211

1312
from test_framework.test_framework import BitcoinTestFramework
14-
from test_framework.authproxy import JSONRPCException
1513
from test_framework.util import (
1614
assert_equal,
17-
start_nodes,
15+
assert_raises_jsonrpc,
1816
connect_nodes_bi,
17+
p2p_port,
18+
start_nodes,
1919
)
2020

2121

@@ -33,7 +33,7 @@ def setup_network(self):
3333

3434
def run_test(self):
3535
assert_equal(self.nodes[0].getnetworkinfo()['networkactive'], True)
36-
assert_equal(self.nodes[0].getnetworkinfo()['connections'], 2) # bilateral connection
36+
assert_equal(self.nodes[0].getnetworkinfo()['connections'], 2)
3737

3838
self.nodes[0].setnetworkactive(False)
3939
assert_equal(self.nodes[0].getnetworkinfo()['networkactive'], False)
@@ -49,6 +49,19 @@ def run_test(self):
4949
assert_equal(self.nodes[0].getnetworkinfo()['networkactive'], True)
5050
assert_equal(self.nodes[0].getnetworkinfo()['connections'], 2)
5151

52+
# test getaddednodeinfo
53+
assert_equal(self.nodes[0].getaddednodeinfo(), [])
54+
# add a node (node2) to node0
55+
ip_port = "127.0.0.1:{}".format(p2p_port(2))
56+
self.nodes[0].addnode(ip_port, 'add')
57+
# check that the node has indeed been added
58+
added_nodes = self.nodes[0].getaddednodeinfo(ip_port)
59+
assert_equal(len(added_nodes), 1)
60+
assert_equal(added_nodes[0]['addednode'], ip_port)
61+
# check that a non-existant node returns an error
62+
assert_raises_jsonrpc(-24, "Node has not been added",
63+
self.nodes[0].getaddednodeinfo, '1.1.1.1')
64+
5265

5366
if __name__ == '__main__':
5467
NetTest().main()

0 commit comments

Comments
 (0)