Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(node-bindings): consolidate integration tests #1422

Merged
merged 2 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 0 additions & 42 deletions crates/node-bindings/tests/anvil.rs

This file was deleted.

75 changes: 0 additions & 75 deletions crates/node-bindings/tests/geth.rs

This file was deleted.

40 changes: 40 additions & 0 deletions crates/node-bindings/tests/it/anvil.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use alloy_node_bindings::Anvil;

#[test]
fn can_launch_anvil() {
if !ci_info::is_ci() {
return;
}

let _ = Anvil::new().spawn();
}

#[test]
fn can_launch_anvil_with_more_accounts() {
if !ci_info::is_ci() {
return;
}

let _ = Anvil::new().arg("--accounts").arg("20").spawn();
}

#[test]
fn assert_chain_id() {
if !ci_info::is_ci() {
return;
}

let id = 99999;
let anvil = Anvil::new().chain_id(id).spawn();
assert_eq!(anvil.chain_id(), id);
}

#[test]
fn assert_chain_id_without_rpc() {
if !ci_info::is_ci() {
return;
}

let anvil = Anvil::new().spawn();
assert_eq!(anvil.chain_id(), 31337);
}
76 changes: 76 additions & 0 deletions crates/node-bindings/tests/it/geth.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
use alloy_node_bindings::{utils::run_with_tempdir_sync, Geth};
use k256::ecdsa::SigningKey;

#[test]
fn port_0() {
if !ci_info::is_ci() {
return;
}

run_with_tempdir_sync("geth-test-", |_| {
let _geth = Geth::new().disable_discovery().port(0u16).spawn();
});
}

#[test]
fn p2p_port() {
if !ci_info::is_ci() {
return;
}

run_with_tempdir_sync("geth-test-", |temp_dir_path| {
let geth = Geth::new().disable_discovery().data_dir(temp_dir_path).spawn();
let p2p_port = geth.p2p_port();
assert!(p2p_port.is_some());
});
}

#[test]
fn explicit_p2p_port() {
if !ci_info::is_ci() {
return;
}

run_with_tempdir_sync("geth-test-", |temp_dir_path| {
// if a p2p port is explicitly set, it should be used
let geth = Geth::new().p2p_port(1234).data_dir(temp_dir_path).spawn();
let p2p_port = geth.p2p_port();
assert_eq!(p2p_port, Some(1234));
});
}

#[test]
fn dev_mode() {
if !ci_info::is_ci() {
return;
}

run_with_tempdir_sync("geth-test-", |temp_dir_path| {
// dev mode should not have a p2p port, and dev should be the default
let geth = Geth::new().data_dir(temp_dir_path).spawn();
let p2p_port = geth.p2p_port();
assert!(p2p_port.is_none(), "{p2p_port:?}");
})
}

#[test]
#[ignore = "fails on geth >=1.14"]
#[allow(deprecated)]
fn clique_correctly_configured() {
if !ci_info::is_ci() {
return;
}

run_with_tempdir_sync("geth-test-", |temp_dir_path| {
let private_key = SigningKey::random(&mut rand::thread_rng());
let geth = Geth::new()
.set_clique_private_key(private_key)
.chain_id(1337u64)
.data_dir(temp_dir_path)
.spawn();

assert!(geth.p2p_port().is_some());
assert!(geth.clique_private_key().is_some());
assert!(geth.genesis().is_some());
})
}
5 changes: 5 additions & 0 deletions crates/node-bindings/tests/it/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#![allow(missing_docs)]

mod anvil;
mod geth;
mod reth;
Loading