Skip to content

Commit 9c08719

Browse files
[test] Introduce test logic to query DNS seeds
This commit introduces a DNS seed to the regest chain params in order to add coverage to the DNS querying logic. The first test checks that we do not query DNS seeds if we are able to succesfully connect to 2 outbound connections. Since we participate in ADDR relay with those connections, including sending a GETADDR message during the VERSION handshake, querying the DNS seeds is unnecessary. Co-authored-by: Martin Zumsande <[email protected]>
1 parent b295395 commit 9c08719

File tree

4 files changed

+40
-3
lines changed

4 files changed

+40
-3
lines changed

src/chainparams.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,8 @@ class CRegTestParams : public CChainParams {
435435
assert(genesis.hashMerkleRoot == uint256S("0x4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"));
436436

437437
vFixedSeeds.clear(); //!< Regtest mode doesn't have any fixed seeds.
438-
vSeeds.clear(); //!< Regtest mode doesn't have any DNS seeds.
438+
vSeeds.clear();
439+
vSeeds.emplace_back("dummySeed.invalid.");
439440

440441
fDefaultConsistencyChecks = true;
441442
fRequireStandard = true;

test/functional/feature_config_args.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,9 @@ def test_seed_peers(self):
158158
self.stop_node(0)
159159

160160
# No peers.dat exists and -dnsseed=1
161-
# We expect the node will use DNS Seeds, but Regtest mode has 0 DNS seeds
162-
# So after 60 seconds, the node should fallback to fixed seeds (this is a slow test)
161+
# We expect the node will use DNS Seeds, but Regtest mode does not have
162+
# any valid DNS seeds. So after 60 seconds, the node should fallback to
163+
# fixed seeds
163164
assert not os.path.exists(os.path.join(default_data_dir, "peers.dat"))
164165
start = int(time.time())
165166
with self.nodes[0].assert_debug_log(expected_msgs=[

test/functional/p2p_dns_seeds.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env python3
2+
# Copyright (c) 2021 The Bitcoin Core developers
3+
# Distributed under the MIT software license, see the accompanying
4+
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5+
"""Test ThreadDNSAddressSeed logic for querying DNS seeds."""
6+
7+
from test_framework.p2p import P2PInterface
8+
from test_framework.test_framework import BitcoinTestFramework
9+
10+
11+
class P2PDNSSeeds(BitcoinTestFramework):
12+
def set_test_params(self):
13+
self.setup_clean_chain = True
14+
self.num_nodes = 1
15+
self.extra_args = [["-dnsseed=1"]]
16+
17+
def run_test(self):
18+
self.existing_outbound_connections_test()
19+
20+
def existing_outbound_connections_test(self):
21+
# Make sure addrman is populated to enter the conditional where we
22+
# delay and potentially skip DNS seeding.
23+
self.nodes[0].addpeeraddress("192.0.0.8", 8333)
24+
25+
self.log.info("Check that we *do not* query DNS seeds if we have 2 outbound connections")
26+
27+
self.restart_node(0)
28+
with self.nodes[0].assert_debug_log(expected_msgs=["P2P peers available. Skipped DNS seeding."], timeout=12):
29+
for i in range(2):
30+
self.nodes[0].add_outbound_p2p_connection(P2PInterface(), p2p_idx=i, connection_type="outbound-full-relay")
31+
32+
33+
if __name__ == '__main__':
34+
P2PDNSSeeds().main()

test/functional/test_runner.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@
121121
'wallet_listreceivedby.py --legacy-wallet',
122122
'wallet_listreceivedby.py --descriptors',
123123
'wallet_abandonconflict.py --legacy-wallet',
124+
'p2p_dns_seeds.py',
124125
'wallet_abandonconflict.py --descriptors',
125126
'feature_csv_activation.py',
126127
'rpc_rawtransaction.py --legacy-wallet',

0 commit comments

Comments
 (0)