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

feat(zk_toolbox): Add check for zksync repo path #2447

Merged
merged 10 commits into from
Jul 24, 2024
31 changes: 26 additions & 5 deletions zk_toolbox/crates/zk_inception/src/commands/ecosystem/create.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use std::{path::PathBuf, str::FromStr};
use std::{
path::{Path, PathBuf},
str::FromStr,
};

use anyhow::bail;
use common::{git, logger, spinner::Spinner};
Expand All @@ -19,10 +22,11 @@ use crate::{
},
},
messages::{
msg_created_ecosystem, MSG_CLONING_ERA_REPO_SPINNER, MSG_CREATING_DEFAULT_CHAIN_SPINNER,
MSG_CREATING_ECOSYSTEM, MSG_CREATING_INITIAL_CONFIGURATIONS_SPINNER,
MSG_ECOSYSTEM_ALREADY_EXISTS_ERR, MSG_ECOSYSTEM_CONFIG_INVALID_ERR, MSG_SELECTED_CONFIG,
MSG_STARTING_CONTAINERS_SPINNER,
msg_created_ecosystem, msg_directory_does_not_contain_cargo_toml_err,
msg_path_to_zksync_does_not_exist_err, MSG_CLONING_ERA_REPO_SPINNER,
MSG_CREATING_DEFAULT_CHAIN_SPINNER, MSG_CREATING_ECOSYSTEM,
MSG_CREATING_INITIAL_CONFIGURATIONS_SPINNER, MSG_ECOSYSTEM_ALREADY_EXISTS_ERR,
MSG_ECOSYSTEM_CONFIG_INVALID_ERR, MSG_SELECTED_CONFIG, MSG_STARTING_CONTAINERS_SPINNER,
},
};

Expand Down Expand Up @@ -62,6 +66,7 @@ fn create(args: EcosystemCreateArgs, shell: &Shell) -> anyhow::Result<()> {
link_to_code
} else {
let path = PathBuf::from_str(&args.link_to_code)?;
check_link_to_code(&path)?;
git::submodule_update(shell, path.clone())?;
path
};
Expand Down Expand Up @@ -114,3 +119,19 @@ fn create(args: EcosystemCreateArgs, shell: &Shell) -> anyhow::Result<()> {
logger::outro(msg_created_ecosystem(ecosystem_name));
Ok(())
}

fn check_link_to_code(path: &Path) -> anyhow::Result<()> {
if !path.exists() {
bail!(msg_path_to_zksync_does_not_exist_err(
path.to_str().unwrap()
));
}

if !path.join("Cargo.toml").exists() {
bail!(msg_directory_does_not_contain_cargo_toml_err(
path.to_str().unwrap()
));
}

Deniallugo marked this conversation as resolved.
Show resolved Hide resolved
Ok(())
}
8 changes: 8 additions & 0 deletions zk_toolbox/crates/zk_inception/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ pub(super) const MSG_ECOSYSTEM_CONFIG_INVALID_ERR: &str = "Invalid ecosystem con
pub(super) const MSG_LINK_TO_CODE_SELECTION_CLONE: &str = "Clone for me (recommended)";
pub(super) const MSG_LINK_TO_CODE_SELECTION_PATH: &str = "I have the code already";

pub(super) fn msg_path_to_zksync_does_not_exist_err(path: &str) -> String {
format!("Path to ZkSync-era repo does not exist: {path:?}")
Deniallugo marked this conversation as resolved.
Show resolved Hide resolved
}

pub(super) fn msg_directory_does_not_contain_cargo_toml_err(path: &str) -> String {
format!("Directory does not contain Cargo.toml: {path:?}")
}

/// Ecosystem and chain init related messages
pub(super) const MSG_L1_RPC_URL_HELP: &str = "L1 RPC URL";
pub(super) const MSG_GENESIS_ARGS_HELP: &str = "Genesis options";
Expand Down
Loading