Skip to content

Commit

Permalink
chore: spawn local network example
Browse files Browse the repository at this point in the history
  • Loading branch information
mickvandijke committed Jan 21, 2025
1 parent cd0cfbe commit b08323a
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions ant-node/examples/spawn_local_network.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
use ant_evm::EvmTestnet;
use ant_node::spawn::network::NetworkSpawner;
use std::time::Duration;
use tokio::time::sleep;
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;
use tracing_subscriber::{fmt, EnvFilter};

#[tokio::main]
async fn main() {
tracing_subscriber::registry()
.with(fmt::layer())
.with(EnvFilter::from_env("RUST_LOG"))
.init();

// start local Ethereum node
let evm_testnet = EvmTestnet::new().await;
let evm_network = evm_testnet.to_network();
let network_size = 2;

let running_network = NetworkSpawner::new()
.with_evm_network(evm_network)
.with_local(true)
.with_size(network_size)
.spawn()
.await
.unwrap();

assert_eq!(running_network.running_nodes().len(), network_size);

// Validate each node's listen addresses are not empty
for node in running_network.running_nodes() {
let listen_addrs = node.get_listen_addrs().await.unwrap();

assert!(!listen_addrs.is_empty());
}

// Wait for nodes to dial each other
sleep(Duration::from_secs(20)).await;

// TODO: Validate that all nodes know each other

Check notice

Code scanning / devskim

A "TODO" or similar was left in source code, possibly indicating incomplete functionality Note

Suspicious comment
for node in running_network.running_nodes() {
let known_peers = node.get_swarm_local_state().await.unwrap().connected_peers;

println!("Known peers: {known_peers:?}");

// TODO: nodes do not know each other..

Check notice

Code scanning / devskim

A "TODO" or similar was left in source code, possibly indicating incomplete functionality Note

Suspicious comment
}

running_network.shutdown();
}

0 comments on commit b08323a

Please sign in to comment.