|
| 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() |
0 commit comments