7
7
Tests correspond to code in rpc/net.cpp.
8
8
"""
9
9
10
- from decimal import Decimal
11
10
import time
12
11
13
12
from test_framework .test_framework import BitcoinTestFramework
14
- from test_framework .authproxy import JSONRPCException
15
13
from test_framework .util import (
16
14
assert_equal ,
17
- start_nodes ,
15
+ assert_raises_jsonrpc ,
18
16
connect_nodes_bi ,
17
+ p2p_port ,
18
+ start_nodes ,
19
19
)
20
20
21
21
@@ -33,7 +33,7 @@ def setup_network(self):
33
33
34
34
def run_test (self ):
35
35
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 )
37
37
38
38
self .nodes [0 ].setnetworkactive (False )
39
39
assert_equal (self .nodes [0 ].getnetworkinfo ()['networkactive' ], False )
@@ -49,6 +49,19 @@ def run_test(self):
49
49
assert_equal (self .nodes [0 ].getnetworkinfo ()['networkactive' ], True )
50
50
assert_equal (self .nodes [0 ].getnetworkinfo ()['connections' ], 2 )
51
51
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
+
52
65
53
66
if __name__ == '__main__' :
54
67
NetTest ().main ()
0 commit comments