|
3 | 3 | # Distributed under the MIT software license, see the accompanying
|
4 | 4 | # file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
5 | 5 | """Test node disconnect and ban behavior"""
|
| 6 | +import time |
6 | 7 |
|
7 | 8 | from test_framework.mininode import wait_until
|
8 | 9 | from test_framework.test_framework import BitcoinTestFramework
|
@@ -56,11 +57,16 @@ def run_test(self):
|
56 | 57 | self.log.info("setban: test persistence across node restart")
|
57 | 58 | self.nodes[1].setban("127.0.0.0/32", "add")
|
58 | 59 | self.nodes[1].setban("127.0.0.0/24", "add")
|
| 60 | + # Set the mocktime so we can control when bans expire |
| 61 | + old_time = int(time.time()) |
| 62 | + self.nodes[1].setmocktime(old_time) |
59 | 63 | self.nodes[1].setban("192.168.0.1", "add", 1) # ban for 1 seconds
|
60 | 64 | self.nodes[1].setban("2001:4d48:ac57:400:cacf:e9ff:fe1d:9c63/19", "add", 1000) # ban for 1000 seconds
|
61 | 65 | listBeforeShutdown = self.nodes[1].listbanned()
|
62 | 66 | assert_equal("192.168.0.1/32", listBeforeShutdown[2]['address'])
|
63 |
| - assert wait_until(lambda: len(self.nodes[1].listbanned()) == 3, timeout=10) |
| 67 | + # Move time forward by 3 seconds so the third ban has expired |
| 68 | + self.nodes[1].setmocktime(old_time + 3) |
| 69 | + assert_equal(len(self.nodes[1].listbanned()), 3) |
64 | 70 |
|
65 | 71 | stop_node(self.nodes[1], 1)
|
66 | 72 |
|
|
0 commit comments