Tests: Add simple test for getaddednodeinfo

* net.py test adds a node and sees if it's in the getaddednodeinfo call
* flake8 fixes
This commit is contained in:
Jimmy Song 2017-04-17 18:42:10 -07:00
parent 987a6c0956
commit bc53752616

View file

@ -7,15 +7,15 @@
Tests correspond to code in rpc/net.cpp. Tests correspond to code in rpc/net.cpp.
""" """
from decimal import Decimal
import time import time
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import BitcoinTestFramework
from test_framework.authproxy import JSONRPCException
from test_framework.util import ( from test_framework.util import (
assert_equal, assert_equal,
start_nodes, assert_raises_jsonrpc,
connect_nodes_bi, connect_nodes_bi,
p2p_port,
start_nodes,
) )
@ -33,7 +33,7 @@ class NetTest(BitcoinTestFramework):
def run_test(self): def run_test(self):
assert_equal(self.nodes[0].getnetworkinfo()['networkactive'], True) assert_equal(self.nodes[0].getnetworkinfo()['networkactive'], True)
assert_equal(self.nodes[0].getnetworkinfo()['connections'], 2) # bilateral connection assert_equal(self.nodes[0].getnetworkinfo()['connections'], 2)
self.nodes[0].setnetworkactive(False) self.nodes[0].setnetworkactive(False)
assert_equal(self.nodes[0].getnetworkinfo()['networkactive'], False) assert_equal(self.nodes[0].getnetworkinfo()['networkactive'], False)
@ -49,6 +49,19 @@ class NetTest(BitcoinTestFramework):
assert_equal(self.nodes[0].getnetworkinfo()['networkactive'], True) assert_equal(self.nodes[0].getnetworkinfo()['networkactive'], True)
assert_equal(self.nodes[0].getnetworkinfo()['connections'], 2) assert_equal(self.nodes[0].getnetworkinfo()['connections'], 2)
# test getaddednodeinfo
assert_equal(self.nodes[0].getaddednodeinfo(), [])
# add a node (node2) to node0
ip_port = "127.0.0.1:{}".format(p2p_port(2))
self.nodes[0].addnode(ip_port, 'add')
# check that the node has indeed been added
added_nodes = self.nodes[0].getaddednodeinfo(ip_port)
assert_equal(len(added_nodes), 1)
assert_equal(added_nodes[0]['addednode'], ip_port)
# check that a non-existant node returns an error
assert_raises_jsonrpc(-24, "Node has not been added",
self.nodes[0].getaddednodeinfo, '1.1.1.1')
if __name__ == '__main__': if __name__ == '__main__':
NetTest().main() NetTest().main()