Skip to content

Commit 02dc80a

Browse files
committed
test: add integration tests for whitelist_only mode
Add whitelist_only_sync: builds a node with whitelist_only enabled and a single whitelisted bitcoind peer, verifies sync completes. Add whitelist_only_no_peers_exits: builds a node with whitelist_only and no peers configured, verifies the node exits with an error instead of falling back to DNS seeding.
1 parent 2519d42 commit 02dc80a

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

tests/core.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,54 @@ async fn tx_can_broadcast() {
633633
.unwrap();
634634
}
635635

636+
#[tokio::test]
637+
async fn whitelist_only_sync() {
638+
let (bitcoind, socket_addr) = start_bitcoind(true).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+
let host = (IpAddr::V4(*socket_addr.ip()), Some(socket_addr.port()));
645+
let builder = bip157::builder::Builder::new(bitcoin::Network::Regtest)
646+
.chain_state(ChainState::Checkpoint(HeaderCheckpoint::from_genesis(
647+
bitcoin::Network::Regtest,
648+
)))
649+
.add_peer(host)
650+
.whitelist_only()
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+
668+
#[tokio::test]
669+
async fn whitelist_only_no_peers_exits() {
670+
// With whitelist_only and no peers configured, the node should exit
671+
// with NoReachablePeers instead of falling back to DNS seeding.
672+
let tempdir = tempfile::TempDir::new().unwrap().path().to_owned();
673+
let builder = bip157::builder::Builder::new(bitcoin::Network::Regtest)
674+
.chain_state(ChainState::Checkpoint(HeaderCheckpoint::from_genesis(
675+
bitcoin::Network::Regtest,
676+
)))
677+
.whitelist_only()
678+
.data_dir(tempdir);
679+
let (node, _client) = builder.build();
680+
let result = node.run().await;
681+
assert!(result.is_err());
682+
}
683+
636684
#[tokio::test]
637685
async fn dns_works() {
638686
let hostname = bip157::lookup_host("seed.bitcoin.sipa.be").await;

0 commit comments

Comments
 (0)