diff options
author | Dhruv Mehta <856960+dhruv@users.noreply.github.com> | 2020-08-16 17:08:44 -0700 |
---|---|---|
committer | Dhruv Mehta <856960+dhruv@users.noreply.github.com> | 2020-08-18 13:13:19 -0700 |
commit | ed5cd12869e0691a785199d2d977ce5879095180 (patch) | |
tree | 0830e1c995828c5df35db23beb4680daa44dbea2 /test/functional | |
parent | f6f082b9343522bc8005f23937ac6ecf56548c98 (diff) |
test: Distinguish between nodes(bitcoind) and peers(mininodes) in p2p_leak.py
Also, remove "C" prefix from class names to match new style
Diffstat (limited to 'test/functional')
-rwxr-xr-x | test/functional/p2p_leak.py | 51 |
1 files changed, 25 insertions, 26 deletions
diff --git a/test/functional/p2p_leak.py b/test/functional/p2p_leak.py index 23152c9dcf..79bf7b2e7c 100755 --- a/test/functional/p2p_leak.py +++ b/test/functional/p2p_leak.py @@ -28,7 +28,7 @@ from test_framework.util import ( DISCOURAGEMENT_THRESHOLD = 100 -class CLazyNode(P2PInterface): +class LazyPeer(P2PInterface): def __init__(self): super().__init__() self.unexpected_msg = False @@ -64,8 +64,8 @@ class CLazyNode(P2PInterface): def on_blocktxn(self, message): self.bad_message(message) -# Node that sends a version but not a verack. -class CNodeNoVerackIdle(CLazyNode): +# Peer that sends a version but not a verack. +class NoVerackIdlePeer(LazyPeer): def __init__(self): self.version_received = False super().__init__() @@ -95,45 +95,44 @@ class P2PLeakTest(BitcoinTestFramework): def run_test(self): # Peer that never sends a version. We will send a bunch of messages - # from this node anyway and verify eventual disconnection. - no_version_disconnect_node = self.nodes[0].add_p2p_connection( - CLazyNode(), send_version=False, wait_for_verack=False) + # from this peer anyway and verify eventual disconnection. + no_version_disconnect_peer = self.nodes[0].add_p2p_connection( + LazyPeer(), send_version=False, wait_for_verack=False) - # Another peer that never sends a version. Just sits idle and hopes to receive - # any message (it shouldn't!) - no_version_idlenode = self.nodes[0].add_p2p_connection(CLazyNode(), send_version=False, wait_for_verack=False) + # Another peer that never sends a version, nor any other messages. It shouldn't receive anything from the node. + no_version_idle_peer = self.nodes[0].add_p2p_connection(LazyPeer(), send_version=False, wait_for_verack=False) # Peer that sends a version but not a verack. - no_verack_idlenode = self.nodes[0].add_p2p_connection(CNodeNoVerackIdle(), wait_for_verack=False) + no_verack_idle_peer = self.nodes[0].add_p2p_connection(NoVerackIdlePeer(), wait_for_verack=False) # Send enough ping messages (any non-version message will do) prior to sending # version to reach the peer discouragement threshold. This should get us disconnected. for _ in range(DISCOURAGEMENT_THRESHOLD): - no_version_disconnect_node.send_message(msg_ping()) + no_version_disconnect_peer.send_message(msg_ping()) - # Wait until we got the verack in response to the version. Though, don't wait for self.nodes[0] to receive the + # Wait until we got the verack in response to the version. Though, don't wait for the node to receive the # verack, since we never sent one - no_verack_idlenode.wait_for_verack() + no_verack_idle_peer.wait_for_verack() - wait_until(lambda: no_version_disconnect_node.ever_connected, timeout=10, lock=mininode_lock) - wait_until(lambda: no_version_idlenode.ever_connected, timeout=10, lock=mininode_lock) - wait_until(lambda: no_verack_idlenode.version_received, timeout=10, lock=mininode_lock) + wait_until(lambda: no_version_disconnect_peer.ever_connected, timeout=10, lock=mininode_lock) + wait_until(lambda: no_version_idle_peer.ever_connected, timeout=10, lock=mininode_lock) + wait_until(lambda: no_verack_idle_peer.version_received, timeout=10, lock=mininode_lock) - # Mine a block and make sure that it's not sent to the connected nodes + # Mine a block and make sure that it's not sent to the connected peers self.nodes[0].generate(nblocks=1) #Give the node enough time to possibly leak out a message time.sleep(5) - # Expect this node to be disconnected for misbehavior - assert not no_version_disconnect_node.is_connected + # Expect this peer to be disconnected for misbehavior + assert not no_version_disconnect_peer.is_connected self.nodes[0].disconnect_p2ps() # Make sure no unexpected messages came in - assert no_version_disconnect_node.unexpected_msg == False - assert no_version_idlenode.unexpected_msg == False - assert no_verack_idlenode.unexpected_msg == False + assert no_version_disconnect_peer.unexpected_msg == False + assert no_version_idle_peer.unexpected_msg == False + assert no_verack_idle_peer.unexpected_msg == False self.log.info('Check that the version message does not leak the local address of the node') p2p_version_store = self.nodes[0].add_p2p_connection(P2PVersionStore()) @@ -146,13 +145,13 @@ class P2PLeakTest(BitcoinTestFramework): assert_equal(ver.nStartingHeight, 201) assert_equal(ver.nRelay, 1) - self.log.info('Check that old nodes are disconnected') - p2p_old_node = self.nodes[0].add_p2p_connection(P2PInterface(), send_version=False, wait_for_verack=False) + self.log.info('Check that old peers are disconnected') + p2p_old_peer = self.nodes[0].add_p2p_connection(P2PInterface(), send_version=False, wait_for_verack=False) old_version_msg = msg_version() old_version_msg.nVersion = 31799 with self.nodes[0].assert_debug_log(['peer=4 using obsolete version 31799; disconnecting']): - p2p_old_node.send_message(old_version_msg) - p2p_old_node.wait_for_disconnect() + p2p_old_peer.send_message(old_version_msg) + p2p_old_peer.wait_for_disconnect() if __name__ == '__main__': |