forest/dev/subcommands/
devnet_cmd.rs1mod eth_gas;
10
11use crate::dev::subcommands::tests_cmd::helpers::{docker, forest_client, lotus_client};
12use crate::rpc::prelude::*;
13use anyhow::{Context as _, ensure};
14
15#[derive(Debug, clap::Subcommand)]
17pub enum DevnetCommand {
18 EthGas(eth_gas::EthGasTestCommand),
19}
20
21impl DevnetCommand {
22 pub async fn run(self) -> anyhow::Result<()> {
23 preflight().await.context("devnet pre-flight failed")?;
24 match self {
25 Self::EthGas(cmd) => cmd.run().await,
26 }
27 }
28}
29
30async fn preflight() -> anyhow::Result<()> {
31 for container in ["forest", "lotus"] {
32 let running = docker(&["inspect", "-f", "{{.State.Running}}", container]).with_context(
33 || format!("could not query container `{container}`; is docker running and the local docker devnet up?"),
34 )?;
35 ensure!(
36 running.trim() == "true",
37 "devnet container `{container}` is not running; bring the local docker devnet up first"
38 );
39 }
40
41 for var in [
42 "FULLNODE_API_INFO",
43 "FOREST_TEST_PRELOADED_ADDRESS",
44 "LOTUS_RPC_PORT",
45 ] {
46 ensure!(
47 std::env::var_os(var).is_some(),
48 "{var} is not set; source the devnet test harness and run `devnet_test_env_init` first"
49 );
50 }
51
52 for (node, client) in [("forest", forest_client()?), ("lotus", lotus_client()?)] {
55 EthBlockNumber::call(&client, ()).await.with_context(|| {
56 format!("{node} eth RPC is not reachable; is the local docker devnet up (with eth RPC enabled) and synced?")
57 })?;
58 }
59
60 Ok(())
61}