mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-10 03:47:29 -03:00
Merge bitcoin/bitcoin#30453: test: Non-Shy version sender
faed5d3870
test: Non-Shy version sender (MarcoFalke) Pull request description: After `add_outbound_p2p_connection`, the test framework normally sends a version message only in reply to a received version. This is fine, but the protocol does not require this and tolerates a version to be sent earlier. However, this is untested, and the missing test coverage leads to bugs being missed. For example https://github.com/bitcoin/bitcoin/pull/30394#pullrequestreview-2166824948 Fix it by adding a test. ACKs for top commit: brunoerg: ACKfaed5d3870
tdb3: ACKfaed5d3870
theStack: tACKfaed5d3870
glozow: ACKfaed5d3870
Tree-SHA512: dbf527a39c932e994a1e8248ba78058000811a4bf69275278f1fd1e545716ac4d2d3be5dcf362976bbafa2a49f91d13e3601daf71d29e9c556179b01af62c03c
This commit is contained in:
commit
20ccb30b7a
1 changed files with 23 additions and 1 deletions
|
@ -1,5 +1,5 @@
|
|||
#!/usr/bin/env python3
|
||||
# Copyright (c) 2020-2021 The Bitcoin Core developers
|
||||
# Copyright (c) 2020-present The Bitcoin Core developers
|
||||
# Distributed under the MIT software license, see the accompanying
|
||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
"""Test add_outbound_p2p_connection test framework functionality"""
|
||||
|
@ -11,6 +11,14 @@ from test_framework.util import (
|
|||
check_node_connections,
|
||||
)
|
||||
|
||||
|
||||
class VersionSender(P2PInterface):
|
||||
def on_open(self):
|
||||
assert self.on_connection_send_msg is not None
|
||||
self.send_version()
|
||||
assert self.on_connection_send_msg is None
|
||||
|
||||
|
||||
class P2PFeelerReceiver(P2PInterface):
|
||||
def on_version(self, message):
|
||||
# The bitcoind node closes feeler connections as soon as a version
|
||||
|
@ -106,5 +114,19 @@ class P2PAddConnections(BitcoinTestFramework):
|
|||
# Feeler connections do not request tx relay
|
||||
assert_equal(feeler_conn.last_message["version"].relay, 0)
|
||||
|
||||
self.log.info("Send version message early to node")
|
||||
# Normally the test framework would be shy and send the version message
|
||||
# only after it received one. See the on_version method. Check that
|
||||
# bitcoind behaves properly when a version is sent unexpectedly (but
|
||||
# tolerably) early.
|
||||
#
|
||||
# This checks that bitcoind sends its own version prior to processing
|
||||
# the remote version (and replying with a verack). Otherwise it would
|
||||
# be violating its own rules, such as "non-version message before
|
||||
# version handshake".
|
||||
ver_conn = self.nodes[0].add_outbound_p2p_connection(VersionSender(), p2p_idx=6, connection_type="outbound-full-relay", supports_v2_p2p=False, advertise_v2_p2p=False)
|
||||
ver_conn.sync_with_ping()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
P2PAddConnections().main()
|
||||
|
|
Loading…
Reference in a new issue