Skip to content

Commit 2077fda

Browse files
committed
[tests] disconnect_ban: add logging
1 parent 395561b commit 2077fda

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

test/functional/disconnect_ban.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,32 +27,39 @@ def setup_network(self):
2727
connect_nodes_bi(self.nodes, 0, 1)
2828

2929
def run_test(self):
30-
###########################
31-
# setban/listbanned tests #
32-
###########################
30+
self.log.info("Test setban and listbanned RPCs")
31+
32+
self.log.info("setban: successfully ban single IP address")
3333
assert_equal(len(self.nodes[1].getpeerinfo()), 2) # node1 should have 2 connections to node0 at this point
3434
self.nodes[1].setban("127.0.0.1", "add")
3535
time.sleep(3) # wait till the nodes are disconected
3636
assert_equal(len(self.nodes[1].getpeerinfo()), 0) # all nodes must be disconnected at this point
3737
assert_equal(len(self.nodes[1].listbanned()), 1)
38+
39+
self.log.info("clearbanned: successfully clear ban list")
3840
self.nodes[1].clearbanned()
3941
assert_equal(len(self.nodes[1].listbanned()), 0)
4042
self.nodes[1].setban("127.0.0.0/24", "add")
43+
44+
self.log.info("setban: fail to ban an already banned subnet")
4145
assert_equal(len(self.nodes[1].listbanned()), 1)
42-
# This will throw an exception because 127.0.0.1 is within range 127.0.0.0/24
4346
assert_raises_jsonrpc(-23, "IP/Subnet already banned", self.nodes[1].setban, "127.0.0.1", "add")
44-
# This will throw an exception because 127.0.0.1/42 is not a real subnet
47+
48+
self.log.info("setban: fail to ban an invalid subnet")
4549
assert_raises_jsonrpc(-30, "Error: Invalid IP/Subnet", self.nodes[1].setban, "127.0.0.1/42", "add")
4650
assert_equal(len(self.nodes[1].listbanned()), 1) # still only one banned ip because 127.0.0.1 is within the range of 127.0.0.0/24
47-
# This will throw an exception because 127.0.0.1 was not added above
51+
52+
self.log.info("setban remove: fail to unban a non-banned subnet")
4853
assert_raises_jsonrpc(-30, "Error: Unban failed", self.nodes[1].setban, "127.0.0.1", "remove")
4954
assert_equal(len(self.nodes[1].listbanned()), 1)
55+
56+
self.log.info("setban remove: successfully unban subnet")
5057
self.nodes[1].setban("127.0.0.0/24", "remove")
5158
assert_equal(len(self.nodes[1].listbanned()), 0)
5259
self.nodes[1].clearbanned()
5360
assert_equal(len(self.nodes[1].listbanned()), 0)
5461

55-
# test persisted banlist
62+
self.log.info("setban: test persistence across node restart")
5663
self.nodes[1].setban("127.0.0.0/32", "add")
5764
self.nodes[1].setban("127.0.0.0/24", "add")
5865
self.nodes[1].setban("192.168.0.1", "add", 1) # ban for 1 seconds
@@ -74,15 +81,16 @@ def run_test(self):
7481
self.nodes[1].clearbanned()
7582
connect_nodes_bi(self.nodes, 0, 1)
7683

77-
###########################
78-
# RPC disconnectnode test #
79-
###########################
84+
self.log.info("Test disconnectrnode RPCs")
85+
86+
self.log.info("disconnectnode: successfully disconnect node")
8087
url = urllib.parse.urlparse(self.nodes[1].url)
8188
self.nodes[0].disconnectnode(url.hostname + ":" + str(p2p_port(1)))
8289
time.sleep(2) # disconnecting a node needs a little bit of time
8390
for node in self.nodes[0].getpeerinfo():
8491
assert(node['addr'] != url.hostname + ":" + str(p2p_port(1)))
8592

93+
self.log.info("disconnectnode: successfully reconnect node")
8694
connect_nodes_bi(self.nodes, 0, 1) # reconnect the node
8795
found = False
8896
for node in self.nodes[0].getpeerinfo():

0 commit comments

Comments
 (0)