Skip to content
This repository has been archived by the owner on Oct 31, 2024. It is now read-only.

Commit

Permalink
feat: add no-edge-process flag to node init (#401)
Browse files Browse the repository at this point in the history
  • Loading branch information
gruberb authored Dec 12, 2023
1 parent 4989936 commit 28a553b
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 11 deletions.
5 changes: 5 additions & 0 deletions crates/topos/src/components/node/commands/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,9 @@ pub struct Init {
/// If omitted, the local FS secrets manager is used
#[arg(long, env = "TOPOS_SECRETS_MANAGER")]
pub secrets_config: Option<String>,

/// For certain use cases, we manually provide private keys to a running node, and don't want to
/// rely on polygon-edge during runtime. Example: A sequencer which runs for an external EVM chain
#[arg(long, env = "TOPOS_NO_EDGE_PROCESS", action)]
pub no_edge_process: bool,
}
26 changes: 15 additions & 11 deletions crates/topos/src/components/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,21 @@ pub(crate) async fn handle_command(
// Generate the configuration as per the role
let mut config_toml = toml::Table::new();

// Generate the Edge configuration
if let Ok(result) = services::process::generate_edge_config(
edge_path.join(BINARY_NAME),
node_path.clone(),
)
.await
{
if result.is_err() {
println!("Failed to generate edge config");
remove_dir_all(node_path).expect("failed to remove config folder");
std::process::exit(1);
if cmd.no_edge_process {
println!("Init the node without polygon-edge process...");
} else {
// Generate the Edge configuration
if let Ok(result) = services::process::generate_edge_config(
edge_path.join(BINARY_NAME),
node_path.clone(),
)
.await
{
if result.is_err() {
println!("Failed to generate edge config");
remove_dir_all(node_path).expect("failed to remove config folder");
std::process::exit(1);
}
}
}

Expand Down
32 changes: 32 additions & 0 deletions crates/topos/tests/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,38 @@ async fn handle_command_init() -> Result<(), Box<dyn std::error::Error>> {
Ok(())
}

#[tokio::test]
async fn handle_command_init_without_polygon_edge() -> Result<(), Box<dyn std::error::Error>> {
let tmp_home_dir = tempdir()?;

let mut cmd = Command::cargo_bin("topos")?;
cmd.arg("node")
.arg("init")
.arg("--home")
.arg(tmp_home_dir.path().to_str().unwrap())
.arg("--no-edge-process");

let output = cmd.assert().success();
let result: &str = std::str::from_utf8(&output.get_output().stdout)?;

assert!(result.contains("Created node config file"));

let home = PathBuf::from(tmp_home_dir.path());

// Verification: check that the config file was created
let config_path = home.join("node").join("default").join("config.toml");
assert!(config_path.exists());

// Further verification might include checking the contents of the config file
let config_contents = std::fs::read_to_string(&config_path).unwrap();

assert!(config_contents.contains("[base]"));
assert!(config_contents.contains("name = \"default\""));
assert!(config_contents.contains("[tce]"));

Ok(())
}

#[test]
fn nothing_written_if_failure() -> Result<(), Box<dyn std::error::Error>> {
let tmp_home_dir = tempdir()?;
Expand Down

0 comments on commit 28a553b

Please sign in to comment.