Skip to content

Commit b7faa33

Browse files
committed
test: add integration test for whitelist_only mode
Add whitelist_only_sync test that builds a node with whitelist_only enabled and verifies it syncs successfully using only the whitelisted bitcoind peer.
1 parent 2519d42 commit b7faa33

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

tests/core.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,39 @@ 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+
// With whitelist_only, only the whitelisted peer should be connected
663+
let peers = requester.peer_info().await.unwrap();
664+
assert_eq!(peers.len(), 1);
665+
requester.shutdown().unwrap();
666+
rpc.stop().unwrap();
667+
}
668+
636669
#[tokio::test]
637670
async fn dns_works() {
638671
let hostname = bip157::lookup_host("seed.bitcoin.sipa.be").await;

0 commit comments

Comments
 (0)