mod eth_gas;
use crate::dev::subcommands::tests_cmd::helpers::{docker, forest_client, lotus_client};
use crate::rpc::prelude::*;
use anyhow::{Context as _, ensure};
#[derive(Debug, clap::Subcommand)]
pub enum DevnetCommand {
EthGas(eth_gas::EthGasTestCommand),
}
impl DevnetCommand {
pub async fn run(self) -> anyhow::Result<()> {
preflight().await.context("devnet pre-flight failed")?;
match self {
Self::EthGas(cmd) => cmd.run().await,
}
}
}
async fn preflight() -> anyhow::Result<()> {
for container in ["forest", "lotus"] {
let running = docker(&["inspect", "-f", "{{.State.Running}}", container]).with_context(
|| format!("could not query container `{container}`; is docker running and the local docker devnet up?"),
)?;
ensure!(
running.trim() == "true",
"devnet container `{container}` is not running; bring the local docker devnet up first"
);
}
for var in [
"FULLNODE_API_INFO",
"FOREST_TEST_PRELOADED_ADDRESS",
"LOTUS_RPC_PORT",
] {
ensure!(
std::env::var_os(var).is_some(),
"{var} is not set; source the devnet test harness and run `devnet_test_env_init` first"
);
}
for (node, client) in [("forest", forest_client()?), ("lotus", lotus_client()?)] {
EthBlockNumber::call(&client, ()).await.with_context(|| {
format!("{node} eth RPC is not reachable; is the local docker devnet up (with eth RPC enabled) and synced?")
})?;
}
Ok(())
}