mirror of
https://github.com/dashpay/dash.git
synced 2024-12-27 04:52:59 +01:00
4c8e77a48d
d841301010914203fb5ef02627c76fad99cb11f1 test: Add docstring to wait_until() in util.py to warn about its usage (Seleme Topuz) 1343c86c7cc1fc896696b3ed87c12039e4ef3a0c test: Update wait_until usage in tests not to use the one from utils (Seleme Topuz) Pull request description: Replace global (from [test_framework/util.py](https://github.com/bitcoin/bitcoin/blob/master/test/functional/test_framework/util.py#L228)) `wait_until()` usages with the ones provided by `BitcoinTestFramework` and `P2PInterface` classes. The motivation behind this change is that the `util.wait_until()` expects a timeout, timeout_factor and lock and it is not aware of the context of the test framework. `BitcoinTestFramework` offers a `wait_until()` which has an understandable amount of default `timeout` and a shared `timeout_factor`. Moreover, on top of these, `mininode.wait_until()` also has a shared lock. closes #19080 ACKs for top commit: MarcoFalke: ACK d841301010914203fb5ef02627c76fad99cb11f1 🦆 kallewoof: utACK d841301010914203fb5ef02627c76fad99cb11f1 Tree-SHA512: 81604f4cfa87fed98071a80e4afe940b3897fe65cf680a69619a93e97d45f25b313c12227de7040e19517fa9c003291b232f1b40b2567aba0148f22c23c47a88
88 lines
2.7 KiB
Python
Executable File
88 lines
2.7 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
# Copyright (c) 2020 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 addrv2 relay
|
|
"""
|
|
|
|
from test_framework.messages import (
|
|
CAddress,
|
|
msg_addrv2,
|
|
NODE_NETWORK,
|
|
)
|
|
from test_framework.p2p import P2PInterface
|
|
from test_framework.test_framework import BitcoinTestFramework
|
|
from test_framework.util import assert_equal
|
|
|
|
|
|
class AddrReceiver(P2PInterface):
|
|
addrv2_received_and_checked = False
|
|
|
|
def __init__(self):
|
|
super().__init__(support_addrv2 = True)
|
|
|
|
def on_addrv2(self, message):
|
|
for addr in message.addrs:
|
|
assert_equal(addr.nServices, 1)
|
|
assert addr.ip.startswith('123.123.123.')
|
|
assert 8333 <= addr.port < 8343
|
|
self.addrv2_received_and_checked = True
|
|
|
|
def wait_for_addrv2(self):
|
|
self.wait_until(lambda: "addrv2" in self.last_message)
|
|
|
|
|
|
class AddrTest(BitcoinTestFramework):
|
|
def set_test_params(self):
|
|
self.setup_clean_chain = True
|
|
self.num_nodes = 1
|
|
|
|
def run_test(self):
|
|
ADDRS = []
|
|
for i in range(10):
|
|
addr = CAddress()
|
|
addr.time = int(self.mocktime) + i
|
|
addr.nServices = NODE_NETWORK
|
|
addr.ip = "123.123.123.{}".format(i % 256)
|
|
addr.port = 8333 + i
|
|
ADDRS.append(addr)
|
|
|
|
self.log.info('Create connection that sends addrv2 messages')
|
|
addr_source = self.nodes[0].add_p2p_connection(P2PInterface())
|
|
|
|
msg = msg_addrv2()
|
|
|
|
self.log.info('Send too-large addrv2 message')
|
|
msg.addrs = ADDRS * 101
|
|
with self.nodes[0].assert_debug_log(['addrv2 message size = 1010']):
|
|
addr_source.send_and_ping(msg)
|
|
|
|
self.nodes[0].disconnect_p2ps()
|
|
|
|
self.log.info('Check that addrv2 message content is relayed and added to addrman')
|
|
addr_source = self.nodes[0].add_p2p_connection(P2PInterface())
|
|
addr_receiver = self.nodes[0].add_p2p_connection(AddrReceiver())
|
|
|
|
msg.addrs = ADDRS
|
|
with self.nodes[0].assert_debug_log([
|
|
'Added 10 addresses from 127.0.0.1: 0 tried',
|
|
'received: addrv2 (131 bytes) peer=1',
|
|
]):
|
|
addr_source.send_and_ping(msg)
|
|
|
|
# Wait until "Added ..." before bumping mocktime to make sure addv2 is (almost) fully processed
|
|
with self.nodes[0].assert_debug_log([
|
|
'sending addrv2 (131 bytes) peer=2',
|
|
]):
|
|
self.bump_mocktime(30 * 60)
|
|
addr_receiver.wait_for_addrv2()
|
|
|
|
assert addr_receiver.addrv2_received_and_checked
|
|
|
|
self.nodes[0].disconnect_p2ps()
|
|
|
|
|
|
if __name__ == '__main__':
|
|
AddrTest().main()
|