mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-03 09:43:55 +02:00
test: Stricter checks in rpc_setban.py
Make the checks stricter and easier to follow: * Fix a typo. * After the first ban from node 1 wait until node 0 "sees" the ban. * Move the restart_node out of the debug log context, to avoid bloat. * Removed the timeout from the outer/lower exit stack to check "dropped (banned)\n" on node 1, because the inner/top exit stack waits longer. * The inner/top exit stack checks for the both disconnections peer=2 and possibly peer=3 (for v2->v1 retry). * And finally, add a redundant assert to confirm once more that node 0 is has "seen" the ban.
This commit is contained in:
@@ -26,19 +26,28 @@ class SetBanTests(BitcoinTestFramework):
|
|||||||
peerinfo = self.nodes[1].getpeerinfo()[0]
|
peerinfo = self.nodes[1].getpeerinfo()[0]
|
||||||
assert "noban" not in peerinfo["permissions"]
|
assert "noban" not in peerinfo["permissions"]
|
||||||
|
|
||||||
# Node 0 get banned by Node 1
|
# Node 0 gets banned by Node 1
|
||||||
self.nodes[1].setban("127.0.0.1", "add")
|
self.nodes[1].setban("127.0.0.1", "add")
|
||||||
|
self.wait_until(lambda: not self.nodes[0].is_connected_to(self.nodes[1]))
|
||||||
|
|
||||||
# Node 0 should not be able to reconnect
|
# Node 0 should not be able to reconnect
|
||||||
|
self.restart_node(1, [])
|
||||||
context = ExitStack()
|
context = ExitStack()
|
||||||
context.enter_context(self.nodes[1].assert_debug_log(expected_msgs=['dropped (banned)\n'], timeout=50))
|
context.enter_context(self.nodes[1].assert_debug_log(expected_msgs=["dropped (banned)\n"]))
|
||||||
# When disconnected right after connecting, a v2 node will attempt to reconnect with v1.
|
# When disconnected right after connecting, a v2 node will attempt to reconnect with v1.
|
||||||
# Wait for that to happen so that it cannot mess with later tests.
|
# Wait for all disconnects on node0, so that it cannot mess with later tests.
|
||||||
if self.options.v2transport:
|
context.enter_context(self.nodes[0].assert_debug_log(
|
||||||
context.enter_context(self.nodes[0].assert_debug_log(expected_msgs=['trying v1 connection'], timeout=50))
|
expected_msgs=[
|
||||||
|
"retrying with v1 transport protocol for peer=2",
|
||||||
|
"Cleared nodestate for peer=2",
|
||||||
|
"Cleared nodestate for peer=3",
|
||||||
|
] if self.options.v2transport else [
|
||||||
|
"Cleared nodestate for peer=2", # Just one v1 disconnect to wait for
|
||||||
|
],
|
||||||
|
timeout=8))
|
||||||
with context:
|
with context:
|
||||||
self.restart_node(1, [])
|
|
||||||
self.nodes[0].addnode("127.0.0.1:" + str(p2p_port(1)), "onetry")
|
self.nodes[0].addnode("127.0.0.1:" + str(p2p_port(1)), "onetry")
|
||||||
|
assert not self.nodes[0].is_connected_to(self.nodes[1])
|
||||||
|
|
||||||
# However, node 0 should be able to reconnect if it has noban permission
|
# However, node 0 should be able to reconnect if it has noban permission
|
||||||
self.restart_node(1, ['-whitelist=127.0.0.1'])
|
self.restart_node(1, ['-whitelist=127.0.0.1'])
|
||||||
|
|||||||
Reference in New Issue
Block a user