mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-10 10:52:31 -05:00
[test] Add tests for addr relay in -blocksonly mode
Co-Authored-By: Martin Zumsande <mzumsande@gmail.com>
This commit is contained in:
parent
a6694eaed8
commit
a732ee353c
1 changed files with 23 additions and 0 deletions
|
@ -59,6 +59,7 @@ class AddrTest(BitcoinTestFramework):
|
||||||
self.oversized_addr_test()
|
self.oversized_addr_test()
|
||||||
self.relay_tests()
|
self.relay_tests()
|
||||||
self.getaddr_tests()
|
self.getaddr_tests()
|
||||||
|
self.blocksonly_mode_tests()
|
||||||
|
|
||||||
def setup_addr_msg(self, num):
|
def setup_addr_msg(self, num):
|
||||||
addrs = []
|
addrs = []
|
||||||
|
@ -167,6 +168,7 @@ class AddrTest(BitcoinTestFramework):
|
||||||
self.log.info('Check that we answer getaddr messages only from inbound peers')
|
self.log.info('Check that we answer getaddr messages only from inbound peers')
|
||||||
inbound_peer = self.nodes[0].add_p2p_connection(GetAddrStore())
|
inbound_peer = self.nodes[0].add_p2p_connection(GetAddrStore())
|
||||||
inbound_peer.sync_with_ping()
|
inbound_peer.sync_with_ping()
|
||||||
|
|
||||||
# Add some addresses to addrman
|
# Add some addresses to addrman
|
||||||
for i in range(1000):
|
for i in range(1000):
|
||||||
first_octet = i >> 8
|
first_octet = i >> 8
|
||||||
|
@ -188,6 +190,27 @@ class AddrTest(BitcoinTestFramework):
|
||||||
|
|
||||||
self.nodes[0].disconnect_p2ps()
|
self.nodes[0].disconnect_p2ps()
|
||||||
|
|
||||||
|
def blocksonly_mode_tests(self):
|
||||||
|
self.log.info('Test addr relay in -blocksonly mode')
|
||||||
|
self.restart_node(0, ["-blocksonly"])
|
||||||
|
self.mocktime = int(time.time())
|
||||||
|
|
||||||
|
self.log.info('Check that we send getaddr messages')
|
||||||
|
full_outbound_peer = self.nodes[0].add_outbound_p2p_connection(GetAddrStore(), p2p_idx=0, connection_type="outbound-full-relay")
|
||||||
|
full_outbound_peer.sync_with_ping()
|
||||||
|
assert full_outbound_peer.getaddr_received
|
||||||
|
|
||||||
|
self.log.info('Check that we relay address messages')
|
||||||
|
addr_source = self.nodes[0].add_p2p_connection(P2PInterface())
|
||||||
|
msg = self.setup_addr_msg(2)
|
||||||
|
addr_source.send_and_ping(msg)
|
||||||
|
self.mocktime += 5 * 60
|
||||||
|
self.nodes[0].setmocktime(self.mocktime)
|
||||||
|
full_outbound_peer.sync_with_ping()
|
||||||
|
assert_equal(full_outbound_peer.num_ipv4_received, 2)
|
||||||
|
|
||||||
|
self.nodes[0].disconnect_p2ps()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
AddrTest().main()
|
AddrTest().main()
|
||||||
|
|
Loading…
Add table
Reference in a new issue