Skip to content

Commit d117f45

Browse files
committed
Add test for setban
1 parent dc7529a commit d117f45

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

test/functional/rpc_setban.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env python3
2+
# Copyright (c) 2015-2019 The Bitcoin Core developers
3+
# Distributed under the MIT software license, see the accompanying
4+
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5+
"""Test the setban rpc call."""
6+
7+
from test_framework.test_framework import BitcoinTestFramework
8+
from test_framework.util import (
9+
connect_nodes,
10+
p2p_port
11+
)
12+
13+
class SetBanTests(BitcoinTestFramework):
14+
def set_test_params(self):
15+
self.num_nodes = 2
16+
self.setup_clean_chain = True
17+
self.extra_args = [[],[]]
18+
19+
def run_test(self):
20+
# Node 0 connects to Node 1, check that the noban permission is not granted
21+
connect_nodes(self.nodes[0], 1)
22+
peerinfo = self.nodes[1].getpeerinfo()[0]
23+
assert(not 'noban' in peerinfo['permissions'])
24+
25+
# Node 0 get banned by Node 1
26+
self.nodes[1].setban("127.0.0.1", "add")
27+
28+
# Node 0 should not be able to reconnect
29+
with self.nodes[1].assert_debug_log(expected_msgs=['dropped (banned)\n']):
30+
self.restart_node(1, [])
31+
self.nodes[0].addnode("127.0.0.1:" + str(p2p_port(1)), "onetry")
32+
33+
# However, node 0 should be able to reconnect if it has noban permission
34+
self.restart_node(1, ['-whitelist=127.0.0.1'])
35+
connect_nodes(self.nodes[0], 1)
36+
peerinfo = self.nodes[1].getpeerinfo()[0]
37+
assert('noban' in peerinfo['permissions'])
38+
39+
# If we remove the ban, Node 0 should be able to reconnect even without noban permission
40+
self.nodes[1].setban("127.0.0.1", "remove")
41+
self.restart_node(1, [])
42+
connect_nodes(self.nodes[0], 1)
43+
peerinfo = self.nodes[1].getpeerinfo()[0]
44+
assert(not 'noban' in peerinfo['permissions'])
45+
46+
if __name__ == '__main__':
47+
SetBanTests().main()

test/functional/test_runner.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@
144144
'rpc_net.py',
145145
'wallet_keypool.py',
146146
'p2p_mempool.py',
147+
'rpc_setban.py',
147148
'p2p_blocksonly.py',
148149
'mining_prioritisetransaction.py',
149150
'p2p_invalid_locator.py',

test/lint/lint-spelling.ignore-words.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ cachable
1212
errorstring
1313
keyserver
1414
homogenous
15+
setban

0 commit comments

Comments
 (0)