mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
Node tests crate (#6972)
This commit is contained in:
14
Cargo.lock
generated
14
Cargo.lock
generated
@ -4512,6 +4512,20 @@ dependencies = [
|
|||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "node-e2e-tests"
|
||||||
|
version = "0.0.0"
|
||||||
|
dependencies = [
|
||||||
|
"eyre",
|
||||||
|
"futures-util",
|
||||||
|
"reth",
|
||||||
|
"reth-node-core",
|
||||||
|
"reth-node-ethereum",
|
||||||
|
"reth-primitives",
|
||||||
|
"serde_json",
|
||||||
|
"tokio",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "nom"
|
name = "nom"
|
||||||
version = "7.1.3"
|
version = "7.1.3"
|
||||||
|
|||||||
@ -42,6 +42,7 @@ members = [
|
|||||||
"crates/node-optimism/",
|
"crates/node-optimism/",
|
||||||
"crates/node-core/",
|
"crates/node-core/",
|
||||||
"crates/node-api/",
|
"crates/node-api/",
|
||||||
|
"crates/node-e2e-tests/",
|
||||||
"crates/stages/",
|
"crates/stages/",
|
||||||
"crates/static-file/",
|
"crates/static-file/",
|
||||||
"crates/storage/codecs/",
|
"crates/storage/codecs/",
|
||||||
|
|||||||
18
crates/node-e2e-tests/Cargo.toml
Normal file
18
crates/node-e2e-tests/Cargo.toml
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
[package]
|
||||||
|
name = "node-e2e-tests"
|
||||||
|
version = "0.0.0"
|
||||||
|
publish = false
|
||||||
|
edition.workspace = true
|
||||||
|
license.workspace = true
|
||||||
|
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
reth.workspace = true
|
||||||
|
reth-node-core.workspace = true
|
||||||
|
reth-primitives.workspace = true
|
||||||
|
reth-node-ethereum.workspace = true
|
||||||
|
futures-util.workspace = true
|
||||||
|
|
||||||
|
eyre.workspace = true
|
||||||
|
tokio.workspace = true
|
||||||
|
serde_json.workspace = true
|
||||||
95
crates/node-e2e-tests/tests/it/dev.rs
Normal file
95
crates/node-e2e-tests/tests/it/dev.rs
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
use futures_util::StreamExt;
|
||||||
|
use reth::{
|
||||||
|
builder::{components::FullNodeComponents, FullNode, NodeBuilder, NodeHandle},
|
||||||
|
providers::CanonStateSubscriptions,
|
||||||
|
rpc::eth::EthTransactions,
|
||||||
|
tasks::TaskManager,
|
||||||
|
};
|
||||||
|
use reth_node_core::{args::RpcServerArgs, node_config::NodeConfig};
|
||||||
|
use reth_node_ethereum::EthereumNode;
|
||||||
|
use reth_primitives::{b256, hex, ChainSpec, Genesis};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn can_run_dev_node() -> eyre::Result<()> {
|
||||||
|
let tasks = TaskManager::current();
|
||||||
|
|
||||||
|
// create node config
|
||||||
|
let node_config = NodeConfig::test()
|
||||||
|
.dev()
|
||||||
|
.with_rpc(RpcServerArgs::default().with_http())
|
||||||
|
.with_chain(custom_chain());
|
||||||
|
|
||||||
|
let NodeHandle { node, node_exit_future: _ } = NodeBuilder::new(node_config)
|
||||||
|
.testing_node(tasks.executor())
|
||||||
|
.node(EthereumNode::default())
|
||||||
|
.launch()
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
assert_chain_advances(node).await;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn assert_chain_advances<Node: FullNodeComponents>(mut node: FullNode<Node>) {
|
||||||
|
let mut notifications = node.provider.canonical_state_stream();
|
||||||
|
|
||||||
|
// submit tx through rpc
|
||||||
|
let raw_tx = hex!("02f876820a28808477359400847735940082520894ab0840c0e43688012c1adb0f5e3fc665188f83d28a029d394a5d630544000080c080a0a044076b7e67b5deecc63f61a8d7913fab86ca365b344b5759d1fe3563b4c39ea019eab979dd000da04dfc72bb0377c092d30fd9e1cab5ae487de49586cc8b0090");
|
||||||
|
|
||||||
|
let eth_api = node.rpc_registry.eth_api();
|
||||||
|
|
||||||
|
let hash = eth_api.send_raw_transaction(raw_tx.into()).await.unwrap();
|
||||||
|
|
||||||
|
let expected = b256!("b1c6512f4fc202c04355fbda66755e0e344b152e633010e8fd75ecec09b63398");
|
||||||
|
|
||||||
|
assert_eq!(hash, expected);
|
||||||
|
println!("submitted transaction: {hash}");
|
||||||
|
|
||||||
|
let head = notifications.next().await.unwrap();
|
||||||
|
|
||||||
|
let tx = head.tip().transactions().next().unwrap();
|
||||||
|
assert_eq!(tx.hash(), hash);
|
||||||
|
println!("mined transaction: {hash}");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn custom_chain() -> Arc<ChainSpec> {
|
||||||
|
let custom_genesis = r#"
|
||||||
|
{
|
||||||
|
|
||||||
|
"nonce": "0x42",
|
||||||
|
"timestamp": "0x0",
|
||||||
|
"extraData": "0x5343",
|
||||||
|
"gasLimit": "0x1388",
|
||||||
|
"difficulty": "0x400000000",
|
||||||
|
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||||
|
"coinbase": "0x0000000000000000000000000000000000000000",
|
||||||
|
"alloc": {
|
||||||
|
"0x6Be02d1d3665660d22FF9624b7BE0551ee1Ac91b": {
|
||||||
|
"balance": "0x4a47e3c12448f4ad000000"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"number": "0x0",
|
||||||
|
"gasUsed": "0x0",
|
||||||
|
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||||
|
"config": {
|
||||||
|
"ethash": {},
|
||||||
|
"chainId": 2600,
|
||||||
|
"homesteadBlock": 0,
|
||||||
|
"eip150Block": 0,
|
||||||
|
"eip155Block": 0,
|
||||||
|
"eip158Block": 0,
|
||||||
|
"byzantiumBlock": 0,
|
||||||
|
"constantinopleBlock": 0,
|
||||||
|
"petersburgBlock": 0,
|
||||||
|
"istanbulBlock": 0,
|
||||||
|
"berlinBlock": 0,
|
||||||
|
"londonBlock": 0,
|
||||||
|
"terminalTotalDifficulty": 0,
|
||||||
|
"terminalTotalDifficultyPassed": true,
|
||||||
|
"shanghaiTime": 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"#;
|
||||||
|
let genesis: Genesis = serde_json::from_str(custom_genesis).unwrap();
|
||||||
|
Arc::new(genesis.into())
|
||||||
|
}
|
||||||
3
crates/node-e2e-tests/tests/it/main.rs
Normal file
3
crates/node-e2e-tests/tests/it/main.rs
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
mod dev;
|
||||||
|
|
||||||
|
fn main() {}
|
||||||
@ -25,7 +25,7 @@ async fn main() -> eyre::Result<()> {
|
|||||||
.with_rpc(RpcServerArgs::default().with_http())
|
.with_rpc(RpcServerArgs::default().with_http())
|
||||||
.with_chain(custom_chain());
|
.with_chain(custom_chain());
|
||||||
|
|
||||||
let NodeHandle { mut node, node_exit_future } = NodeBuilder::new(node_config)
|
let NodeHandle { mut node, node_exit_future: _ } = NodeBuilder::new(node_config)
|
||||||
.testing_node(tasks.executor())
|
.testing_node(tasks.executor())
|
||||||
.node(EthereumNode::default())
|
.node(EthereumNode::default())
|
||||||
.launch()
|
.launch()
|
||||||
@ -50,8 +50,7 @@ async fn main() -> eyre::Result<()> {
|
|||||||
let tx = head.tip().transactions().next().unwrap();
|
let tx = head.tip().transactions().next().unwrap();
|
||||||
assert_eq!(tx.hash(), hash);
|
assert_eq!(tx.hash(), hash);
|
||||||
println!("mined transaction: {hash}");
|
println!("mined transaction: {hash}");
|
||||||
|
Ok(())
|
||||||
node_exit_future.await
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn custom_chain() -> Arc<ChainSpec> {
|
fn custom_chain() -> Arc<ChainSpec> {
|
||||||
|
|||||||
Reference in New Issue
Block a user