Skip to content

Commit bea4087

Browse files
committed
test: add integration test for DnsPeer
Add dns_peer_sync test that builds a node with a DnsPeer pointing at the local bitcoind and verifies the node resolves the hostname, connects, and syncs the chain successfully.
1 parent 5f7e263 commit bea4087

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

tests/core.rs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use bip157::{
88
chain::{checkpoints::HeaderCheckpoint, BlockHeaderChanges, ChainState},
99
client::Client,
1010
node::Node,
11-
Address, BlockHash, Event, Info, ServiceFlags, Transaction, TrustedPeer, Warning,
11+
Address, BlockHash, DnsPeer, Event, Info, ServiceFlags, Transaction, TrustedPeer, Warning,
1212
};
1313
use bitcoin::{
1414
absolute,
@@ -633,6 +633,38 @@ async fn tx_can_broadcast() {
633633
.unwrap();
634634
}
635635

636+
#[tokio::test]
637+
async fn dns_peer_sync() {
638+
let (bitcoind, socket_addr) = start_bitcoind(false).unwrap();
639+
let rpc = &bitcoind.client;
640+
let tempdir = tempfile::TempDir::new().unwrap().path().to_owned();
641+
let miner = rpc.new_address().unwrap();
642+
mine_blocks(rpc, &miner, 10, 2).await;
643+
let best = best_hash(rpc);
644+
// Use a DNS peer instead of a resolved TrustedPeer
645+
let dns_peer = DnsPeer::new("127.0.0.1", socket_addr.port());
646+
let builder = bip157::builder::Builder::new(bitcoin::Network::Regtest)
647+
.chain_state(ChainState::Checkpoint(HeaderCheckpoint::from_genesis(
648+
bitcoin::Network::Regtest,
649+
)))
650+
.add_dns_peer(dns_peer)
651+
.data_dir(tempdir);
652+
let (node, client) = builder.build();
653+
tokio::task::spawn(async move { node.run().await });
654+
let Client {
655+
requester,
656+
info_rx,
657+
warn_rx,
658+
event_rx: mut channel,
659+
} = client;
660+
tokio::task::spawn(async move { print_logs(info_rx, warn_rx).await });
661+
sync_assert(&best, &mut channel).await;
662+
let cp = requester.chain_tip().await.unwrap();
663+
assert_eq!(cp.hash, best);
664+
requester.shutdown().unwrap();
665+
rpc.stop().unwrap();
666+
}
667+
636668
#[tokio::test]
637669
async fn dns_works() {
638670
let hostname = bip157::lookup_host("seed.bitcoin.sipa.be").await;

0 commit comments

Comments
 (0)