MCPcopy Create free account
hub / github.com/ElementsProject/elements / run_test

Method run_test

test/functional/rpc_setban.py:21–71  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

19 return any(e['address'] == addr for e in node.listbanned())
20
21 def run_test(self):
22 # Node 0 connects to Node 1, check that the noban permission is not granted
23 self.connect_nodes(0, 1)
24 peerinfo = self.nodes[1].getpeerinfo()[0]
25 assert not "noban" in peerinfo["permissions"]
26
27 # Node 0 get banned by Node 1
28 self.nodes[1].setban("127.0.0.1", "add")
29
30 # Node 0 should not be able to reconnect
31 with self.nodes[1].assert_debug_log(expected_msgs=['dropped (banned)\n'], timeout=50):
32 self.restart_node(1, [])
33 self.nodes[0].addnode("127.0.0.1:" + str(p2p_port(1)), "onetry")
34
35 # However, node 0 should be able to reconnect if it has noban permission
36 self.restart_node(1, ['-whitelist=127.0.0.1'])
37 self.connect_nodes(0, 1)
38 peerinfo = self.nodes[1].getpeerinfo()[0]
39 assert "noban" in peerinfo["permissions"]
40
41 # If we remove the ban, Node 0 should be able to reconnect even without noban permission
42 self.nodes[1].setban("127.0.0.1", "remove")
43 self.restart_node(1, [])
44 self.connect_nodes(0, 1)
45 peerinfo = self.nodes[1].getpeerinfo()[0]
46 assert not "noban" in peerinfo["permissions"]
47
48 self.log.info("Test that a non-IP address can be banned/unbanned")
49 node = self.nodes[1]
50 tor_addr = "pg6mmjiyjmcrsslvykfwnntlaru7p5svn6y2ymmju6nubxndf4pscryd.onion"
51 ip_addr = "1.2.3.4"
52 assert not self.is_banned(node, tor_addr)
53 assert not self.is_banned(node, ip_addr)
54
55 node.setban(tor_addr, "add")
56 assert self.is_banned(node, tor_addr)
57 assert not self.is_banned(node, ip_addr)
58
59 self.log.info("Test the ban list is preserved through restart")
60
61 self.restart_node(1)
62 assert self.is_banned(node, tor_addr)
63 assert not self.is_banned(node, ip_addr)
64
65 node.setban(tor_addr, "remove")
66 assert not self.is_banned(self.nodes[1], tor_addr)
67 assert not self.is_banned(node, ip_addr)
68
69 self.restart_node(1)
70 assert not self.is_banned(node, tor_addr)
71 assert not self.is_banned(node, ip_addr)
72
73
74if __name__ == '__main__':

Callers

nothing calls this directly

Calls 6

is_bannedMethod · 0.95
p2p_portFunction · 0.90
connect_nodesMethod · 0.80
infoMethod · 0.80
assert_debug_logMethod · 0.45
restart_nodeMethod · 0.45

Tested by

no test coverage detected