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

Fix/init blocking #1660

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/crates/soroban-test/tests/it/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ mod custom_types;
mod dotenv;
mod fund;
mod hello_world;
mod init;
mod snapshot;
mod tx;
mod util;
Expand Down
1 change: 0 additions & 1 deletion cmd/crates/soroban-test/tests/it/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ mod arg_parsing;
mod build;
mod config;
mod help;
mod init;
#[cfg(feature = "it")]
mod integration;
mod plugin;
Expand Down
64 changes: 32 additions & 32 deletions cmd/soroban-cli/src/commands/contract/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ pub enum Error {

impl Cmd {
#[allow(clippy::unused_self)]
pub fn run(&self, global_args: &global::Args) -> Result<(), Error> {
pub async fn run(&self, global_args: &global::Args) -> Result<(), Error> {
let runner = Runner {
args: self.clone(),
print: print::Print::new(global_args.quiet),
};

runner.run()
runner.run().await
}
}

Expand All @@ -103,7 +103,7 @@ struct Runner {
}

impl Runner {
fn run(&self) -> Result<(), Error> {
async fn run(&self) -> Result<(), Error> {
let project_path = PathBuf::from(&self.args.project_path);
self.print
.infoln(format!("Initializing project at {project_path:?}"));
Expand All @@ -112,7 +112,7 @@ impl Runner {
Self::create_dir_all(&project_path)?;
self.copy_template_files()?;

if !Self::check_internet_connection() {
if !Self::check_internet_connection().await {
self.print.warnln("It doesn't look like you're connected to the internet. We're still able to initialize a new project, but additional examples and the frontend template will not be included.");
return Ok(());
}
Expand Down Expand Up @@ -260,8 +260,8 @@ impl Runner {
.unwrap_or(false)
}

fn check_internet_connection() -> bool {
if let Ok(_req) = http::blocking_client().get(GITHUB_URL).send() {
async fn check_internet_connection() -> bool {
if let Ok(_req) = http::client().get(GITHUB_URL).send().await {
return true;
}

Expand Down Expand Up @@ -454,8 +454,8 @@ mod tests {

const TEST_PROJECT_NAME: &str = "test-project";

#[test]
fn test_init() {
#[tokio::test]
async fn test_init() {
let temp_dir = tempfile::tempdir().unwrap();
let project_dir = temp_dir.path().join(TEST_PROJECT_NAME);
let runner = Runner {
Expand All @@ -467,7 +467,7 @@ mod tests {
},
print: print::Print::new(false),
};
runner.run().unwrap();
runner.run().await.unwrap();

assert_base_template_files_exist(&project_dir);
assert_default_hello_world_contract_files_exist(&project_dir);
Expand All @@ -480,8 +480,8 @@ mod tests {
temp_dir.close().unwrap();
}

#[test]
fn test_init_including_example_contract() {
#[tokio::test]
async fn test_init_including_example_contract() {
let temp_dir = tempfile::tempdir().unwrap();
let project_dir = temp_dir.path().join(TEST_PROJECT_NAME);
let runner = Runner {
Expand All @@ -493,7 +493,7 @@ mod tests {
},
print: print::Print::new(false),
};
runner.run().unwrap();
runner.run().await.unwrap();

assert_base_template_files_exist(&project_dir);
assert_default_hello_world_contract_files_exist(&project_dir);
Expand All @@ -511,8 +511,8 @@ mod tests {
temp_dir.close().unwrap();
}

#[test]
fn test_init_including_multiple_example_contracts() {
#[tokio::test]
async fn test_init_including_multiple_example_contracts() {
let temp_dir = tempfile::tempdir().unwrap();
let project_dir = temp_dir.path().join("project");
let runner = Runner {
Expand All @@ -524,7 +524,7 @@ mod tests {
},
print: print::Print::new(false),
};
runner.run().unwrap();
runner.run().await.unwrap();

assert_base_template_files_exist(&project_dir);
assert_default_hello_world_contract_files_exist(&project_dir);
Expand All @@ -543,8 +543,8 @@ mod tests {
temp_dir.close().unwrap();
}

#[test]
fn test_init_with_invalid_example_contract() {
#[tokio::test]
async fn test_init_with_invalid_example_contract() {
let temp_dir = tempfile::tempdir().unwrap();
let project_dir = temp_dir.path().join("project");
let runner = Runner {
Expand All @@ -556,13 +556,13 @@ mod tests {
},
print: print::Print::new(false),
};
assert!(runner.run().is_err());
assert!(runner.run().await.is_err());

temp_dir.close().unwrap();
}

#[test]
fn test_init_with_frontend_template() {
#[tokio::test]
async fn test_init_with_frontend_template() {
let temp_dir = tempfile::tempdir().unwrap();
let project_dir = temp_dir.path().join(TEST_PROJECT_NAME);
let runner = Runner {
Expand All @@ -574,7 +574,7 @@ mod tests {
},
print: print::Print::new(false),
};
runner.run().unwrap();
runner.run().await.unwrap();

assert_base_template_files_exist(&project_dir);
assert_default_hello_world_contract_files_exist(&project_dir);
Expand All @@ -592,8 +592,8 @@ mod tests {
temp_dir.close().unwrap();
}

#[test]
fn test_init_with_overwrite() {
#[tokio::test]
async fn test_init_with_overwrite() {
let temp_dir = tempfile::tempdir().unwrap();
let project_dir = temp_dir.path().join(TEST_PROJECT_NAME);

Expand All @@ -607,7 +607,7 @@ mod tests {
},
print: print::Print::new(false),
};
runner.run().unwrap();
runner.run().await.unwrap();

// Get initial modification times
let initial_mod_times = get_mod_times(&project_dir);
Expand All @@ -622,7 +622,7 @@ mod tests {
},
print: print::Print::new(false),
};
runner.run().unwrap();
runner.run().await.unwrap();

// Get new modification times
let new_mod_times = get_mod_times(&project_dir);
Expand Down Expand Up @@ -653,8 +653,8 @@ mod tests {
mod_times
}

#[test]
fn test_init_from_within_an_existing_project() {
#[tokio::test]
async fn test_init_from_within_an_existing_project() {
let temp_dir = tempfile::tempdir().unwrap();
let project_dir = temp_dir.path().join("./");
let runner = Runner {
Expand All @@ -666,7 +666,7 @@ mod tests {
},
print: print::Print::new(false),
};
runner.run().unwrap();
runner.run().await.unwrap();

assert_base_template_files_exist(&project_dir);
assert_default_hello_world_contract_files_exist(&project_dir);
Expand All @@ -686,8 +686,8 @@ mod tests {
temp_dir.close().unwrap();
}

#[test]
fn test_init_does_not_duplicate_frontend_readme_contents_when_run_more_than_once() {
#[tokio::test]
async fn test_init_does_not_duplicate_frontend_readme_contents_when_run_more_than_once() {
let temp_dir = tempfile::tempdir().unwrap();
let project_dir = temp_dir.path().join(TEST_PROJECT_NAME);
let runner = Runner {
Expand All @@ -699,7 +699,7 @@ mod tests {
},
print: print::Print::new(false),
};
runner.run().unwrap();
runner.run().await.unwrap();

// call init again to make sure the README.md's contents are not duplicated
let runner = Runner {
Expand All @@ -711,7 +711,7 @@ mod tests {
},
print: print::Print::new(false),
};
runner.run().unwrap();
runner.run().await.unwrap();

assert_base_template_files_exist(&project_dir);
assert_default_hello_world_contract_files_exist(&project_dir);
Expand Down
2 changes: 1 addition & 1 deletion cmd/soroban-cli/src/commands/contract/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ impl Cmd {
Cmd::Deploy(deploy) => deploy.run(global_args).await?,
Cmd::Id(id) => id.run()?,
Cmd::Info(info) => info.run().await?,
Cmd::Init(init) => init.run(global_args)?,
Cmd::Init(init) => init.run(global_args).await?,
Cmd::Inspect(inspect) => inspect.run(global_args)?,
Cmd::Install(install) => install.run(global_args).await?,
Cmd::Invoke(invoke) => invoke.run(global_args).await?,
Expand Down
Loading