From 532531fc760e964e35e5e42061569cd7efc62959 Mon Sep 17 00:00:00 2001 From: ea-open-source Date: Fri, 20 May 2022 15:03:52 +0700 Subject: [PATCH 01/22] upload metadata to movey # Conflicts: # Cargo.lock # language/tools/move-cli/Cargo.toml --- language/tools/move-cli/Cargo.toml | 2 + language/tools/move-cli/tests/cli_tests.rs | 82 +++++++++++++++++++ .../upload_tests/valid_package/Move.toml | 10 +++ .../valid_package/sources/Dummy.move | 1 + 4 files changed, 95 insertions(+) create mode 100644 language/tools/move-cli/tests/upload_tests/valid_package/Move.toml create mode 100644 language/tools/move-cli/tests/upload_tests/valid_package/sources/Dummy.move diff --git a/language/tools/move-cli/Cargo.toml b/language/tools/move-cli/Cargo.toml index e060a4133e..6e6a1b856e 100644 --- a/language/tools/move-cli/Cargo.toml +++ b/language/tools/move-cli/Cargo.toml @@ -21,6 +21,7 @@ tempfile = "3.2.0" walkdir = "2.3.1" codespan-reporting = "0.11.1" itertools = "0.10.0" +serde_json = "1.0" toml_edit = { version = "0.14.3", features = ["easy"] } bcs = "0.1.2" @@ -48,6 +49,7 @@ move-unit-test = { path = "../move-unit-test" } move-errmapgen = { path = "../../move-prover/move-errmapgen" } move-bytecode-source-map = { path = "../../move-ir-compiler/move-bytecode-source-map" } move-bytecode-viewer = { path = "../move-bytecode-viewer" } +reqwest = { version = "0.10", features = ["blocking", "json"] } [dev-dependencies] datatest-stable = "0.1.1" diff --git a/language/tools/move-cli/tests/cli_tests.rs b/language/tools/move-cli/tests/cli_tests.rs index f0c6d060c2..ff9bface82 100644 --- a/language/tools/move-cli/tests/cli_tests.rs +++ b/language/tools/move-cli/tests/cli_tests.rs @@ -12,6 +12,7 @@ use std::{env, fs, io::Write}; use std::os::unix::fs::PermissionsExt; use std::{path::PathBuf, process::Stdio}; use toml_edit::easy::Value; +use std::process::Command; pub const CLI_METATEST_PATH: [&str; 3] = ["tests", "metatests", "args.txt"]; @@ -61,6 +62,87 @@ fn cross_process_locking_git_deps() { handle.join().unwrap(); } +const PACKAGE_PATH: &str = "./tests/upload_tests/valid_package"; +#[cfg(debug_assertions)] +const CLI_EXE: &str = "../../../../../../target/debug/move"; +#[cfg(not(debug_assertions))] +const CLI_EXE: &str = "../../../../../../target/release/move"; + +#[test] +fn upload_package_to_movey_works() { + init_git(PACKAGE_PATH, 0); + let output = Command::new(CLI_EXE) + .current_dir(PACKAGE_PATH) + .args(["package", "upload", "--test"]) + .output() + .unwrap(); + assert!(output.status.success()); + let res_path = format!("{}{}", PACKAGE_PATH, "/request-body.txt"); + let data = std::fs::read_to_string(&res_path).unwrap(); + assert!(data.contains("rev")); + assert!(data.contains("\"github_repo_url\":\"https://github.com/diem/move\"")); + assert!(data.contains("\"description\":\"Description test\"")); + std::fs::remove_file(&res_path).unwrap(); +} + +#[test] +fn upload_package_to_movey_with_no_remote_should_panic() { + init_git(PACKAGE_PATH, 1); + let output = Command::new(CLI_EXE) + .current_dir(PACKAGE_PATH) + .args(["package", "upload", "--test"]) + .output() + .unwrap(); + assert!(!output.status.success()); + let error = String::from_utf8_lossy(output.stderr.as_slice()).to_string(); + assert!(error.contains("invalid git repository")); +} + +#[test] +fn upload_package_to_movey_with_no_head_commit_id_should_panic() { + init_git(PACKAGE_PATH, 2); + let output = Command::new(CLI_EXE) + .current_dir(PACKAGE_PATH) + .args(["package", "upload", "--test"]) + .output() + .unwrap(); + assert!(!output.status.success()); + let error = String::from_utf8_lossy(output.stderr.as_slice()).to_string(); + assert!(error.contains("invalid HEAD commit id")); +} + +// flag == 0: all git command are run +// flag == 1: missing git add remote command +// flag == 2: missing git commit command +fn init_git(package_path: &str, flag: i32) { + let git_path = format!("{}{}", package_path, "/.git"); + if Path::new::(&git_path).exists() { + fs::remove_dir_all(&git_path).unwrap(); + } + Command::new("git") + .current_dir(package_path) + .args(&["init"]) + .output().unwrap(); + if flag != 1 { + Command::new("git") + .current_dir(package_path) + .args(&["remote", "add", "origin", "git@github.com:diem/move.git"]) + .output().unwrap(); + } + Command::new("touch") + .current_dir(package_path) + .args(&["simplefile"]) + .output().unwrap(); + Command::new("git") + .current_dir(package_path) + .args(&["add", "simplefile"]) + .output().unwrap(); + if flag != 2{ + Command::new("git") + .current_dir(package_path) + .args(&["commit", "-m", "initial commit"]) + .output().unwrap(); + } #[test] fn save_credential_works() { let cli_exe = env!("CARGO_BIN_EXE_move"); diff --git a/language/tools/move-cli/tests/upload_tests/valid_package/Move.toml b/language/tools/move-cli/tests/upload_tests/valid_package/Move.toml new file mode 100644 index 0000000000..739ccaab2d --- /dev/null +++ b/language/tools/move-cli/tests/upload_tests/valid_package/Move.toml @@ -0,0 +1,10 @@ +[package] +name = "Package1" +version = "0.0.0" +description = "Description test" + +[addresses] +Std = "0x1" + +[dependencies] +MoveStdlib = { git = "https://github.com/diem/move.git", subdir = "language/move-stdlib", rev = "98ed299" } diff --git a/language/tools/move-cli/tests/upload_tests/valid_package/sources/Dummy.move b/language/tools/move-cli/tests/upload_tests/valid_package/sources/Dummy.move new file mode 100644 index 0000000000..45646f1b13 --- /dev/null +++ b/language/tools/move-cli/tests/upload_tests/valid_package/sources/Dummy.move @@ -0,0 +1 @@ +module 0x1::Dummy {} From e1091b2c78d31718625dffe55535da1b90ebd466 Mon Sep 17 00:00:00 2001 From: ea-open-source Date: Wed, 15 Jun 2022 21:06:23 +0700 Subject: [PATCH 02/22] Add api token to upload request, get token from credential file # Conflicts: # Cargo.lock # language/tools/move-cli/tests/cli_tests.rs --- language/tools/move-cli/src/lib.rs | 1 + .../tools/move-cli/src/utils/credential.rs | 37 +++++++++++++++++++ language/tools/move-cli/src/utils/mod.rs | 1 + language/tools/move-cli/tests/cli_tests.rs | 4 +- .../upload_tests/valid_package/simplefile | 0 5 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 language/tools/move-cli/src/utils/credential.rs create mode 100644 language/tools/move-cli/src/utils/mod.rs create mode 100644 language/tools/move-cli/tests/upload_tests/valid_package/simplefile diff --git a/language/tools/move-cli/src/lib.rs b/language/tools/move-cli/src/lib.rs index f7cef69805..fc755185df 100644 --- a/language/tools/move-cli/src/lib.rs +++ b/language/tools/move-cli/src/lib.rs @@ -11,6 +11,7 @@ use move_package::BuildConfig; pub mod base; pub mod experimental; pub mod sandbox; +pub mod utils; /// Default directory where saved Move resources live pub const DEFAULT_STORAGE_DIR: &str = "storage"; diff --git a/language/tools/move-cli/src/utils/credential.rs b/language/tools/move-cli/src/utils/credential.rs new file mode 100644 index 0000000000..75cba3c13e --- /dev/null +++ b/language/tools/move-cli/src/utils/credential.rs @@ -0,0 +1,37 @@ +use std::fs; +use toml_edit::easy::Value; + +pub fn get_move_home_path(is_test_mode: bool) -> String { + let mut home = std::env::var("MOVE_HOME").unwrap_or_else(|_| { + format!( + "{}/.move", + std::env::var("HOME").expect("env var 'HOME' must be set") + ) + }); + if is_test_mode && !home.contains("/test") { + home.push_str("/test"); + } + home +} + +pub fn get_credential_path(is_test_mode: bool) -> String { + get_move_home_path(is_test_mode) + "/credential.toml" +} + +pub fn get_registry_api_token(is_test_mode: bool) -> String { + let move_home = get_move_home_path(is_test_mode); + let credential_path = move_home.clone() + "/credential.toml"; + let contents = fs::read_to_string(&credential_path).expect("Unable to read credential.toml"); + let mut toml: Value = contents.parse().expect("Unable to parse credential.toml"); + let registry = toml + .as_table_mut() + .unwrap() + .get_mut("registry") + .expect("Unable to get [registry] table in credential.toml"); + let token = registry + .as_table_mut() + .unwrap() + .get_mut("token") + .expect("Unable to get token"); + token.to_string().replace("\"", "") +} diff --git a/language/tools/move-cli/src/utils/mod.rs b/language/tools/move-cli/src/utils/mod.rs new file mode 100644 index 0000000000..510c0f2a46 --- /dev/null +++ b/language/tools/move-cli/src/utils/mod.rs @@ -0,0 +1 @@ +pub mod credential; diff --git a/language/tools/move-cli/tests/cli_tests.rs b/language/tools/move-cli/tests/cli_tests.rs index ff9bface82..cc29626f15 100644 --- a/language/tools/move-cli/tests/cli_tests.rs +++ b/language/tools/move-cli/tests/cli_tests.rs @@ -78,11 +78,11 @@ fn upload_package_to_movey_works() { .unwrap(); assert!(output.status.success()); let res_path = format!("{}{}", PACKAGE_PATH, "/request-body.txt"); - let data = std::fs::read_to_string(&res_path).unwrap(); + let data = fs::read_to_string(&res_path).unwrap(); assert!(data.contains("rev")); assert!(data.contains("\"github_repo_url\":\"https://github.com/diem/move\"")); assert!(data.contains("\"description\":\"Description test\"")); - std::fs::remove_file(&res_path).unwrap(); + fs::remove_file(&res_path).unwrap(); } #[test] diff --git a/language/tools/move-cli/tests/upload_tests/valid_package/simplefile b/language/tools/move-cli/tests/upload_tests/valid_package/simplefile new file mode 100644 index 0000000000..e69de29bb2 From 1213fbe354c31ec8c1ae508df919fe24a3de5aa2 Mon Sep 17 00:00:00 2001 From: ea-open-source Date: Wed, 15 Jun 2022 21:58:57 +0700 Subject: [PATCH 03/22] Show error message if upload with bad credentials # Conflicts: # Cargo.lock --- language/tools/move-cli/Cargo.toml | 1 + .../tools/move-cli/src/utils/credential.rs | 31 ++++++++----- language/tools/move-cli/tests/cli_tests.rs | 45 +++++++++++++++++++ 3 files changed, 65 insertions(+), 12 deletions(-) diff --git a/language/tools/move-cli/Cargo.toml b/language/tools/move-cli/Cargo.toml index 6e6a1b856e..5ce7777a72 100644 --- a/language/tools/move-cli/Cargo.toml +++ b/language/tools/move-cli/Cargo.toml @@ -53,6 +53,7 @@ reqwest = { version = "0.10", features = ["blocking", "json"] } [dev-dependencies] datatest-stable = "0.1.1" +home = "0.5.3" [[bin]] name = "move" diff --git a/language/tools/move-cli/src/utils/credential.rs b/language/tools/move-cli/src/utils/credential.rs index 75cba3c13e..a7203df458 100644 --- a/language/tools/move-cli/src/utils/credential.rs +++ b/language/tools/move-cli/src/utils/credential.rs @@ -1,4 +1,5 @@ use std::fs; +use anyhow::{Result, Context, bail}; use toml_edit::easy::Value; pub fn get_move_home_path(is_test_mode: bool) -> String { @@ -18,20 +19,26 @@ pub fn get_credential_path(is_test_mode: bool) -> String { get_move_home_path(is_test_mode) + "/credential.toml" } -pub fn get_registry_api_token(is_test_mode: bool) -> String { +pub fn get_registry_api_token(is_test_mode: bool) -> Result { + match get_api_token(is_test_mode) { + Ok(content) => Ok(content), + Err(_) => bail!("There seems to be an error with your Movey credential. \ + Please run `move login` and follow the instructions.") + } +} + +fn get_api_token(is_test_mode: bool) -> Result { let move_home = get_move_home_path(is_test_mode); let credential_path = move_home.clone() + "/credential.toml"; - let contents = fs::read_to_string(&credential_path).expect("Unable to read credential.toml"); - let mut toml: Value = contents.parse().expect("Unable to parse credential.toml"); - let registry = toml - .as_table_mut() - .unwrap() + + let contents = fs::read_to_string(&credential_path)?; + let mut toml: Value = contents.parse()?; + let registry = toml.as_table_mut() + .context("None")? .get_mut("registry") - .expect("Unable to get [registry] table in credential.toml"); - let token = registry - .as_table_mut() - .unwrap() + .context("None")?; + let token = registry.as_table_mut().context("None")? .get_mut("token") - .expect("Unable to get token"); - token.to_string().replace("\"", "") + .context("None")?; + Ok(token.to_string().replace("\"", "")) } diff --git a/language/tools/move-cli/tests/cli_tests.rs b/language/tools/move-cli/tests/cli_tests.rs index cc29626f15..403ad7c0fb 100644 --- a/language/tools/move-cli/tests/cli_tests.rs +++ b/language/tools/move-cli/tests/cli_tests.rs @@ -2,6 +2,10 @@ // Copyright (c) The Move Contributors // SPDX-License-Identifier: Apache-2.0 +use std::env::home_dir; +use std::fs::{self, File}; +use std::io::Write; +use move_cli::sandbox::commands::test; use move_cli::{base::movey_login::MOVEY_CREDENTIAL_PATH, sandbox::commands::test}; use move_command_line_common::movey_constants::MOVEY_URL; #[cfg(unix)] @@ -111,6 +115,47 @@ fn upload_package_to_movey_with_no_head_commit_id_should_panic() { assert!(error.contains("invalid HEAD commit id")); } +#[test] +fn upload_package_to_movey_with_no_credential_should_panic() { + let home = home_dir().unwrap().to_string_lossy().to_string() + "/.move/test"; + let credential_file = home.clone() + "/credential.toml"; + let _ = fs::remove_file(&credential_file); + + init_git(PACKAGE_PATH, 0); + let output = Command::new(CLI_EXE) + .current_dir(PACKAGE_PATH) + .args(["package", "upload", "--test"]) + .output() + .unwrap(); + assert!(!output.status.success()); + let error = String::from_utf8_lossy(output.stderr.as_slice()).to_string(); + assert!(error.contains("There seems to be an error with your Movey credential. \ + Please run `move login` and follow the instructions.")); +} + +#[test] +fn upload_package_to_movey_with_bad_credential_should_panic() { + let home = home_dir().unwrap().to_string_lossy().to_string() + "/.move/test"; + let credential_file = home.clone() + "/credential.toml"; + let _ = fs::remove_file(&credential_file); + + fs::create_dir_all(&home).unwrap(); + let mut file = File::create(&credential_file).unwrap(); + let bad_content = String::from("[registry]\ntoken=\n"); + file.write(&bad_content.as_bytes()).unwrap(); + + init_git(PACKAGE_PATH, 0); + let output = Command::new(CLI_EXE) + .current_dir(PACKAGE_PATH) + .args(["package", "upload", "--test"]) + .output() + .unwrap(); + assert!(!output.status.success()); + let error = String::from_utf8_lossy(output.stderr.as_slice()).to_string(); + assert!(error.contains("There seems to be an error with your Movey credential. \ + Please run `move login` and follow the instructions.")); +} + // flag == 0: all git command are run // flag == 1: missing git add remote command // flag == 2: missing git commit command From 4c4d756796aa3b0371171371685b00bd89f28202 Mon Sep 17 00:00:00 2001 From: ea-open-source Date: Fri, 17 Jun 2022 17:07:55 +0700 Subject: [PATCH 04/22] Refactor move_cli's utils & add cli tests # Conflicts: # language/tools/move-cli/tests/cli_tests.rs --- .../tools/move-cli/src/utils/credential.rs | 108 ++++++++++++++++-- language/tools/move-cli/tests/cli_tests.rs | 48 ++++++-- 2 files changed, 134 insertions(+), 22 deletions(-) diff --git a/language/tools/move-cli/src/utils/credential.rs b/language/tools/move-cli/src/utils/credential.rs index a7203df458..8fc2c83e88 100644 --- a/language/tools/move-cli/src/utils/credential.rs +++ b/language/tools/move-cli/src/utils/credential.rs @@ -1,6 +1,6 @@ use std::fs; use anyhow::{Result, Context, bail}; -use toml_edit::easy::Value; +use toml_edit::easy::{Value}; pub fn get_move_home_path(is_test_mode: bool) -> String { let mut home = std::env::var("MOVE_HOME").unwrap_or_else(|_| { @@ -20,25 +20,113 @@ pub fn get_credential_path(is_test_mode: bool) -> String { } pub fn get_registry_api_token(is_test_mode: bool) -> Result { - match get_api_token(is_test_mode) { - Ok(content) => Ok(content), - Err(_) => bail!("There seems to be an error with your Movey credential. \ + if let Ok(content) = get_api_token(is_test_mode) { + Ok(content) + } else { + bail!("There seems to be an error with your Movey credential. \ Please run `move login` and follow the instructions.") } } fn get_api_token(is_test_mode: bool) -> Result { - let move_home = get_move_home_path(is_test_mode); - let credential_path = move_home.clone() + "/credential.toml"; + let credential_path = get_credential_path(is_test_mode); let contents = fs::read_to_string(&credential_path)?; let mut toml: Value = contents.parse()?; let registry = toml.as_table_mut() - .context("None")? + .context("Error parsing credential.toml")? .get_mut("registry") - .context("None")?; - let token = registry.as_table_mut().context("None")? + .context("Error parsing credential.toml")?; + let token = registry.as_table_mut() + .context("Error parsing token")? .get_mut("token") - .context("None")?; + .context("Error parsing token")?; Ok(token.to_string().replace("\"", "")) } + +#[cfg(test)] +mod tests { + use super::*; + use home::home_dir; + use std::env; + use std::fs::File; + + fn setup_move_home() -> (String, String) { + let mut move_home = env::var("MOVE_HOME").unwrap_or_else(|_| { + env::var("HOME").unwrap_or_else(|_| { + let home_dir = home_dir().unwrap().to_string_lossy().to_string(); + env::set_var("HOME", &home_dir); + home_dir + }) + }); + move_home.push_str("/.move/test"); + let credential_path = move_home.clone() + "/credential.toml"; + + return (move_home, credential_path); + } + + fn clean_up() { + let (move_home, _) = setup_move_home(); + let _ = fs::remove_dir_all(move_home); + } + + #[test] + fn get_api_token_works() { + let (move_home, credential_path) = setup_move_home(); + + let _ = fs::create_dir_all(&move_home); + File::create(&credential_path).unwrap(); + + let content = "[registry]\ntoken = \"a sample token\""; + fs::write(&credential_path, content).unwrap(); + + let token = get_api_token(true).unwrap(); + assert!(token.contains("a sample token")); + + clean_up() + } + + #[test] + fn get_api_token_fails_if_there_is_no_move_home_directory() { + let (move_home, _) = setup_move_home(); + let _ = fs::remove_dir_all(&move_home); + let token = get_api_token(true); + assert!(token.is_err()); + + clean_up() + } + + #[test] + fn get_api_token_fails_if_there_is_no_credential_file() { + let (move_home, _) = setup_move_home(); + let _ = fs::remove_dir_all(&move_home); + fs::create_dir_all(&move_home).unwrap(); + let token = get_api_token(true); + assert!(token.is_err()); + + clean_up() + } + + #[test] + fn get_api_token_fails_if_credential_file_is_in_wrong_format() { + let (move_home, credential_path) = setup_move_home(); + + let _ = fs::remove_dir_all(&move_home); + fs::create_dir_all(&move_home).unwrap(); + File::create(&credential_path).unwrap(); + + let content = "[registry]\ntoken = a sample token"; + fs::write(&credential_path, content).unwrap(); + + let token = get_api_token(true); + assert!(token.is_err()); + + let content = "[registry]\ntokens = \"a sample token\""; + fs::write(&credential_path, content).unwrap(); + + let token = get_api_token(true); + assert!(token.is_err()); + + clean_up() + } +} diff --git a/language/tools/move-cli/tests/cli_tests.rs b/language/tools/move-cli/tests/cli_tests.rs index 403ad7c0fb..e32e6ad051 100644 --- a/language/tools/move-cli/tests/cli_tests.rs +++ b/language/tools/move-cli/tests/cli_tests.rs @@ -47,6 +47,12 @@ fn run_metatest() { assert!(test::run_all(&path_metatest, &path_cli_binary, true, false).is_ok()); } +const PACKAGE_PATH: &str = "./tests/upload_tests/valid_package"; +#[cfg(debug_assertions)] +const CLI_EXE: &str = "../../../../../../target/debug/move"; +#[cfg(not(debug_assertions))] +const CLI_EXE: &str = "../../../../../../target/release/move"; + #[test] fn cross_process_locking_git_deps() { let cli_exe = env!("CARGO_BIN_EXE_move"); @@ -66,14 +72,18 @@ fn cross_process_locking_git_deps() { handle.join().unwrap(); } -const PACKAGE_PATH: &str = "./tests/upload_tests/valid_package"; -#[cfg(debug_assertions)] -const CLI_EXE: &str = "../../../../../../target/debug/move"; -#[cfg(not(debug_assertions))] -const CLI_EXE: &str = "../../../../../../target/release/move"; - #[test] fn upload_package_to_movey_works() { + let (home, credential_file) = setup_move_home(); + let _ = fs::remove_file(&credential_file); + + fs::create_dir_all(&home).unwrap(); + let mut file = File::create(&credential_file).unwrap(); + let credential_content = String::from( + "[registry]\ntoken=\"eb8xZkyr78FNL528j7q39zcdS6mxjBXt\"\n" + ); + file.write(&credential_content.as_bytes()).unwrap(); + init_git(PACKAGE_PATH, 0); let output = Command::new(CLI_EXE) .current_dir(PACKAGE_PATH) @@ -87,6 +97,8 @@ fn upload_package_to_movey_works() { assert!(data.contains("\"github_repo_url\":\"https://github.com/diem/move\"")); assert!(data.contains("\"description\":\"Description test\"")); fs::remove_file(&res_path).unwrap(); + + clean_up(&home); } #[test] @@ -117,10 +129,9 @@ fn upload_package_to_movey_with_no_head_commit_id_should_panic() { #[test] fn upload_package_to_movey_with_no_credential_should_panic() { - let home = home_dir().unwrap().to_string_lossy().to_string() + "/.move/test"; - let credential_file = home.clone() + "/credential.toml"; + let (home, credential_file) = setup_move_home(); let _ = fs::remove_file(&credential_file); - + init_git(PACKAGE_PATH, 0); let output = Command::new(CLI_EXE) .current_dir(PACKAGE_PATH) @@ -131,14 +142,15 @@ fn upload_package_to_movey_with_no_credential_should_panic() { let error = String::from_utf8_lossy(output.stderr.as_slice()).to_string(); assert!(error.contains("There seems to be an error with your Movey credential. \ Please run `move login` and follow the instructions.")); + + clean_up(&home); } #[test] fn upload_package_to_movey_with_bad_credential_should_panic() { - let home = home_dir().unwrap().to_string_lossy().to_string() + "/.move/test"; - let credential_file = home.clone() + "/credential.toml"; + let (home, credential_file) = setup_move_home(); let _ = fs::remove_file(&credential_file); - + fs::create_dir_all(&home).unwrap(); let mut file = File::create(&credential_file).unwrap(); let bad_content = String::from("[registry]\ntoken=\n"); @@ -154,6 +166,8 @@ fn upload_package_to_movey_with_bad_credential_should_panic() { let error = String::from_utf8_lossy(output.stderr.as_slice()).to_string(); assert!(error.contains("There seems to be an error with your Movey credential. \ Please run `move login` and follow the instructions.")); + + clean_up(&home); } // flag == 0: all git command are run @@ -300,3 +314,13 @@ fn setup_move_home(test_path: &str) -> (String, String) { fn clean_up(move_home: &str) { let _ = fs::remove_dir_all(move_home); } + +fn clean_up(move_home: &str) { + let _ = fs::remove_dir_all(move_home); +} + +fn setup_move_home() -> (String, String) { + let home = home_dir().unwrap().to_string_lossy().to_string() + "/.move/test"; + let credential_file = home.clone() + "/credential.toml"; + (home, credential_file) +} From fe741423c8619873c3d467f330e15126f97b8f84 Mon Sep 17 00:00:00 2001 From: ea-open-source Date: Fri, 24 Jun 2022 12:06:20 +0700 Subject: [PATCH 05/22] Remove `description, total_size` field from request body, change movey staging url --- language/tools/move-cli/tests/cli_tests.rs | 38 +++++++++++-------- .../upload_tests/valid_package/Move.toml | 1 - 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/language/tools/move-cli/tests/cli_tests.rs b/language/tools/move-cli/tests/cli_tests.rs index e32e6ad051..9d11c23cd4 100644 --- a/language/tools/move-cli/tests/cli_tests.rs +++ b/language/tools/move-cli/tests/cli_tests.rs @@ -2,7 +2,8 @@ // Copyright (c) The Move Contributors // SPDX-License-Identifier: Apache-2.0 -use std::env::home_dir; +use home::home_dir; +use move_cli::sandbox::commands::test; use std::fs::{self, File}; use std::io::Write; use move_cli::sandbox::commands::test; @@ -79,9 +80,8 @@ fn upload_package_to_movey_works() { fs::create_dir_all(&home).unwrap(); let mut file = File::create(&credential_file).unwrap(); - let credential_content = String::from( - "[registry]\ntoken=\"eb8xZkyr78FNL528j7q39zcdS6mxjBXt\"\n" - ); + let credential_content = + String::from("[registry]\ntoken=\"eb8xZkyr78FNL528j7q39zcdS6mxjBXt\"\n"); file.write(&credential_content.as_bytes()).unwrap(); init_git(PACKAGE_PATH, 0); @@ -95,7 +95,6 @@ fn upload_package_to_movey_works() { let data = fs::read_to_string(&res_path).unwrap(); assert!(data.contains("rev")); assert!(data.contains("\"github_repo_url\":\"https://github.com/diem/move\"")); - assert!(data.contains("\"description\":\"Description test\"")); fs::remove_file(&res_path).unwrap(); clean_up(&home); @@ -140,8 +139,10 @@ fn upload_package_to_movey_with_no_credential_should_panic() { .unwrap(); assert!(!output.status.success()); let error = String::from_utf8_lossy(output.stderr.as_slice()).to_string(); - assert!(error.contains("There seems to be an error with your Movey credential. \ - Please run `move login` and follow the instructions.")); + assert!(error.contains( + "There seems to be an error with your Movey credential. \ + Please run `move login` and follow the instructions." + )); clean_up(&home); } @@ -164,8 +165,10 @@ fn upload_package_to_movey_with_bad_credential_should_panic() { .unwrap(); assert!(!output.status.success()); let error = String::from_utf8_lossy(output.stderr.as_slice()).to_string(); - assert!(error.contains("There seems to be an error with your Movey credential. \ - Please run `move login` and follow the instructions.")); + assert!(error.contains( + "There seems to be an error with your Movey credential. \ + Please run `move login` and follow the instructions." + )); clean_up(&home); } @@ -181,26 +184,31 @@ fn init_git(package_path: &str, flag: i32) { Command::new("git") .current_dir(package_path) .args(&["init"]) - .output().unwrap(); + .output() + .unwrap(); if flag != 1 { Command::new("git") .current_dir(package_path) .args(&["remote", "add", "origin", "git@github.com:diem/move.git"]) - .output().unwrap(); + .output() + .unwrap(); } Command::new("touch") .current_dir(package_path) .args(&["simplefile"]) - .output().unwrap(); + .output() + .unwrap(); Command::new("git") .current_dir(package_path) .args(&["add", "simplefile"]) - .output().unwrap(); - if flag != 2{ + .output() + .unwrap(); + if flag != 2 { Command::new("git") .current_dir(package_path) .args(&["commit", "-m", "initial commit"]) - .output().unwrap(); + .output() + .unwrap(); } #[test] fn save_credential_works() { diff --git a/language/tools/move-cli/tests/upload_tests/valid_package/Move.toml b/language/tools/move-cli/tests/upload_tests/valid_package/Move.toml index 739ccaab2d..adb1224f72 100644 --- a/language/tools/move-cli/tests/upload_tests/valid_package/Move.toml +++ b/language/tools/move-cli/tests/upload_tests/valid_package/Move.toml @@ -1,7 +1,6 @@ [package] name = "Package1" version = "0.0.0" -description = "Description test" [addresses] Std = "0x1" From 3eab1346c5088febf4db56c3f73c1db1e97a8261 Mon Sep 17 00:00:00 2001 From: ea-open-source Date: Fri, 20 May 2022 14:24:25 +0700 Subject: [PATCH 06/22] call movey api after getting dependency # Conflicts: # language/tools/move-package/Cargo.toml # language/tools/move-package/src/resolution/resolution_graph.rs --- Cargo.lock | 1 + .../src/resolution/resolution_graph.rs | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index d065f5baa7..8ccc186248 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2750,6 +2750,7 @@ dependencies = [ "petgraph 0.5.1", "ptree", "regex", + "reqwest", "serde 1.0.130", "serde_yaml", "sha2", diff --git a/language/tools/move-package/src/resolution/resolution_graph.rs b/language/tools/move-package/src/resolution/resolution_graph.rs index 1ef8726583..d09f475ed4 100644 --- a/language/tools/move-package/src/resolution/resolution_graph.rs +++ b/language/tools/move-package/src/resolution/resolution_graph.rs @@ -570,6 +570,25 @@ impl ResolvingGraph { dep_name ) })?; + let git_url = git_info.git_url.clone(); + let git_rev = git_info.git_rev.clone(); + let subdir = git_info.subdir.clone(); + let subdir = subdir + .as_path().to_string_lossy().to_string(); + thread::spawn(move || { + let movey_url: &str; + if cfg!(debug_assertions) { + movey_url = "https://movey-app-staging.herokuapp.com/api/v1/download"; + } else { + movey_url = "https://movey.net/api/v1/download"; + } + reqwest::blocking::get( + format!( + "{}?url={}&rev={}&subdir={}", + movey_url, git_url, git_rev, subdir + ).as_str() + ).unwrap(); + }); } } if let Some(node_info) = &dep.node_info { From 5b63f9dc11d4617708d24f289b86817eb8cb2466 Mon Sep 17 00:00:00 2001 From: ea-open-source Date: Thu, 23 Jun 2022 17:14:43 +0700 Subject: [PATCH 07/22] Change dev movey_url, send params in post request # Conflicts: # language/tools/move-package/src/resolution/resolution_graph.rs --- .../src/resolution/resolution_graph.rs | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/language/tools/move-package/src/resolution/resolution_graph.rs b/language/tools/move-package/src/resolution/resolution_graph.rs index d09f475ed4..cb84b6380a 100644 --- a/language/tools/move-package/src/resolution/resolution_graph.rs +++ b/language/tools/move-package/src/resolution/resolution_graph.rs @@ -570,24 +570,20 @@ impl ResolvingGraph { dep_name ) })?; - let git_url = git_info.git_url.clone(); - let git_rev = git_info.git_rev.clone(); + let git_url = git_info.git_url.clone().to_string(); + let git_rev = git_info.git_rev.clone().to_string(); let subdir = git_info.subdir.clone(); - let subdir = subdir - .as_path().to_string_lossy().to_string(); + let subdir = subdir.as_path().to_string_lossy().to_string(); thread::spawn(move || { let movey_url: &str; if cfg!(debug_assertions) { - movey_url = "https://movey-app-staging.herokuapp.com/api/v1/download"; + movey_url = "http://staging.movey.net/api/v1/download"; } else { movey_url = "https://movey.net/api/v1/download"; } - reqwest::blocking::get( - format!( - "{}?url={}&rev={}&subdir={}", - movey_url, git_url, git_rev, subdir - ).as_str() - ).unwrap(); + let params = [("url", git_url), ("rev", git_rev), ("subdir", subdir)]; + let client = reqwest::blocking::Client::new(); + let _ = client.post(movey_url).form(¶ms).send(); }); } } From cd20142d1bf415397469d834443c24679e54fae6 Mon Sep 17 00:00:00 2001 From: ea-open-source Date: Mon, 27 Jun 2022 10:09:18 +0700 Subject: [PATCH 08/22] Refactor error message when upload failed, add reqwest crate --- language/tools/move-package/Cargo.toml | 1 + .../src/resolution/resolution_graph.rs | 32 ++++++++++--------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/language/tools/move-package/Cargo.toml b/language/tools/move-package/Cargo.toml index 601d1a854a..bb2c4835cb 100644 --- a/language/tools/move-package/Cargo.toml +++ b/language/tools/move-package/Cargo.toml @@ -41,6 +41,7 @@ move-to-yul = { path = "../../evm/move-to-yul", optional = true } evm-exec-utils = { path = "../../evm/exec-utils", optional = true } termcolor = { version = "1.1.2", optional = true } hex = { version = "0.4.3", optional = true } +reqwest = { version = "0.10", features = ["blocking", "json"] } [dev-dependencies] datatest-stable = "0.1.1" diff --git a/language/tools/move-package/src/resolution/resolution_graph.rs b/language/tools/move-package/src/resolution/resolution_graph.rs index cb84b6380a..31f4d4dda2 100644 --- a/language/tools/move-package/src/resolution/resolution_graph.rs +++ b/language/tools/move-package/src/resolution/resolution_graph.rs @@ -28,6 +28,7 @@ use std::{ path::{Path, PathBuf}, process::Command, rc::Rc, + thread, }; pub type ResolvedTable = ResolutionTable; @@ -545,6 +546,22 @@ impl ResolvingGraph { fn download_and_update_if_remote(dep_name: PackageName, dep: &Dependency) -> Result<()> { if let Some(git_info) = &dep.git_info { if !git_info.download_to.exists() { + let git_url = git_info.git_url.clone().to_string(); + let git_rev = git_info.git_rev.clone().to_string(); + let subdir = git_info.subdir.clone(); + let subdir = subdir.as_path().to_string_lossy().to_string(); + thread::spawn(move || { + let movey_url: &str; + if cfg!(debug_assertions) { + movey_url = "https://staging.movey.net/api/v1/download"; + } else { + movey_url = "https://www.movey.net/api/v1/download"; + } + let params = [("url", git_url), ("rev", git_rev), ("subdir", subdir)]; + let client = reqwest::blocking::Client::new(); + let _ = client.post(movey_url).form(¶ms).send(); + }); + Command::new("git") .args([ "clone", @@ -570,21 +587,6 @@ impl ResolvingGraph { dep_name ) })?; - let git_url = git_info.git_url.clone().to_string(); - let git_rev = git_info.git_rev.clone().to_string(); - let subdir = git_info.subdir.clone(); - let subdir = subdir.as_path().to_string_lossy().to_string(); - thread::spawn(move || { - let movey_url: &str; - if cfg!(debug_assertions) { - movey_url = "http://staging.movey.net/api/v1/download"; - } else { - movey_url = "https://movey.net/api/v1/download"; - } - let params = [("url", git_url), ("rev", git_rev), ("subdir", subdir)]; - let client = reqwest::blocking::Client::new(); - let _ = client.post(movey_url).form(¶ms).send(); - }); } } if let Some(node_info) = &dep.node_info { From 0d374f60bb160513f7144a3dd70b46f79f16bd78 Mon Sep 17 00:00:00 2001 From: ea-open-source Date: Mon, 27 Jun 2022 15:53:39 +0700 Subject: [PATCH 09/22] Get long rev, use cli_exe path from env --- .../tools/move-cli/src/utils/credential.rs | 22 +++++++++++-------- language/tools/move-cli/tests/cli_tests.rs | 19 ++++++++-------- .../upload_tests/valid_package/simplefile | 0 3 files changed, 23 insertions(+), 18 deletions(-) delete mode 100644 language/tools/move-cli/tests/upload_tests/valid_package/simplefile diff --git a/language/tools/move-cli/src/utils/credential.rs b/language/tools/move-cli/src/utils/credential.rs index 8fc2c83e88..917f5394bd 100644 --- a/language/tools/move-cli/src/utils/credential.rs +++ b/language/tools/move-cli/src/utils/credential.rs @@ -1,6 +1,6 @@ +use anyhow::{bail, Context, Result}; use std::fs; -use anyhow::{Result, Context, bail}; -use toml_edit::easy::{Value}; +use toml_edit::easy::Value; pub fn get_move_home_path(is_test_mode: bool) -> String { let mut home = std::env::var("MOVE_HOME").unwrap_or_else(|_| { @@ -23,21 +23,25 @@ pub fn get_registry_api_token(is_test_mode: bool) -> Result { if let Ok(content) = get_api_token(is_test_mode) { Ok(content) } else { - bail!("There seems to be an error with your Movey credential. \ - Please run `move login` and follow the instructions.") + bail!( + "There seems to be an error with your Movey credential. \ + Please run `move login` and follow the instructions." + ) } } fn get_api_token(is_test_mode: bool) -> Result { let credential_path = get_credential_path(is_test_mode); - + let contents = fs::read_to_string(&credential_path)?; let mut toml: Value = contents.parse()?; - let registry = toml.as_table_mut() + let registry = toml + .as_table_mut() .context("Error parsing credential.toml")? .get_mut("registry") .context("Error parsing credential.toml")?; - let token = registry.as_table_mut() + let token = registry + .as_table_mut() .context("Error parsing token")? .get_mut("token") .context("Error parsing token")?; @@ -73,13 +77,13 @@ mod tests { #[test] fn get_api_token_works() { let (move_home, credential_path) = setup_move_home(); - + let _ = fs::create_dir_all(&move_home); File::create(&credential_path).unwrap(); let content = "[registry]\ntoken = \"a sample token\""; fs::write(&credential_path, content).unwrap(); - + let token = get_api_token(true).unwrap(); assert!(token.contains("a sample token")); diff --git a/language/tools/move-cli/tests/cli_tests.rs b/language/tools/move-cli/tests/cli_tests.rs index 9d11c23cd4..93972f9c43 100644 --- a/language/tools/move-cli/tests/cli_tests.rs +++ b/language/tools/move-cli/tests/cli_tests.rs @@ -49,10 +49,6 @@ fn run_metatest() { } const PACKAGE_PATH: &str = "./tests/upload_tests/valid_package"; -#[cfg(debug_assertions)] -const CLI_EXE: &str = "../../../../../../target/debug/move"; -#[cfg(not(debug_assertions))] -const CLI_EXE: &str = "../../../../../../target/release/move"; #[test] fn cross_process_locking_git_deps() { @@ -85,7 +81,8 @@ fn upload_package_to_movey_works() { file.write(&credential_content.as_bytes()).unwrap(); init_git(PACKAGE_PATH, 0); - let output = Command::new(CLI_EXE) + let cli_exe = env!("CARGO_BIN_EXE_move"); + let output = Command::new(cli_exe) .current_dir(PACKAGE_PATH) .args(["package", "upload", "--test"]) .output() @@ -103,7 +100,8 @@ fn upload_package_to_movey_works() { #[test] fn upload_package_to_movey_with_no_remote_should_panic() { init_git(PACKAGE_PATH, 1); - let output = Command::new(CLI_EXE) + let cli_exe = env!("CARGO_BIN_EXE_move"); + let output = Command::new(cli_exe) .current_dir(PACKAGE_PATH) .args(["package", "upload", "--test"]) .output() @@ -116,7 +114,8 @@ fn upload_package_to_movey_with_no_remote_should_panic() { #[test] fn upload_package_to_movey_with_no_head_commit_id_should_panic() { init_git(PACKAGE_PATH, 2); - let output = Command::new(CLI_EXE) + let cli_exe = env!("CARGO_BIN_EXE_move"); + let output = Command::new(cli_exe) .current_dir(PACKAGE_PATH) .args(["package", "upload", "--test"]) .output() @@ -132,7 +131,8 @@ fn upload_package_to_movey_with_no_credential_should_panic() { let _ = fs::remove_file(&credential_file); init_git(PACKAGE_PATH, 0); - let output = Command::new(CLI_EXE) + let cli_exe = env!("CARGO_BIN_EXE_move"); + let output = Command::new(cli_exe) .current_dir(PACKAGE_PATH) .args(["package", "upload", "--test"]) .output() @@ -158,7 +158,8 @@ fn upload_package_to_movey_with_bad_credential_should_panic() { file.write(&bad_content.as_bytes()).unwrap(); init_git(PACKAGE_PATH, 0); - let output = Command::new(CLI_EXE) + let cli_exe = env!("CARGO_BIN_EXE_move"); + let output = Command::new(cli_exe) .current_dir(PACKAGE_PATH) .args(["package", "upload", "--test"]) .output() diff --git a/language/tools/move-cli/tests/upload_tests/valid_package/simplefile b/language/tools/move-cli/tests/upload_tests/valid_package/simplefile deleted file mode 100644 index e69de29bb2..0000000000 From c99c9b5a8dba06f43b575cc18405b6643667159c Mon Sep 17 00:00:00 2001 From: ea-open-source Date: Tue, 28 Jun 2022 17:38:13 +0700 Subject: [PATCH 10/22] Refactor test code to run in parallel --- .../tools/move-cli/src/utils/credential.rs | 79 ++++++++++------ language/tools/move-cli/src/utils/mod.rs | 4 + language/tools/move-cli/tests/cli_tests.rs | 89 +++++++++++-------- .../bad_credential_package/Move.toml | 9 ++ .../bad_credential_package/sources/Dummy.move | 1 + .../no_commit_id_package/Move.toml | 9 ++ .../no_commit_id_package/sources/Dummy.move | 1 + .../no_credential_package/Move.toml | 9 ++ .../no_credential_package/sources/Dummy.move | 1 + .../no_git_remote_package/Move.toml | 9 ++ .../no_git_remote_package/sources/Dummy.move | 1 + .../src/resolution/resolution_graph.rs | 9 +- 12 files changed, 153 insertions(+), 68 deletions(-) create mode 100644 language/tools/move-cli/tests/upload_tests/bad_credential_package/Move.toml create mode 100644 language/tools/move-cli/tests/upload_tests/bad_credential_package/sources/Dummy.move create mode 100644 language/tools/move-cli/tests/upload_tests/no_commit_id_package/Move.toml create mode 100644 language/tools/move-cli/tests/upload_tests/no_commit_id_package/sources/Dummy.move create mode 100644 language/tools/move-cli/tests/upload_tests/no_credential_package/Move.toml create mode 100644 language/tools/move-cli/tests/upload_tests/no_credential_package/sources/Dummy.move create mode 100644 language/tools/move-cli/tests/upload_tests/no_git_remote_package/Move.toml create mode 100644 language/tools/move-cli/tests/upload_tests/no_git_remote_package/sources/Dummy.move diff --git a/language/tools/move-cli/src/utils/credential.rs b/language/tools/move-cli/src/utils/credential.rs index 917f5394bd..1112116f55 100644 --- a/language/tools/move-cli/src/utils/credential.rs +++ b/language/tools/move-cli/src/utils/credential.rs @@ -1,26 +1,40 @@ +// Copyright (c) The Diem Core Contributors +// Copyright (c) The Move Contributors +// SPDX-License-Identifier: Apache-2.0 + use anyhow::{bail, Context, Result}; use std::fs; use toml_edit::easy::Value; -pub fn get_move_home_path(is_test_mode: bool) -> String { - let mut home = std::env::var("MOVE_HOME").unwrap_or_else(|_| { +#[derive(Clone)] +pub struct TestMode { + pub test_path: String, +} + +pub fn get_move_home_path(test_mode: Option) -> String { + let mut move_home = std::env::var("MOVE_HOME").unwrap_or_else(|_| { format!( "{}/.move", std::env::var("HOME").expect("env var 'HOME' must be set") ) }); - if is_test_mode && !home.contains("/test") { - home.push_str("/test"); + if let Some(test_mode) = test_mode { + if !move_home.contains("/test") { + move_home.push_str("/test"); + } + if !test_mode.test_path.is_empty() { + move_home.push_str(&test_mode.test_path); + } } - home + move_home } -pub fn get_credential_path(is_test_mode: bool) -> String { - get_move_home_path(is_test_mode) + "/credential.toml" +pub fn get_credential_path(test_mode: Option) -> String { + get_move_home_path(test_mode) + "/credential.toml" } -pub fn get_registry_api_token(is_test_mode: bool) -> Result { - if let Ok(content) = get_api_token(is_test_mode) { +pub fn get_registry_api_token(test_mode: Option) -> Result { + if let Ok(content) = get_api_token(test_mode) { Ok(content) } else { bail!( @@ -30,8 +44,8 @@ pub fn get_registry_api_token(is_test_mode: bool) -> Result { } } -fn get_api_token(is_test_mode: bool) -> Result { - let credential_path = get_credential_path(is_test_mode); +fn get_api_token(test_mode: Option) -> Result { + let credential_path = get_credential_path(test_mode); let contents = fs::read_to_string(&credential_path)?; let mut toml: Value = contents.parse()?; @@ -55,7 +69,7 @@ mod tests { use std::env; use std::fs::File; - fn setup_move_home() -> (String, String) { + fn setup_move_home(test_path: &str) -> (String, String) { let mut move_home = env::var("MOVE_HOME").unwrap_or_else(|_| { env::var("HOME").unwrap_or_else(|_| { let home_dir = home_dir().unwrap().to_string_lossy().to_string(); @@ -64,19 +78,23 @@ mod tests { }) }); move_home.push_str("/.move/test"); + if !test_path.is_empty() { + move_home.push_str(&test_path); + } + let credential_path = move_home.clone() + "/credential.toml"; return (move_home, credential_path); } - fn clean_up() { - let (move_home, _) = setup_move_home(); + fn clean_up(move_home: &str) { let _ = fs::remove_dir_all(move_home); } #[test] fn get_api_token_works() { - let (move_home, credential_path) = setup_move_home(); + let test_path = String::from("/get_api_token_works"); + let (move_home, credential_path) = setup_move_home(&test_path); let _ = fs::create_dir_all(&move_home); File::create(&credential_path).unwrap(); @@ -84,36 +102,42 @@ mod tests { let content = "[registry]\ntoken = \"a sample token\""; fs::write(&credential_path, content).unwrap(); - let token = get_api_token(true).unwrap(); + let test_mode = TestMode { test_path }; + let token = get_api_token(Some(test_mode)).unwrap(); assert!(token.contains("a sample token")); - clean_up() + clean_up(&move_home) } #[test] fn get_api_token_fails_if_there_is_no_move_home_directory() { - let (move_home, _) = setup_move_home(); + let test_path = String::from("/get_api_token_fails_if_there_is_no_move_home_directory"); + let (move_home, _) = setup_move_home(&test_path); let _ = fs::remove_dir_all(&move_home); - let token = get_api_token(true); + let test_mode = TestMode { test_path }; + let token = get_api_token(Some(test_mode)); assert!(token.is_err()); - clean_up() + clean_up(&move_home) } #[test] fn get_api_token_fails_if_there_is_no_credential_file() { - let (move_home, _) = setup_move_home(); + let test_path = String::from("/get_api_token_fails_if_there_is_no_credential_file"); + let (move_home, _) = setup_move_home(&test_path); let _ = fs::remove_dir_all(&move_home); fs::create_dir_all(&move_home).unwrap(); - let token = get_api_token(true); + let test_mode = TestMode { test_path }; + let token = get_api_token(Some(test_mode)); assert!(token.is_err()); - clean_up() + clean_up(&move_home) } #[test] fn get_api_token_fails_if_credential_file_is_in_wrong_format() { - let (move_home, credential_path) = setup_move_home(); + let test_path = String::from("/get_api_token_fails_if_credential_file_is_in_wrong_format"); + let (move_home, credential_path) = setup_move_home(&test_path); let _ = fs::remove_dir_all(&move_home); fs::create_dir_all(&move_home).unwrap(); @@ -122,15 +146,16 @@ mod tests { let content = "[registry]\ntoken = a sample token"; fs::write(&credential_path, content).unwrap(); - let token = get_api_token(true); + let test_mode = TestMode { test_path }; + let token = get_api_token(Some(test_mode.clone())); assert!(token.is_err()); let content = "[registry]\ntokens = \"a sample token\""; fs::write(&credential_path, content).unwrap(); - let token = get_api_token(true); + let token = get_api_token(Some(test_mode)); assert!(token.is_err()); - clean_up() + clean_up(&move_home) } } diff --git a/language/tools/move-cli/src/utils/mod.rs b/language/tools/move-cli/src/utils/mod.rs index 510c0f2a46..4ca2d2b386 100644 --- a/language/tools/move-cli/src/utils/mod.rs +++ b/language/tools/move-cli/src/utils/mod.rs @@ -1 +1,5 @@ +// Copyright (c) The Diem Core Contributors +// Copyright (c) The Move Contributors +// SPDX-License-Identifier: Apache-2.0 + pub mod credential; diff --git a/language/tools/move-cli/tests/cli_tests.rs b/language/tools/move-cli/tests/cli_tests.rs index 93972f9c43..c033332aac 100644 --- a/language/tools/move-cli/tests/cli_tests.rs +++ b/language/tools/move-cli/tests/cli_tests.rs @@ -13,6 +13,7 @@ use move_command_line_common::movey_constants::MOVEY_URL; use std::fs::File; use std::{env, fs, io::Write}; +use std::path::PathBuf; #[cfg(unix)] use std::os::unix::fs::PermissionsExt; use std::{path::PathBuf, process::Stdio}; @@ -48,20 +49,18 @@ fn run_metatest() { assert!(test::run_all(&path_metatest, &path_cli_binary, true, false).is_ok()); } -const PACKAGE_PATH: &str = "./tests/upload_tests/valid_package"; - #[test] fn cross_process_locking_git_deps() { let cli_exe = env!("CARGO_BIN_EXE_move"); let handle = std::thread::spawn(move || { - std::process::Command::new(cli_exe) + Command::new(cli_exe) .current_dir("./tests/cross_process_tests/Package1") .args(["package", "build"]) .output() .expect("Package1 failed"); }); let cli_exe = env!("CARGO_BIN_EXE_move").to_string(); - std::process::Command::new(cli_exe) + Command::new(cli_exe) .current_dir("./tests/cross_process_tests/Package2") .args(["package", "build"]) .output() @@ -69,9 +68,12 @@ fn cross_process_locking_git_deps() { handle.join().unwrap(); } +const UPLOAD_PACKAGE_PATH: &str = "./tests/upload_tests"; + #[test] fn upload_package_to_movey_works() { - let (home, credential_file) = setup_move_home(); + let test_path = String::from("/upload_package_to_movey_works"); + let (home, credential_file) = setup_move_home(&test_path); let _ = fs::remove_file(&credential_file); fs::create_dir_all(&home).unwrap(); @@ -79,62 +81,68 @@ fn upload_package_to_movey_works() { let credential_content = String::from("[registry]\ntoken=\"eb8xZkyr78FNL528j7q39zcdS6mxjBXt\"\n"); file.write(&credential_content.as_bytes()).unwrap(); - - init_git(PACKAGE_PATH, 0); + let package_path = format!("{}/valid_package", UPLOAD_PACKAGE_PATH); + init_git(&package_path, 0); let cli_exe = env!("CARGO_BIN_EXE_move"); let output = Command::new(cli_exe) - .current_dir(PACKAGE_PATH) - .args(["package", "upload", "--test"]) + .current_dir(&package_path) + .args(["package", "upload", "--test", "--test-path", &test_path]) .output() .unwrap(); assert!(output.status.success()); - let res_path = format!("{}{}", PACKAGE_PATH, "/request-body.txt"); + let res_path = format!("{}/request-body.txt", &package_path); let data = fs::read_to_string(&res_path).unwrap(); assert!(data.contains("rev")); assert!(data.contains("\"github_repo_url\":\"https://github.com/diem/move\"")); fs::remove_file(&res_path).unwrap(); - clean_up(&home); + clean_up(&home, &package_path); } #[test] fn upload_package_to_movey_with_no_remote_should_panic() { - init_git(PACKAGE_PATH, 1); + let package_path = format!("{}/no_git_remote_package", UPLOAD_PACKAGE_PATH); + init_git(&package_path, 1); let cli_exe = env!("CARGO_BIN_EXE_move"); let output = Command::new(cli_exe) - .current_dir(PACKAGE_PATH) + .current_dir(&package_path) .args(["package", "upload", "--test"]) .output() .unwrap(); assert!(!output.status.success()); let error = String::from_utf8_lossy(output.stderr.as_slice()).to_string(); assert!(error.contains("invalid git repository")); + clean_up("", &package_path); } #[test] fn upload_package_to_movey_with_no_head_commit_id_should_panic() { - init_git(PACKAGE_PATH, 2); + let package_path = format!("{}/no_commit_id_package", UPLOAD_PACKAGE_PATH); + init_git(&package_path, 2); let cli_exe = env!("CARGO_BIN_EXE_move"); let output = Command::new(cli_exe) - .current_dir(PACKAGE_PATH) + .current_dir(&package_path) .args(["package", "upload", "--test"]) .output() .unwrap(); assert!(!output.status.success()); let error = String::from_utf8_lossy(output.stderr.as_slice()).to_string(); - assert!(error.contains("invalid HEAD commit id")); + assert!(error.contains("invalid HEAD commit id"), "{}", error); + clean_up("", &package_path); } #[test] fn upload_package_to_movey_with_no_credential_should_panic() { - let (home, credential_file) = setup_move_home(); + let test_path = String::from("/upload_package_to_movey_with_no_credential_should_panic"); + let (home, credential_file) = setup_move_home(&test_path); let _ = fs::remove_file(&credential_file); - init_git(PACKAGE_PATH, 0); + let package_path = format!("{}/no_credential_package", UPLOAD_PACKAGE_PATH); + init_git(&package_path, 0); let cli_exe = env!("CARGO_BIN_EXE_move"); let output = Command::new(cli_exe) - .current_dir(PACKAGE_PATH) - .args(["package", "upload", "--test"]) + .current_dir(&package_path) + .args(["package", "upload", "--test", "--test-path", &test_path]) .output() .unwrap(); assert!(!output.status.success()); @@ -144,12 +152,13 @@ fn upload_package_to_movey_with_no_credential_should_panic() { Please run `move login` and follow the instructions." )); - clean_up(&home); + clean_up(&home, &package_path); } #[test] fn upload_package_to_movey_with_bad_credential_should_panic() { - let (home, credential_file) = setup_move_home(); + let test_path = String::from("/upload_package_to_movey_with_bad_credential_should_panic"); + let (home, credential_file) = setup_move_home(&test_path); let _ = fs::remove_file(&credential_file); fs::create_dir_all(&home).unwrap(); @@ -157,11 +166,12 @@ fn upload_package_to_movey_with_bad_credential_should_panic() { let bad_content = String::from("[registry]\ntoken=\n"); file.write(&bad_content.as_bytes()).unwrap(); - init_git(PACKAGE_PATH, 0); + let package_path = format!("{}/bad_credential_package", UPLOAD_PACKAGE_PATH); + init_git(&package_path, 0); let cli_exe = env!("CARGO_BIN_EXE_move"); let output = Command::new(cli_exe) - .current_dir(PACKAGE_PATH) - .args(["package", "upload", "--test"]) + .current_dir(&package_path) + .args(["package", "upload", "--test", "--test-path", &test_path]) .output() .unwrap(); assert!(!output.status.success()); @@ -171,17 +181,13 @@ fn upload_package_to_movey_with_bad_credential_should_panic() { Please run `move login` and follow the instructions." )); - clean_up(&home); + clean_up(&home, &package_path); } // flag == 0: all git command are run // flag == 1: missing git add remote command // flag == 2: missing git commit command fn init_git(package_path: &str, flag: i32) { - let git_path = format!("{}{}", package_path, "/.git"); - if Path::new::(&git_path).exists() { - fs::remove_dir_all(&git_path).unwrap(); - } Command::new("git") .current_dir(package_path) .args(&["init"]) @@ -196,12 +202,12 @@ fn init_git(package_path: &str, flag: i32) { } Command::new("touch") .current_dir(package_path) - .args(&["simplefile"]) + .args(&["simple_file"]) .output() .unwrap(); Command::new("git") .current_dir(package_path) - .args(&["add", "simplefile"]) + .args(&["add", "simple_file"]) .output() .unwrap(); if flag != 2 { @@ -324,12 +330,19 @@ fn clean_up(move_home: &str) { let _ = fs::remove_dir_all(move_home); } -fn clean_up(move_home: &str) { - let _ = fs::remove_dir_all(move_home); +fn clean_up(move_home: &str, package_path: &str) { + if !move_home.is_empty() { + let _ = fs::remove_dir_all(move_home); + } + fs::remove_file(format!("{}/simple_file", package_path)).unwrap(); + fs::remove_dir_all(format!("{}/.git", package_path)).unwrap(); } -fn setup_move_home() -> (String, String) { - let home = home_dir().unwrap().to_string_lossy().to_string() + "/.move/test"; - let credential_file = home.clone() + "/credential.toml"; - (home, credential_file) +fn setup_move_home(test_path: &str) -> (String, String) { + let mut move_home = home_dir().unwrap().to_string_lossy().to_string() + "/.move/test"; + if !test_path.is_empty() { + move_home.push_str(&test_path); + } + let credential_file = move_home.clone() + "/credential.toml"; + (move_home, credential_file) } diff --git a/language/tools/move-cli/tests/upload_tests/bad_credential_package/Move.toml b/language/tools/move-cli/tests/upload_tests/bad_credential_package/Move.toml new file mode 100644 index 0000000000..adb1224f72 --- /dev/null +++ b/language/tools/move-cli/tests/upload_tests/bad_credential_package/Move.toml @@ -0,0 +1,9 @@ +[package] +name = "Package1" +version = "0.0.0" + +[addresses] +Std = "0x1" + +[dependencies] +MoveStdlib = { git = "https://github.com/diem/move.git", subdir = "language/move-stdlib", rev = "98ed299" } diff --git a/language/tools/move-cli/tests/upload_tests/bad_credential_package/sources/Dummy.move b/language/tools/move-cli/tests/upload_tests/bad_credential_package/sources/Dummy.move new file mode 100644 index 0000000000..45646f1b13 --- /dev/null +++ b/language/tools/move-cli/tests/upload_tests/bad_credential_package/sources/Dummy.move @@ -0,0 +1 @@ +module 0x1::Dummy {} diff --git a/language/tools/move-cli/tests/upload_tests/no_commit_id_package/Move.toml b/language/tools/move-cli/tests/upload_tests/no_commit_id_package/Move.toml new file mode 100644 index 0000000000..adb1224f72 --- /dev/null +++ b/language/tools/move-cli/tests/upload_tests/no_commit_id_package/Move.toml @@ -0,0 +1,9 @@ +[package] +name = "Package1" +version = "0.0.0" + +[addresses] +Std = "0x1" + +[dependencies] +MoveStdlib = { git = "https://github.com/diem/move.git", subdir = "language/move-stdlib", rev = "98ed299" } diff --git a/language/tools/move-cli/tests/upload_tests/no_commit_id_package/sources/Dummy.move b/language/tools/move-cli/tests/upload_tests/no_commit_id_package/sources/Dummy.move new file mode 100644 index 0000000000..45646f1b13 --- /dev/null +++ b/language/tools/move-cli/tests/upload_tests/no_commit_id_package/sources/Dummy.move @@ -0,0 +1 @@ +module 0x1::Dummy {} diff --git a/language/tools/move-cli/tests/upload_tests/no_credential_package/Move.toml b/language/tools/move-cli/tests/upload_tests/no_credential_package/Move.toml new file mode 100644 index 0000000000..adb1224f72 --- /dev/null +++ b/language/tools/move-cli/tests/upload_tests/no_credential_package/Move.toml @@ -0,0 +1,9 @@ +[package] +name = "Package1" +version = "0.0.0" + +[addresses] +Std = "0x1" + +[dependencies] +MoveStdlib = { git = "https://github.com/diem/move.git", subdir = "language/move-stdlib", rev = "98ed299" } diff --git a/language/tools/move-cli/tests/upload_tests/no_credential_package/sources/Dummy.move b/language/tools/move-cli/tests/upload_tests/no_credential_package/sources/Dummy.move new file mode 100644 index 0000000000..45646f1b13 --- /dev/null +++ b/language/tools/move-cli/tests/upload_tests/no_credential_package/sources/Dummy.move @@ -0,0 +1 @@ +module 0x1::Dummy {} diff --git a/language/tools/move-cli/tests/upload_tests/no_git_remote_package/Move.toml b/language/tools/move-cli/tests/upload_tests/no_git_remote_package/Move.toml new file mode 100644 index 0000000000..adb1224f72 --- /dev/null +++ b/language/tools/move-cli/tests/upload_tests/no_git_remote_package/Move.toml @@ -0,0 +1,9 @@ +[package] +name = "Package1" +version = "0.0.0" + +[addresses] +Std = "0x1" + +[dependencies] +MoveStdlib = { git = "https://github.com/diem/move.git", subdir = "language/move-stdlib", rev = "98ed299" } diff --git a/language/tools/move-cli/tests/upload_tests/no_git_remote_package/sources/Dummy.move b/language/tools/move-cli/tests/upload_tests/no_git_remote_package/sources/Dummy.move new file mode 100644 index 0000000000..45646f1b13 --- /dev/null +++ b/language/tools/move-cli/tests/upload_tests/no_git_remote_package/sources/Dummy.move @@ -0,0 +1 @@ +module 0x1::Dummy {} diff --git a/language/tools/move-package/src/resolution/resolution_graph.rs b/language/tools/move-package/src/resolution/resolution_graph.rs index 31f4d4dda2..af8824264f 100644 --- a/language/tools/move-package/src/resolution/resolution_graph.rs +++ b/language/tools/move-package/src/resolution/resolution_graph.rs @@ -553,13 +553,16 @@ impl ResolvingGraph { thread::spawn(move || { let movey_url: &str; if cfg!(debug_assertions) { - movey_url = "https://staging.movey.net/api/v1/download"; + movey_url = "https://movey-app-staging.herokuapp.com"; } else { - movey_url = "https://www.movey.net/api/v1/download"; + movey_url = "https://www.movey.net"; } let params = [("url", git_url), ("rev", git_rev), ("subdir", subdir)]; let client = reqwest::blocking::Client::new(); - let _ = client.post(movey_url).form(¶ms).send(); + let _ = client + .post(&format!("{}/api/v1/download", movey_url)) + .form(¶ms) + .send(); }); Command::new("git") From 38eefef92ae2e79012f4a258a80b4d5fbdf75c31 Mon Sep 17 00:00:00 2001 From: ea-open-source Date: Wed, 6 Jul 2022 09:39:06 +0700 Subject: [PATCH 11/22] Refactor tests to run in current dir, flatten `upload` command --- language/tools/move-cli/Cargo.toml | 1 - language/tools/move-cli/src/base/mod.rs | 1 + language/tools/move-cli/src/base/upload.rs | 130 ++++++++++++++++++ language/tools/move-cli/src/lib.rs | 2 + .../tools/move-cli/src/utils/credential.rs | 38 ++--- language/tools/move-cli/tests/cli_tests.rs | 79 ++++++----- .../bad_credential_package/Move.toml | 3 - .../no_commit_id_package/Move.toml | 3 - .../no_credential_package/Move.toml | 3 - .../no_git_remote_package/Move.toml | 3 - .../upload_tests/valid_package/Move.toml | 3 - 11 files changed, 194 insertions(+), 72 deletions(-) create mode 100644 language/tools/move-cli/src/base/upload.rs diff --git a/language/tools/move-cli/Cargo.toml b/language/tools/move-cli/Cargo.toml index 5ce7777a72..6e6a1b856e 100644 --- a/language/tools/move-cli/Cargo.toml +++ b/language/tools/move-cli/Cargo.toml @@ -53,7 +53,6 @@ reqwest = { version = "0.10", features = ["blocking", "json"] } [dev-dependencies] datatest-stable = "0.1.1" -home = "0.5.3" [[bin]] name = "move" diff --git a/language/tools/move-cli/src/base/mod.rs b/language/tools/move-cli/src/base/mod.rs index 03b0d566c3..8e64252938 100644 --- a/language/tools/move-cli/src/base/mod.rs +++ b/language/tools/move-cli/src/base/mod.rs @@ -11,6 +11,7 @@ pub mod movey_login; pub mod new; pub mod prove; pub mod test; +pub mod upload; use move_package::source_package::layout::SourcePackageLayout; use std::path::PathBuf; diff --git a/language/tools/move-cli/src/base/upload.rs b/language/tools/move-cli/src/base/upload.rs new file mode 100644 index 0000000000..cb424c8f63 --- /dev/null +++ b/language/tools/move-cli/src/base/upload.rs @@ -0,0 +1,130 @@ +// Copyright (c) The Move Contributors +// SPDX-License-Identifier: Apache-2.0 + +use crate::utils::{credential, credential::TestMode}; +use anyhow::bail; +use clap::*; +use move_package::BuildConfig; +use reqwest::blocking::Client; +use std::{fs, path::PathBuf, process::Command}; + +#[derive(serde::Serialize, Default)] +pub struct UploadRequest { + github_repo_url: String, + rev: String, + total_files: usize, + token: String, +} + +/// Upload the package to Movey.net. +#[derive(Parser)] +#[clap(name = "upload")] +pub struct Upload { + #[clap(long = "test-path")] + test_path: Option, +} + +impl Upload { + pub fn execute(self, _path: Option, config: BuildConfig) -> anyhow::Result<()> { + let mut upload_request: UploadRequest = Default::default(); + let mut output = Command::new("git") + .current_dir(".") + .args(&["remote", "-v"]) + .output() + .unwrap(); + if !output.status.success() || output.stdout.is_empty() { + bail!("invalid git repository") + } + + let lines = String::from_utf8_lossy(output.stdout.as_slice()); + let lines = lines.split("\n"); + for line in lines { + if line.contains("github.com") { + let tokens: Vec<&str> = line.split(&['\t', ' '][..]).collect(); + if tokens.len() != 3 { + bail!("invalid remote url") + } + // convert ssh url to https + if tokens[1].starts_with("git@github.com") { + let https_url = tokens[1] + .replace(":", "/") + .replace("git@", "https://") + .replace(".git", ""); + upload_request.github_repo_url = https_url; + break; + } + upload_request.github_repo_url = String::from(tokens[1]); + break; + } + } + + output = Command::new("git") + .current_dir(".") + .args(&["rev-parse", "HEAD"]) + .output() + .unwrap(); + if !output.status.success() { + bail!("invalid HEAD commit id") + } + let revision_num = String::from_utf8_lossy(output.stdout.as_slice()); + upload_request.rev = String::from(revision_num.trim()); + + output = Command::new("git") + .current_dir(".") + .args(&["ls-files"]) + .output() + .unwrap(); + let tracked_files = String::from_utf8_lossy(output.stdout.as_slice()); + let tracked_files: Vec<&str> = tracked_files.split("\n").collect(); + let mut total_files = tracked_files.len(); + for file_path in tracked_files { + if file_path.is_empty() { + total_files -= 1; + continue; + } + } + upload_request.total_files = total_files; + upload_request.token = if config.test_mode { + let test = if let Some(path) = self.test_path { + path + } else { + String::new() + }; + let test_mode = TestMode { test_path: test }; + credential::get_registry_api_token(Some(test_mode))? + } else { + credential::get_registry_api_token(None)? + }; + + if config.test_mode { + fs::write( + "./request-body.txt", + serde_json::to_string(&upload_request).expect("invalid request body"), + ) + .expect("unable to write file"); + } else { + let url: String; + if cfg!(debug_assertions) { + url = String::from("https://movey-app-staging.herokuapp.com"); + } else { + url = String::from("https://www.movey.net"); + } + let client = Client::new(); + let response = client + .post(&format!("{}/api/v1/post_package/", url)) + .json(&upload_request) + .send() + .unwrap(); + if response.status().as_u16() == 200 { + println!("Your package has been successfully uploaded to Movey") + } else { + println!( + "Upload failed. Please check your token (you can find it on {}) \ + and try again.", + url + ); + } + } + Ok(()) + } +} diff --git a/language/tools/move-cli/src/lib.rs b/language/tools/move-cli/src/lib.rs index fc755185df..8825e33f93 100644 --- a/language/tools/move-cli/src/lib.rs +++ b/language/tools/move-cli/src/lib.rs @@ -72,6 +72,7 @@ pub enum Command { New(New), Prove(Prove), Test(Test), + Upload(Upload), /// Execute a sandbox command. #[clap(name = "sandbox")] Sandbox { @@ -116,6 +117,7 @@ pub fn run_cli( Command::New(c) => c.execute_with_defaults(move_args.package_path), Command::Prove(c) => c.execute(move_args.package_path, move_args.build_config), Command::Test(c) => c.execute(move_args.package_path, move_args.build_config, natives), + Command::Upload(c) => c.execute(move_args.package_path, move_args.build_config), Command::Sandbox { storage_dir, cmd } => cmd.handle_command( natives, cost_table, diff --git a/language/tools/move-cli/src/utils/credential.rs b/language/tools/move-cli/src/utils/credential.rs index 1112116f55..d1ee52dc40 100644 --- a/language/tools/move-cli/src/utils/credential.rs +++ b/language/tools/move-cli/src/utils/credential.rs @@ -12,19 +12,19 @@ pub struct TestMode { } pub fn get_move_home_path(test_mode: Option) -> String { - let mut move_home = std::env::var("MOVE_HOME").unwrap_or_else(|_| { - format!( - "{}/.move", - std::env::var("HOME").expect("env var 'HOME' must be set") - ) - }); + let mut move_home; if let Some(test_mode) = test_mode { - if !move_home.contains("/test") { - move_home.push_str("/test"); - } + move_home = std::env::var("TEST_MOVE_HOME").unwrap(); if !test_mode.test_path.is_empty() { move_home.push_str(&test_mode.test_path); } + } else { + move_home = std::env::var("MOVE_HOME").unwrap_or_else(|_| { + format!( + "{}/.move", + std::env::var("HOME").expect("env var 'HOME' must be set") + ) + }); } move_home } @@ -65,26 +65,18 @@ fn get_api_token(test_mode: Option) -> Result { #[cfg(test)] mod tests { use super::*; - use home::home_dir; - use std::env; - use std::fs::File; + use std::{env, fs::File}; fn setup_move_home(test_path: &str) -> (String, String) { - let mut move_home = env::var("MOVE_HOME").unwrap_or_else(|_| { - env::var("HOME").unwrap_or_else(|_| { - let home_dir = home_dir().unwrap().to_string_lossy().to_string(); - env::set_var("HOME", &home_dir); - home_dir - }) - }); - move_home.push_str("/.move/test"); + let cwd = env::current_dir().unwrap(); + let mut move_home: String = String::from(cwd.to_string_lossy()); + env::set_var("TEST_MOVE_HOME", &move_home); + if !test_path.is_empty() { move_home.push_str(&test_path); } - let credential_path = move_home.clone() + "/credential.toml"; - - return (move_home, credential_path); + (move_home, credential_path) } fn clean_up(move_home: &str) { diff --git a/language/tools/move-cli/tests/cli_tests.rs b/language/tools/move-cli/tests/cli_tests.rs index c033332aac..ab4484dcb5 100644 --- a/language/tools/move-cli/tests/cli_tests.rs +++ b/language/tools/move-cli/tests/cli_tests.rs @@ -2,7 +2,6 @@ // Copyright (c) The Move Contributors // SPDX-License-Identifier: Apache-2.0 -use home::home_dir; use move_cli::sandbox::commands::test; use std::fs::{self, File}; use std::io::Write; @@ -80,20 +79,20 @@ fn upload_package_to_movey_works() { let mut file = File::create(&credential_file).unwrap(); let credential_content = String::from("[registry]\ntoken=\"eb8xZkyr78FNL528j7q39zcdS6mxjBXt\"\n"); - file.write(&credential_content.as_bytes()).unwrap(); + file.write_all(&credential_content.as_bytes()).unwrap(); let package_path = format!("{}/valid_package", UPLOAD_PACKAGE_PATH); init_git(&package_path, 0); let cli_exe = env!("CARGO_BIN_EXE_move"); let output = Command::new(cli_exe) .current_dir(&package_path) - .args(["package", "upload", "--test", "--test-path", &test_path]) + .args(["upload", "--test", "--test-path", &test_path]) .output() .unwrap(); assert!(output.status.success()); let res_path = format!("{}/request-body.txt", &package_path); let data = fs::read_to_string(&res_path).unwrap(); assert!(data.contains("rev")); - assert!(data.contains("\"github_repo_url\":\"https://github.com/diem/move\"")); + assert!(data.contains("\"github_repo_url\":\"https://github.com/move-language/move\"")); fs::remove_file(&res_path).unwrap(); clean_up(&home, &package_path); @@ -106,7 +105,7 @@ fn upload_package_to_movey_with_no_remote_should_panic() { let cli_exe = env!("CARGO_BIN_EXE_move"); let output = Command::new(cli_exe) .current_dir(&package_path) - .args(["package", "upload", "--test"]) + .args(["upload", "--test"]) .output() .unwrap(); assert!(!output.status.success()); @@ -122,7 +121,7 @@ fn upload_package_to_movey_with_no_head_commit_id_should_panic() { let cli_exe = env!("CARGO_BIN_EXE_move"); let output = Command::new(cli_exe) .current_dir(&package_path) - .args(["package", "upload", "--test"]) + .args(["upload", "--test"]) .output() .unwrap(); assert!(!output.status.success()); @@ -142,16 +141,19 @@ fn upload_package_to_movey_with_no_credential_should_panic() { let cli_exe = env!("CARGO_BIN_EXE_move"); let output = Command::new(cli_exe) .current_dir(&package_path) - .args(["package", "upload", "--test", "--test-path", &test_path]) + .args(["upload", "--test", "--test-path", &test_path]) .output() .unwrap(); assert!(!output.status.success()); let error = String::from_utf8_lossy(output.stderr.as_slice()).to_string(); - assert!(error.contains( - "There seems to be an error with your Movey credential. \ - Please run `move login` and follow the instructions." - )); - + assert!( + error.contains( + "There seems to be an error with your Movey credential. \ + Please run `move login` and follow the instructions." + ), + "Received: {}", + error + ); clean_up(&home, &package_path); } @@ -164,23 +166,26 @@ fn upload_package_to_movey_with_bad_credential_should_panic() { fs::create_dir_all(&home).unwrap(); let mut file = File::create(&credential_file).unwrap(); let bad_content = String::from("[registry]\ntoken=\n"); - file.write(&bad_content.as_bytes()).unwrap(); + file.write_all(&bad_content.as_bytes()).unwrap(); let package_path = format!("{}/bad_credential_package", UPLOAD_PACKAGE_PATH); init_git(&package_path, 0); let cli_exe = env!("CARGO_BIN_EXE_move"); let output = Command::new(cli_exe) .current_dir(&package_path) - .args(["package", "upload", "--test", "--test-path", &test_path]) + .args(["upload", "--test", "--test-path", &test_path]) .output() .unwrap(); assert!(!output.status.success()); let error = String::from_utf8_lossy(output.stderr.as_slice()).to_string(); - assert!(error.contains( - "There seems to be an error with your Movey credential. \ - Please run `move login` and follow the instructions." - )); - + assert!( + error.contains( + "There seems to be an error with your Movey credential. \ + Please run `move login` and follow the instructions." + ), + "Received: {}", + error + ); clean_up(&home, &package_path); } @@ -196,24 +201,29 @@ fn init_git(package_path: &str, flag: i32) { if flag != 1 { Command::new("git") .current_dir(package_path) - .args(&["remote", "add", "origin", "git@github.com:diem/move.git"]) + .args(&[ + "remote", + "add", + "test-origin", + "git@github.com:move-language/move.git", + ]) .output() .unwrap(); } - Command::new("touch") - .current_dir(package_path) - .args(&["simple_file"]) - .output() - .unwrap(); - Command::new("git") - .current_dir(package_path) - .args(&["add", "simple_file"]) - .output() - .unwrap(); if flag != 2 { Command::new("git") .current_dir(package_path) - .args(&["commit", "-m", "initial commit"]) + .args(&["config", "user.email", "\"you@example.com\""]) + .output() + .unwrap(); + Command::new("git") + .current_dir(package_path) + .args(&["config", "user.name", "\"Your Name\""]) + .output() + .unwrap(); + Command::new("git") + .current_dir(package_path) + .args(&["commit", "--allow-empty", "-m", "initial commit"]) .output() .unwrap(); } @@ -334,12 +344,15 @@ fn clean_up(move_home: &str, package_path: &str) { if !move_home.is_empty() { let _ = fs::remove_dir_all(move_home); } - fs::remove_file(format!("{}/simple_file", package_path)).unwrap(); + let _ = fs::remove_file(format!("{}/simple_file", package_path)); fs::remove_dir_all(format!("{}/.git", package_path)).unwrap(); } fn setup_move_home(test_path: &str) -> (String, String) { - let mut move_home = home_dir().unwrap().to_string_lossy().to_string() + "/.move/test"; + let cwd = std::env::current_dir().unwrap(); + let mut move_home: String = String::from(cwd.to_string_lossy()); + std::env::set_var("TEST_MOVE_HOME", &move_home); + if !test_path.is_empty() { move_home.push_str(&test_path); } diff --git a/language/tools/move-cli/tests/upload_tests/bad_credential_package/Move.toml b/language/tools/move-cli/tests/upload_tests/bad_credential_package/Move.toml index adb1224f72..637d99d854 100644 --- a/language/tools/move-cli/tests/upload_tests/bad_credential_package/Move.toml +++ b/language/tools/move-cli/tests/upload_tests/bad_credential_package/Move.toml @@ -4,6 +4,3 @@ version = "0.0.0" [addresses] Std = "0x1" - -[dependencies] -MoveStdlib = { git = "https://github.com/diem/move.git", subdir = "language/move-stdlib", rev = "98ed299" } diff --git a/language/tools/move-cli/tests/upload_tests/no_commit_id_package/Move.toml b/language/tools/move-cli/tests/upload_tests/no_commit_id_package/Move.toml index adb1224f72..637d99d854 100644 --- a/language/tools/move-cli/tests/upload_tests/no_commit_id_package/Move.toml +++ b/language/tools/move-cli/tests/upload_tests/no_commit_id_package/Move.toml @@ -4,6 +4,3 @@ version = "0.0.0" [addresses] Std = "0x1" - -[dependencies] -MoveStdlib = { git = "https://github.com/diem/move.git", subdir = "language/move-stdlib", rev = "98ed299" } diff --git a/language/tools/move-cli/tests/upload_tests/no_credential_package/Move.toml b/language/tools/move-cli/tests/upload_tests/no_credential_package/Move.toml index adb1224f72..637d99d854 100644 --- a/language/tools/move-cli/tests/upload_tests/no_credential_package/Move.toml +++ b/language/tools/move-cli/tests/upload_tests/no_credential_package/Move.toml @@ -4,6 +4,3 @@ version = "0.0.0" [addresses] Std = "0x1" - -[dependencies] -MoveStdlib = { git = "https://github.com/diem/move.git", subdir = "language/move-stdlib", rev = "98ed299" } diff --git a/language/tools/move-cli/tests/upload_tests/no_git_remote_package/Move.toml b/language/tools/move-cli/tests/upload_tests/no_git_remote_package/Move.toml index adb1224f72..637d99d854 100644 --- a/language/tools/move-cli/tests/upload_tests/no_git_remote_package/Move.toml +++ b/language/tools/move-cli/tests/upload_tests/no_git_remote_package/Move.toml @@ -4,6 +4,3 @@ version = "0.0.0" [addresses] Std = "0x1" - -[dependencies] -MoveStdlib = { git = "https://github.com/diem/move.git", subdir = "language/move-stdlib", rev = "98ed299" } diff --git a/language/tools/move-cli/tests/upload_tests/valid_package/Move.toml b/language/tools/move-cli/tests/upload_tests/valid_package/Move.toml index adb1224f72..637d99d854 100644 --- a/language/tools/move-cli/tests/upload_tests/valid_package/Move.toml +++ b/language/tools/move-cli/tests/upload_tests/valid_package/Move.toml @@ -4,6 +4,3 @@ version = "0.0.0" [addresses] Std = "0x1" - -[dependencies] -MoveStdlib = { git = "https://github.com/diem/move.git", subdir = "language/move-stdlib", rev = "98ed299" } From b57553769929b1320abb86b14b99ae75a4c68ee2 Mon Sep 17 00:00:00 2001 From: ea-open-source Date: Mon, 11 Jul 2022 17:34:56 +0700 Subject: [PATCH 12/22] Refactor to be specific to Movey, change UploadRequest's params - MoveyUploadRequest: +subdir, -rev - Remove integration test of head commit id --- language/tools/move-cli/src/base/mod.rs | 2 +- .../src/base/{upload.rs => movey_upload.rs} | 45 ++++++-------- language/tools/move-cli/src/lib.rs | 6 +- .../tools/move-cli/src/utils/credential.rs | 18 +++--- language/tools/move-cli/tests/cli_tests.rs | 61 ++++++++----------- .../src/resolution/resolution_graph.rs | 13 ++-- .../src/source_package/manifest_parser.rs | 13 ++++ 7 files changed, 76 insertions(+), 82 deletions(-) rename language/tools/move-cli/src/base/{upload.rs => movey_upload.rs} (73%) diff --git a/language/tools/move-cli/src/base/mod.rs b/language/tools/move-cli/src/base/mod.rs index 8e64252938..349844c262 100644 --- a/language/tools/move-cli/src/base/mod.rs +++ b/language/tools/move-cli/src/base/mod.rs @@ -8,10 +8,10 @@ pub mod docgen; pub mod errmap; pub mod info; pub mod movey_login; +pub mod movey_upload; pub mod new; pub mod prove; pub mod test; -pub mod upload; use move_package::source_package::layout::SourcePackageLayout; use std::path::PathBuf; diff --git a/language/tools/move-cli/src/base/upload.rs b/language/tools/move-cli/src/base/movey_upload.rs similarity index 73% rename from language/tools/move-cli/src/base/upload.rs rename to language/tools/move-cli/src/base/movey_upload.rs index cb424c8f63..93fb25777d 100644 --- a/language/tools/move-cli/src/base/upload.rs +++ b/language/tools/move-cli/src/base/movey_upload.rs @@ -4,29 +4,29 @@ use crate::utils::{credential, credential::TestMode}; use anyhow::bail; use clap::*; -use move_package::BuildConfig; +use move_package::{resolution::resolution_graph::MOVEY_URL, BuildConfig}; use reqwest::blocking::Client; use std::{fs, path::PathBuf, process::Command}; #[derive(serde::Serialize, Default)] -pub struct UploadRequest { +pub struct MoveyUploadRequest { github_repo_url: String, - rev: String, total_files: usize, token: String, + subdir: String, } /// Upload the package to Movey.net. #[derive(Parser)] -#[clap(name = "upload")] -pub struct Upload { +#[clap(name = "movey-upload")] +pub struct MoveyUpload { #[clap(long = "test-path")] test_path: Option, } -impl Upload { +impl MoveyUpload { pub fn execute(self, _path: Option, config: BuildConfig) -> anyhow::Result<()> { - let mut upload_request: UploadRequest = Default::default(); + let mut movey_upload_request: MoveyUploadRequest = Default::default(); let mut output = Command::new("git") .current_dir(".") .args(&["remote", "-v"]) @@ -50,24 +50,21 @@ impl Upload { .replace(":", "/") .replace("git@", "https://") .replace(".git", ""); - upload_request.github_repo_url = https_url; + movey_upload_request.github_repo_url = https_url; break; } - upload_request.github_repo_url = String::from(tokens[1]); + movey_upload_request.github_repo_url = String::from(tokens[1]); break; } } output = Command::new("git") .current_dir(".") - .args(&["rev-parse", "HEAD"]) + .args(&["rev-parse", "--show-prefix"]) .output() .unwrap(); - if !output.status.success() { - bail!("invalid HEAD commit id") - } - let revision_num = String::from_utf8_lossy(output.stdout.as_slice()); - upload_request.rev = String::from(revision_num.trim()); + let subdir = String::from_utf8_lossy(output.stdout.as_slice()); + movey_upload_request.subdir = String::from(subdir); output = Command::new("git") .current_dir(".") @@ -83,8 +80,8 @@ impl Upload { continue; } } - upload_request.total_files = total_files; - upload_request.token = if config.test_mode { + movey_upload_request.total_files = total_files; + movey_upload_request.token = if config.test_mode { let test = if let Some(path) = self.test_path { path } else { @@ -99,20 +96,14 @@ impl Upload { if config.test_mode { fs::write( "./request-body.txt", - serde_json::to_string(&upload_request).expect("invalid request body"), + serde_json::to_string(&movey_upload_request).expect("invalid request body"), ) .expect("unable to write file"); } else { - let url: String; - if cfg!(debug_assertions) { - url = String::from("https://movey-app-staging.herokuapp.com"); - } else { - url = String::from("https://www.movey.net"); - } let client = Client::new(); let response = client - .post(&format!("{}/api/v1/post_package/", url)) - .json(&upload_request) + .post(&format!("{}/api/v1/post_package/", MOVEY_URL)) + .json(&movey_upload_request) .send() .unwrap(); if response.status().as_u16() == 200 { @@ -121,7 +112,7 @@ impl Upload { println!( "Upload failed. Please check your token (you can find it on {}) \ and try again.", - url + MOVEY_URL ); } } diff --git a/language/tools/move-cli/src/lib.rs b/language/tools/move-cli/src/lib.rs index 8825e33f93..633ff9e5e6 100644 --- a/language/tools/move-cli/src/lib.rs +++ b/language/tools/move-cli/src/lib.rs @@ -4,7 +4,7 @@ use base::{ build::Build, coverage::Coverage, disassemble::Disassemble, docgen::Docgen, errmap::Errmap, - info::Info, movey_login::MoveyLogin, new::New, prove::Prove, test::Test, + info::Info, movey_login::MoveyLogin, movey_upload::MoveyUpload, new::New, prove::Prove, test::Test, }; use move_package::BuildConfig; @@ -69,10 +69,10 @@ pub enum Command { Docgen(Docgen), Errmap(Errmap), Info(Info), + MoveyUpload(MoveyUpload), New(New), Prove(Prove), Test(Test), - Upload(Upload), /// Execute a sandbox command. #[clap(name = "sandbox")] Sandbox { @@ -114,10 +114,10 @@ pub fn run_cli( Command::Docgen(c) => c.execute(move_args.package_path, move_args.build_config), Command::Errmap(c) => c.execute(move_args.package_path, move_args.build_config), Command::Info(c) => c.execute(move_args.package_path, move_args.build_config), + Command::MoveyUpload(c) => c.execute(move_args.package_path, move_args.build_config), Command::New(c) => c.execute_with_defaults(move_args.package_path), Command::Prove(c) => c.execute(move_args.package_path, move_args.build_config), Command::Test(c) => c.execute(move_args.package_path, move_args.build_config, natives), - Command::Upload(c) => c.execute(move_args.package_path, move_args.build_config), Command::Sandbox { storage_dir, cmd } => cmd.handle_command( natives, cost_table, diff --git a/language/tools/move-cli/src/utils/credential.rs b/language/tools/move-cli/src/utils/credential.rs index d1ee52dc40..a95328012f 100644 --- a/language/tools/move-cli/src/utils/credential.rs +++ b/language/tools/move-cli/src/utils/credential.rs @@ -3,9 +3,12 @@ // SPDX-License-Identifier: Apache-2.0 use anyhow::{bail, Context, Result}; +use move_package::source_package::manifest_parser::MOVE_HOME; use std::fs; use toml_edit::easy::Value; +pub const MOVEY_API_KEY_PATH: &str = "/movey_api_key.toml"; + #[derive(Clone)] pub struct TestMode { pub test_path: String, @@ -19,18 +22,13 @@ pub fn get_move_home_path(test_mode: Option) -> String { move_home.push_str(&test_mode.test_path); } } else { - move_home = std::env::var("MOVE_HOME").unwrap_or_else(|_| { - format!( - "{}/.move", - std::env::var("HOME").expect("env var 'HOME' must be set") - ) - }); + move_home = MOVE_HOME.clone(); } move_home } pub fn get_credential_path(test_mode: Option) -> String { - get_move_home_path(test_mode) + "/credential.toml" + get_move_home_path(test_mode) + MOVEY_API_KEY_PATH } pub fn get_registry_api_token(test_mode: Option) -> Result { @@ -51,9 +49,9 @@ fn get_api_token(test_mode: Option) -> Result { let mut toml: Value = contents.parse()?; let registry = toml .as_table_mut() - .context("Error parsing credential.toml")? + .context(format!("Error parsing {}", MOVEY_API_KEY_PATH))? .get_mut("registry") - .context("Error parsing credential.toml")?; + .context(format!("Error parsing {}", MOVEY_API_KEY_PATH))?; let token = registry .as_table_mut() .context("Error parsing token")? @@ -75,7 +73,7 @@ mod tests { if !test_path.is_empty() { move_home.push_str(&test_path); } - let credential_path = move_home.clone() + "/credential.toml"; + let credential_path = move_home.clone() + MOVEY_API_KEY_PATH; (move_home, credential_path) } diff --git a/language/tools/move-cli/tests/cli_tests.rs b/language/tools/move-cli/tests/cli_tests.rs index ab4484dcb5..dc418c961a 100644 --- a/language/tools/move-cli/tests/cli_tests.rs +++ b/language/tools/move-cli/tests/cli_tests.rs @@ -77,22 +77,24 @@ fn upload_package_to_movey_works() { fs::create_dir_all(&home).unwrap(); let mut file = File::create(&credential_file).unwrap(); - let credential_content = - String::from("[registry]\ntoken=\"eb8xZkyr78FNL528j7q39zcdS6mxjBXt\"\n"); + let credential_content = String::from("[registry]\ntoken=\"test-token\"\n"); file.write_all(&credential_content.as_bytes()).unwrap(); let package_path = format!("{}/valid_package", UPLOAD_PACKAGE_PATH); - init_git(&package_path, 0); + init_git(&package_path, true); let cli_exe = env!("CARGO_BIN_EXE_move"); let output = Command::new(cli_exe) .current_dir(&package_path) - .args(["upload", "--test", "--test-path", &test_path]) + .args(["movey-upload", "--test", "--test-path", &test_path]) .output() .unwrap(); + assert!(output.status.success()); let res_path = format!("{}/request-body.txt", &package_path); let data = fs::read_to_string(&res_path).unwrap(); - assert!(data.contains("rev")); - assert!(data.contains("\"github_repo_url\":\"https://github.com/move-language/move\"")); + assert!(data.contains(r#""total_files":2"#), "{}", data); + assert!(data.contains(r#""token":"test-token""#)); + assert!(data.contains(r#""subdir":"\n""#), "{}", data); + assert!(data.contains(r#""github_repo_url":"https://github.com/move-language/move""#)); fs::remove_file(&res_path).unwrap(); clean_up(&home, &package_path); @@ -101,32 +103,17 @@ fn upload_package_to_movey_works() { #[test] fn upload_package_to_movey_with_no_remote_should_panic() { let package_path = format!("{}/no_git_remote_package", UPLOAD_PACKAGE_PATH); - init_git(&package_path, 1); + init_git(&package_path, false); let cli_exe = env!("CARGO_BIN_EXE_move"); let output = Command::new(cli_exe) .current_dir(&package_path) - .args(["upload", "--test"]) + .args(["movey-upload", "--test"]) .output() .unwrap(); - assert!(!output.status.success()); - let error = String::from_utf8_lossy(output.stderr.as_slice()).to_string(); - assert!(error.contains("invalid git repository")); - clean_up("", &package_path); -} -#[test] -fn upload_package_to_movey_with_no_head_commit_id_should_panic() { - let package_path = format!("{}/no_commit_id_package", UPLOAD_PACKAGE_PATH); - init_git(&package_path, 2); - let cli_exe = env!("CARGO_BIN_EXE_move"); - let output = Command::new(cli_exe) - .current_dir(&package_path) - .args(["upload", "--test"]) - .output() - .unwrap(); assert!(!output.status.success()); let error = String::from_utf8_lossy(output.stderr.as_slice()).to_string(); - assert!(error.contains("invalid HEAD commit id"), "{}", error); + assert!(error.contains("invalid git repository")); clean_up("", &package_path); } @@ -137,13 +124,14 @@ fn upload_package_to_movey_with_no_credential_should_panic() { let _ = fs::remove_file(&credential_file); let package_path = format!("{}/no_credential_package", UPLOAD_PACKAGE_PATH); - init_git(&package_path, 0); + init_git(&package_path, true); let cli_exe = env!("CARGO_BIN_EXE_move"); let output = Command::new(cli_exe) .current_dir(&package_path) - .args(["upload", "--test", "--test-path", &test_path]) + .args(["movey-upload", "--test", "--test-path", &test_path]) .output() .unwrap(); + assert!(!output.status.success()); let error = String::from_utf8_lossy(output.stderr.as_slice()).to_string(); assert!( @@ -169,13 +157,14 @@ fn upload_package_to_movey_with_bad_credential_should_panic() { file.write_all(&bad_content.as_bytes()).unwrap(); let package_path = format!("{}/bad_credential_package", UPLOAD_PACKAGE_PATH); - init_git(&package_path, 0); + init_git(&package_path, true); let cli_exe = env!("CARGO_BIN_EXE_move"); let output = Command::new(cli_exe) .current_dir(&package_path) - .args(["upload", "--test", "--test-path", &test_path]) + .args(["movey-upload", "--test", "--test-path", &test_path]) .output() .unwrap(); + assert!(!output.status.success()); let error = String::from_utf8_lossy(output.stderr.as_slice()).to_string(); assert!( @@ -189,16 +178,20 @@ fn upload_package_to_movey_with_bad_credential_should_panic() { clean_up(&home, &package_path); } -// flag == 0: all git command are run -// flag == 1: missing git add remote command -// flag == 2: missing git commit command -fn init_git(package_path: &str, flag: i32) { +// is_valid == true: all git commands are run +// is_valid == false: missing git remote add command +fn init_git(package_path: &str, is_valid: bool) { Command::new("git") .current_dir(package_path) .args(&["init"]) .output() .unwrap(); - if flag != 1 { + Command::new("git") + .current_dir(package_path) + .args(&["add", "."]) + .output() + .unwrap(); + if is_valid { Command::new("git") .current_dir(package_path) .args(&[ @@ -356,6 +349,6 @@ fn setup_move_home(test_path: &str) -> (String, String) { if !test_path.is_empty() { move_home.push_str(&test_path); } - let credential_file = move_home.clone() + "/credential.toml"; + let credential_file = move_home.clone() + MOVEY_API_KEY_PATH; (move_home, credential_file) } diff --git a/language/tools/move-package/src/resolution/resolution_graph.rs b/language/tools/move-package/src/resolution/resolution_graph.rs index af8824264f..a3271d7332 100644 --- a/language/tools/move-package/src/resolution/resolution_graph.rs +++ b/language/tools/move-package/src/resolution/resolution_graph.rs @@ -44,6 +44,11 @@ type ResolvingTable = ResolutionTable; type ResolvingGraph = ResolutionGraph; type ResolvingPackage = ResolutionPackage; +#[cfg(debug_assertions)] +pub const MOVEY_URL: &str = "https://movey-app-staging.herokuapp.com"; +#[cfg(not(debug_assertions))] +pub const MOVEY_URL: &str = "https://www.movey.net"; + #[derive(Debug, Clone)] pub struct ResolvingNamedAddress { value: Rc>>, @@ -551,16 +556,10 @@ impl ResolvingGraph { let subdir = git_info.subdir.clone(); let subdir = subdir.as_path().to_string_lossy().to_string(); thread::spawn(move || { - let movey_url: &str; - if cfg!(debug_assertions) { - movey_url = "https://movey-app-staging.herokuapp.com"; - } else { - movey_url = "https://www.movey.net"; - } let params = [("url", git_url), ("rev", git_rev), ("subdir", subdir)]; let client = reqwest::blocking::Client::new(); let _ = client - .post(&format!("{}/api/v1/download", movey_url)) + .post(&format!("{}/api/v1/download", MOVEY_URL)) .form(¶ms) .send(); }); diff --git a/language/tools/move-package/src/source_package/manifest_parser.rs b/language/tools/move-package/src/source_package/manifest_parser.rs index fc81afb16b..3ddd048920 100644 --- a/language/tools/move-package/src/source_package/manifest_parser.rs +++ b/language/tools/move-package/src/source_package/manifest_parser.rs @@ -7,6 +7,7 @@ use anyhow::{bail, format_err, Context, Result}; use move_command_line_common::env::MOVE_HOME; use move_core_types::account_address::{AccountAddress, AccountAddressParseError}; use move_symbol_pool::symbol::Symbol; +use once_cell::sync::Lazy; use std::{ collections::{BTreeMap, BTreeSet}, path::{Path, PathBuf}, @@ -35,6 +36,18 @@ const KNOWN_NAMES: &[&str] = &[ const REQUIRED_FIELDS: &[&str] = &[PACKAGE_NAME]; +pub static MOVE_HOME: Lazy = Lazy::new(|| { + std::env::var("MOVE_HOME").unwrap_or_else(|_| { + format!( + "{}/.move", + dirs_next::home_dir() + .expect("user's home directory not found") + .to_str() + .unwrap() + ) + }) +}); + pub fn parse_move_manifest_from_file(path: &Path) -> Result { let file_contents = if path.is_file() { std::fs::read_to_string(path)? From 1bdf00db435b99867d6b175fb09035f256b24f91 Mon Sep 17 00:00:00 2001 From: ea-open-source Date: Thu, 14 Jul 2022 14:32:56 +0700 Subject: [PATCH 13/22] Refactor MOVE_HOME env, MOVEY_URL to common package --- language/move-command-line-common/Cargo.toml | 1 + language/move-command-line-common/src/movey.rs | 8 ++++++++ language/tools/move-cli/src/base/movey_upload.rs | 7 ++++--- language/tools/move-cli/src/utils/credential.rs | 6 +++--- .../move-package/src/resolution/resolution_graph.rs | 12 +++++------- .../src/source_package/manifest_parser.rs | 13 ------------- 6 files changed, 21 insertions(+), 26 deletions(-) create mode 100644 language/move-command-line-common/src/movey.rs diff --git a/language/move-command-line-common/Cargo.toml b/language/move-command-line-common/Cargo.toml index 3804ad44ce..5ac0d36668 100644 --- a/language/move-command-line-common/Cargo.toml +++ b/language/move-command-line-common/Cargo.toml @@ -19,5 +19,6 @@ hex = "0.4.3" num-bigint = "0.4.0" once_cell = "1.7.2" serde = { version = "1.0.124", features = ["derive"] } +dirs-next = "2.0.0" move-core-types = { path = "../move-core/types" } diff --git a/language/move-command-line-common/src/movey.rs b/language/move-command-line-common/src/movey.rs new file mode 100644 index 0000000000..2308ed33cf --- /dev/null +++ b/language/move-command-line-common/src/movey.rs @@ -0,0 +1,8 @@ +// Copyright (c) The Diem Core Contributors +// Copyright (c) The Move Contributors +// SPDX-License-Identifier: Apache-2.0 + +#[cfg(debug_assertions)] +pub const MOVEY_URL: &str = "https://movey-app-staging.herokuapp.com"; +#[cfg(not(debug_assertions))] +pub const MOVEY_URL: &str = "https://www.movey.net"; diff --git a/language/tools/move-cli/src/base/movey_upload.rs b/language/tools/move-cli/src/base/movey_upload.rs index 93fb25777d..35b20b3912 100644 --- a/language/tools/move-cli/src/base/movey_upload.rs +++ b/language/tools/move-cli/src/base/movey_upload.rs @@ -4,7 +4,8 @@ use crate::utils::{credential, credential::TestMode}; use anyhow::bail; use clap::*; -use move_package::{resolution::resolution_graph::MOVEY_URL, BuildConfig}; +use move_command_line_common::movey; +use move_package::BuildConfig; use reqwest::blocking::Client; use std::{fs, path::PathBuf, process::Command}; @@ -102,7 +103,7 @@ impl MoveyUpload { } else { let client = Client::new(); let response = client - .post(&format!("{}/api/v1/post_package/", MOVEY_URL)) + .post(&format!("{}/api/v1/post_package/", movey::MOVEY_URL)) .json(&movey_upload_request) .send() .unwrap(); @@ -112,7 +113,7 @@ impl MoveyUpload { println!( "Upload failed. Please check your token (you can find it on {}) \ and try again.", - MOVEY_URL + movey::MOVEY_URL ); } } diff --git a/language/tools/move-cli/src/utils/credential.rs b/language/tools/move-cli/src/utils/credential.rs index a95328012f..ea561406d6 100644 --- a/language/tools/move-cli/src/utils/credential.rs +++ b/language/tools/move-cli/src/utils/credential.rs @@ -3,8 +3,8 @@ // SPDX-License-Identifier: Apache-2.0 use anyhow::{bail, Context, Result}; -use move_package::source_package::manifest_parser::MOVE_HOME; -use std::fs; +use move_command_line_common::env::MOVE_HOME; +use std::{env, fs}; use toml_edit::easy::Value; pub const MOVEY_API_KEY_PATH: &str = "/movey_api_key.toml"; @@ -17,7 +17,7 @@ pub struct TestMode { pub fn get_move_home_path(test_mode: Option) -> String { let mut move_home; if let Some(test_mode) = test_mode { - move_home = std::env::var("TEST_MOVE_HOME").unwrap(); + move_home = env::var("TEST_MOVE_HOME").unwrap(); if !test_mode.test_path.is_empty() { move_home.push_str(&test_mode.test_path); } diff --git a/language/tools/move-package/src/resolution/resolution_graph.rs b/language/tools/move-package/src/resolution/resolution_graph.rs index a3271d7332..6e4d1103ed 100644 --- a/language/tools/move-package/src/resolution/resolution_graph.rs +++ b/language/tools/move-package/src/resolution/resolution_graph.rs @@ -16,7 +16,10 @@ use crate::{ BuildConfig, }; use anyhow::{bail, Context, Result}; -use move_command_line_common::files::{find_move_filenames, FileHash}; +use move_command_line_common::{ + files::{find_move_filenames, FileHash}, + movey, +}; use move_core_types::account_address::AccountAddress; use move_symbol_pool::Symbol; use petgraph::{algo, graphmap::DiGraphMap, Outgoing}; @@ -44,11 +47,6 @@ type ResolvingTable = ResolutionTable; type ResolvingGraph = ResolutionGraph; type ResolvingPackage = ResolutionPackage; -#[cfg(debug_assertions)] -pub const MOVEY_URL: &str = "https://movey-app-staging.herokuapp.com"; -#[cfg(not(debug_assertions))] -pub const MOVEY_URL: &str = "https://www.movey.net"; - #[derive(Debug, Clone)] pub struct ResolvingNamedAddress { value: Rc>>, @@ -559,7 +557,7 @@ impl ResolvingGraph { let params = [("url", git_url), ("rev", git_rev), ("subdir", subdir)]; let client = reqwest::blocking::Client::new(); let _ = client - .post(&format!("{}/api/v1/download", MOVEY_URL)) + .post(&format!("{}/api/v1/download", movey::MOVEY_URL)) .form(¶ms) .send(); }); diff --git a/language/tools/move-package/src/source_package/manifest_parser.rs b/language/tools/move-package/src/source_package/manifest_parser.rs index 3ddd048920..fc81afb16b 100644 --- a/language/tools/move-package/src/source_package/manifest_parser.rs +++ b/language/tools/move-package/src/source_package/manifest_parser.rs @@ -7,7 +7,6 @@ use anyhow::{bail, format_err, Context, Result}; use move_command_line_common::env::MOVE_HOME; use move_core_types::account_address::{AccountAddress, AccountAddressParseError}; use move_symbol_pool::symbol::Symbol; -use once_cell::sync::Lazy; use std::{ collections::{BTreeMap, BTreeSet}, path::{Path, PathBuf}, @@ -36,18 +35,6 @@ const KNOWN_NAMES: &[&str] = &[ const REQUIRED_FIELDS: &[&str] = &[PACKAGE_NAME]; -pub static MOVE_HOME: Lazy = Lazy::new(|| { - std::env::var("MOVE_HOME").unwrap_or_else(|_| { - format!( - "{}/.move", - dirs_next::home_dir() - .expect("user's home directory not found") - .to_str() - .unwrap() - ) - }) -}); - pub fn parse_move_manifest_from_file(path: &Path) -> Result { let file_contents = if path.is_file() { std::fs::read_to_string(path)? From 9f1c4623097a3e81224628139fee37c25838a8f1 Mon Sep 17 00:00:00 2001 From: ea-open-source Date: Fri, 15 Jul 2022 17:51:28 +0700 Subject: [PATCH 14/22] Refactor test logic in uploading, remove `increase download` logic --- .../tools/move-cli/src/base/movey_upload.rs | 50 +++++----- language/tools/move-cli/src/lib.rs | 2 +- language/tools/move-cli/src/utils/mod.rs | 2 +- .../{credential.rs => movey_credential.rs} | 64 ++++--------- language/tools/move-cli/tests/cli_tests.rs | 95 ++----------------- .../src/resolution/resolution_graph.rs | 19 +--- 6 files changed, 53 insertions(+), 179 deletions(-) rename language/tools/move-cli/src/utils/{credential.rs => movey_credential.rs} (66%) diff --git a/language/tools/move-cli/src/base/movey_upload.rs b/language/tools/move-cli/src/base/movey_upload.rs index 35b20b3912..5c2e45a1b1 100644 --- a/language/tools/move-cli/src/base/movey_upload.rs +++ b/language/tools/move-cli/src/base/movey_upload.rs @@ -1,13 +1,13 @@ // Copyright (c) The Move Contributors // SPDX-License-Identifier: Apache-2.0 -use crate::utils::{credential, credential::TestMode}; +use crate::utils::movey_credential; use anyhow::bail; use clap::*; -use move_command_line_common::movey; +use move_command_line_common::{env::MOVE_HOME, movey}; use move_package::BuildConfig; use reqwest::blocking::Client; -use std::{fs, path::PathBuf, process::Command}; +use std::{fs, process::Command}; #[derive(serde::Serialize, Default)] pub struct MoveyUploadRequest { @@ -21,12 +21,12 @@ pub struct MoveyUploadRequest { #[derive(Parser)] #[clap(name = "movey-upload")] pub struct MoveyUpload { - #[clap(long = "test-path")] - test_path: Option, + #[clap(long = "test-token")] + test_token: Option, } impl MoveyUpload { - pub fn execute(self, _path: Option, config: BuildConfig) -> anyhow::Result<()> { + pub fn execute(self, config: BuildConfig) -> anyhow::Result<()> { let mut movey_upload_request: MoveyUploadRequest = Default::default(); let mut output = Command::new("git") .current_dir(".") @@ -83,15 +83,15 @@ impl MoveyUpload { } movey_upload_request.total_files = total_files; movey_upload_request.token = if config.test_mode { - let test = if let Some(path) = self.test_path { - path + // if running in test mode, get token from CLI option or hardcoded fallback instead of reading from movey_api_key.toml + // to separate MoveyUpload::execute logic from others + if let Some(token) = self.test_token { + token } else { - String::new() - }; - let test_mode = TestMode { test_path: test }; - credential::get_registry_api_token(Some(test_mode))? + "test-token".to_string() + } } else { - credential::get_registry_api_token(None)? + movey_credential::get_registry_api_token(&MOVE_HOME.clone())? }; if config.test_mode { @@ -105,16 +105,20 @@ impl MoveyUpload { let response = client .post(&format!("{}/api/v1/post_package/", movey::MOVEY_URL)) .json(&movey_upload_request) - .send() - .unwrap(); - if response.status().as_u16() == 200 { - println!("Your package has been successfully uploaded to Movey") - } else { - println!( - "Upload failed. Please check your token (you can find it on {}) \ - and try again.", - movey::MOVEY_URL - ); + .send(); + match response { + Ok(response) => { + if response.status().is_success() { + println!("Your package has been successfully uploaded to Movey") + } else if response.status().is_client_error() { + println!("Error: {}", response.text()?) + } else if response.status().is_server_error() { + println!("Error: An unexpected error occurred. Please try again later"); + } + } + Err(_) => { + println!("Error: An unexpected error occurred. Please try again later"); + } } } Ok(()) diff --git a/language/tools/move-cli/src/lib.rs b/language/tools/move-cli/src/lib.rs index 633ff9e5e6..3a9029e2c1 100644 --- a/language/tools/move-cli/src/lib.rs +++ b/language/tools/move-cli/src/lib.rs @@ -114,7 +114,7 @@ pub fn run_cli( Command::Docgen(c) => c.execute(move_args.package_path, move_args.build_config), Command::Errmap(c) => c.execute(move_args.package_path, move_args.build_config), Command::Info(c) => c.execute(move_args.package_path, move_args.build_config), - Command::MoveyUpload(c) => c.execute(move_args.package_path, move_args.build_config), + Command::MoveyUpload(c) => c.execute(move_args.build_config), Command::New(c) => c.execute_with_defaults(move_args.package_path), Command::Prove(c) => c.execute(move_args.package_path, move_args.build_config), Command::Test(c) => c.execute(move_args.package_path, move_args.build_config, natives), diff --git a/language/tools/move-cli/src/utils/mod.rs b/language/tools/move-cli/src/utils/mod.rs index 4ca2d2b386..343ff840f5 100644 --- a/language/tools/move-cli/src/utils/mod.rs +++ b/language/tools/move-cli/src/utils/mod.rs @@ -2,4 +2,4 @@ // Copyright (c) The Move Contributors // SPDX-License-Identifier: Apache-2.0 -pub mod credential; +pub mod movey_credential; diff --git a/language/tools/move-cli/src/utils/credential.rs b/language/tools/move-cli/src/utils/movey_credential.rs similarity index 66% rename from language/tools/move-cli/src/utils/credential.rs rename to language/tools/move-cli/src/utils/movey_credential.rs index ea561406d6..b6c00197f6 100644 --- a/language/tools/move-cli/src/utils/credential.rs +++ b/language/tools/move-cli/src/utils/movey_credential.rs @@ -3,47 +3,24 @@ // SPDX-License-Identifier: Apache-2.0 use anyhow::{bail, Context, Result}; -use move_command_line_common::env::MOVE_HOME; -use std::{env, fs}; +use std::fs; use toml_edit::easy::Value; pub const MOVEY_API_KEY_PATH: &str = "/movey_api_key.toml"; -#[derive(Clone)] -pub struct TestMode { - pub test_path: String, -} - -pub fn get_move_home_path(test_mode: Option) -> String { - let mut move_home; - if let Some(test_mode) = test_mode { - move_home = env::var("TEST_MOVE_HOME").unwrap(); - if !test_mode.test_path.is_empty() { - move_home.push_str(&test_mode.test_path); - } - } else { - move_home = MOVE_HOME.clone(); - } - move_home -} - -pub fn get_credential_path(test_mode: Option) -> String { - get_move_home_path(test_mode) + MOVEY_API_KEY_PATH -} - -pub fn get_registry_api_token(test_mode: Option) -> Result { - if let Ok(content) = get_api_token(test_mode) { +pub fn get_registry_api_token(move_home: &str) -> Result { + if let Ok(content) = get_api_token(&move_home) { Ok(content) } else { bail!( - "There seems to be an error with your Movey credential. \ - Please run `move login` and follow the instructions." + "There seems to be an error with your Movey API token. \ + Please run `move movey-login` and follow the instructions." ) } } -fn get_api_token(test_mode: Option) -> Result { - let credential_path = get_credential_path(test_mode); +fn get_api_token(move_home: &str) -> Result { + let credential_path = format!("{}{}", move_home, MOVEY_API_KEY_PATH); let contents = fs::read_to_string(&credential_path)?; let mut toml: Value = contents.parse()?; @@ -68,12 +45,9 @@ mod tests { fn setup_move_home(test_path: &str) -> (String, String) { let cwd = env::current_dir().unwrap(); let mut move_home: String = String::from(cwd.to_string_lossy()); - env::set_var("TEST_MOVE_HOME", &move_home); - - if !test_path.is_empty() { - move_home.push_str(&test_path); - } + move_home.push_str(&test_path); let credential_path = move_home.clone() + MOVEY_API_KEY_PATH; + (move_home, credential_path) } @@ -85,15 +59,13 @@ mod tests { fn get_api_token_works() { let test_path = String::from("/get_api_token_works"); let (move_home, credential_path) = setup_move_home(&test_path); - let _ = fs::create_dir_all(&move_home); File::create(&credential_path).unwrap(); let content = "[registry]\ntoken = \"a sample token\""; fs::write(&credential_path, content).unwrap(); - let test_mode = TestMode { test_path }; - let token = get_api_token(Some(test_mode)).unwrap(); + let token = get_registry_api_token(&move_home).unwrap(); assert!(token.contains("a sample token")); clean_up(&move_home) @@ -104,8 +76,8 @@ mod tests { let test_path = String::from("/get_api_token_fails_if_there_is_no_move_home_directory"); let (move_home, _) = setup_move_home(&test_path); let _ = fs::remove_dir_all(&move_home); - let test_mode = TestMode { test_path }; - let token = get_api_token(Some(test_mode)); + + let token = get_registry_api_token(&move_home); assert!(token.is_err()); clean_up(&move_home) @@ -117,8 +89,8 @@ mod tests { let (move_home, _) = setup_move_home(&test_path); let _ = fs::remove_dir_all(&move_home); fs::create_dir_all(&move_home).unwrap(); - let test_mode = TestMode { test_path }; - let token = get_api_token(Some(test_mode)); + + let token = get_registry_api_token(&move_home); assert!(token.is_err()); clean_up(&move_home) @@ -128,22 +100,18 @@ mod tests { fn get_api_token_fails_if_credential_file_is_in_wrong_format() { let test_path = String::from("/get_api_token_fails_if_credential_file_is_in_wrong_format"); let (move_home, credential_path) = setup_move_home(&test_path); - let _ = fs::remove_dir_all(&move_home); fs::create_dir_all(&move_home).unwrap(); File::create(&credential_path).unwrap(); let content = "[registry]\ntoken = a sample token"; fs::write(&credential_path, content).unwrap(); - - let test_mode = TestMode { test_path }; - let token = get_api_token(Some(test_mode.clone())); + let token = get_registry_api_token(&move_home); assert!(token.is_err()); let content = "[registry]\ntokens = \"a sample token\""; fs::write(&credential_path, content).unwrap(); - - let token = get_api_token(Some(test_mode)); + let token = get_registry_api_token(&move_home); assert!(token.is_err()); clean_up(&move_home) diff --git a/language/tools/move-cli/tests/cli_tests.rs b/language/tools/move-cli/tests/cli_tests.rs index dc418c961a..8def34728c 100644 --- a/language/tools/move-cli/tests/cli_tests.rs +++ b/language/tools/move-cli/tests/cli_tests.rs @@ -71,20 +71,13 @@ const UPLOAD_PACKAGE_PATH: &str = "./tests/upload_tests"; #[test] fn upload_package_to_movey_works() { - let test_path = String::from("/upload_package_to_movey_works"); - let (home, credential_file) = setup_move_home(&test_path); - let _ = fs::remove_file(&credential_file); - - fs::create_dir_all(&home).unwrap(); - let mut file = File::create(&credential_file).unwrap(); - let credential_content = String::from("[registry]\ntoken=\"test-token\"\n"); - file.write_all(&credential_content.as_bytes()).unwrap(); let package_path = format!("{}/valid_package", UPLOAD_PACKAGE_PATH); init_git(&package_path, true); + let cli_exe = env!("CARGO_BIN_EXE_move"); let output = Command::new(cli_exe) .current_dir(&package_path) - .args(["movey-upload", "--test", "--test-path", &test_path]) + .args(["movey-upload", "--test", "--test-token", "test-token"]) .output() .unwrap(); @@ -95,15 +88,16 @@ fn upload_package_to_movey_works() { assert!(data.contains(r#""token":"test-token""#)); assert!(data.contains(r#""subdir":"\n""#), "{}", data); assert!(data.contains(r#""github_repo_url":"https://github.com/move-language/move""#)); - fs::remove_file(&res_path).unwrap(); - clean_up(&home, &package_path); + fs::remove_file(&res_path).unwrap(); + clean_up(&package_path); } #[test] fn upload_package_to_movey_with_no_remote_should_panic() { let package_path = format!("{}/no_git_remote_package", UPLOAD_PACKAGE_PATH); init_git(&package_path, false); + let cli_exe = env!("CARGO_BIN_EXE_move"); let output = Command::new(cli_exe) .current_dir(&package_path) @@ -114,68 +108,8 @@ fn upload_package_to_movey_with_no_remote_should_panic() { assert!(!output.status.success()); let error = String::from_utf8_lossy(output.stderr.as_slice()).to_string(); assert!(error.contains("invalid git repository")); - clean_up("", &package_path); -} - -#[test] -fn upload_package_to_movey_with_no_credential_should_panic() { - let test_path = String::from("/upload_package_to_movey_with_no_credential_should_panic"); - let (home, credential_file) = setup_move_home(&test_path); - let _ = fs::remove_file(&credential_file); - - let package_path = format!("{}/no_credential_package", UPLOAD_PACKAGE_PATH); - init_git(&package_path, true); - let cli_exe = env!("CARGO_BIN_EXE_move"); - let output = Command::new(cli_exe) - .current_dir(&package_path) - .args(["movey-upload", "--test", "--test-path", &test_path]) - .output() - .unwrap(); - - assert!(!output.status.success()); - let error = String::from_utf8_lossy(output.stderr.as_slice()).to_string(); - assert!( - error.contains( - "There seems to be an error with your Movey credential. \ - Please run `move login` and follow the instructions." - ), - "Received: {}", - error - ); - clean_up(&home, &package_path); -} -#[test] -fn upload_package_to_movey_with_bad_credential_should_panic() { - let test_path = String::from("/upload_package_to_movey_with_bad_credential_should_panic"); - let (home, credential_file) = setup_move_home(&test_path); - let _ = fs::remove_file(&credential_file); - - fs::create_dir_all(&home).unwrap(); - let mut file = File::create(&credential_file).unwrap(); - let bad_content = String::from("[registry]\ntoken=\n"); - file.write_all(&bad_content.as_bytes()).unwrap(); - - let package_path = format!("{}/bad_credential_package", UPLOAD_PACKAGE_PATH); - init_git(&package_path, true); - let cli_exe = env!("CARGO_BIN_EXE_move"); - let output = Command::new(cli_exe) - .current_dir(&package_path) - .args(["movey-upload", "--test", "--test-path", &test_path]) - .output() - .unwrap(); - - assert!(!output.status.success()); - let error = String::from_utf8_lossy(output.stderr.as_slice()).to_string(); - assert!( - error.contains( - "There seems to be an error with your Movey credential. \ - Please run `move login` and follow the instructions." - ), - "Received: {}", - error - ); - clean_up(&home, &package_path); + clean_up(&package_path); } // is_valid == true: all git commands are run @@ -333,22 +267,7 @@ fn clean_up(move_home: &str) { let _ = fs::remove_dir_all(move_home); } -fn clean_up(move_home: &str, package_path: &str) { - if !move_home.is_empty() { - let _ = fs::remove_dir_all(move_home); - } +fn clean_up(package_path: &str) { let _ = fs::remove_file(format!("{}/simple_file", package_path)); fs::remove_dir_all(format!("{}/.git", package_path)).unwrap(); } - -fn setup_move_home(test_path: &str) -> (String, String) { - let cwd = std::env::current_dir().unwrap(); - let mut move_home: String = String::from(cwd.to_string_lossy()); - std::env::set_var("TEST_MOVE_HOME", &move_home); - - if !test_path.is_empty() { - move_home.push_str(&test_path); - } - let credential_file = move_home.clone() + MOVEY_API_KEY_PATH; - (move_home, credential_file) -} diff --git a/language/tools/move-package/src/resolution/resolution_graph.rs b/language/tools/move-package/src/resolution/resolution_graph.rs index 6e4d1103ed..1ef8726583 100644 --- a/language/tools/move-package/src/resolution/resolution_graph.rs +++ b/language/tools/move-package/src/resolution/resolution_graph.rs @@ -16,10 +16,7 @@ use crate::{ BuildConfig, }; use anyhow::{bail, Context, Result}; -use move_command_line_common::{ - files::{find_move_filenames, FileHash}, - movey, -}; +use move_command_line_common::files::{find_move_filenames, FileHash}; use move_core_types::account_address::AccountAddress; use move_symbol_pool::Symbol; use petgraph::{algo, graphmap::DiGraphMap, Outgoing}; @@ -31,7 +28,6 @@ use std::{ path::{Path, PathBuf}, process::Command, rc::Rc, - thread, }; pub type ResolvedTable = ResolutionTable; @@ -549,19 +545,6 @@ impl ResolvingGraph { fn download_and_update_if_remote(dep_name: PackageName, dep: &Dependency) -> Result<()> { if let Some(git_info) = &dep.git_info { if !git_info.download_to.exists() { - let git_url = git_info.git_url.clone().to_string(); - let git_rev = git_info.git_rev.clone().to_string(); - let subdir = git_info.subdir.clone(); - let subdir = subdir.as_path().to_string_lossy().to_string(); - thread::spawn(move || { - let params = [("url", git_url), ("rev", git_rev), ("subdir", subdir)]; - let client = reqwest::blocking::Client::new(); - let _ = client - .post(&format!("{}/api/v1/download", movey::MOVEY_URL)) - .form(¶ms) - .send(); - }); - Command::new("git") .args([ "clone", From ccc39c601c2284fe56cc76fed444b08d8b214c73 Mon Sep 17 00:00:00 2001 From: ea-open-source Date: Fri, 22 Jul 2022 12:20:30 +0700 Subject: [PATCH 15/22] Add Movey server Mock, refactor test code in upload - Add more integration test to Movey upload - Remove unused stub move packages - Upgrade `log` crate version - Add `httpmock` crate --- devtools/x-core/Cargo.toml | 2 +- language/tools/move-cli/Cargo.toml | 1 + .../tools/move-cli/src/base/movey_upload.rs | 93 ++++++------ language/tools/move-cli/src/lib.rs | 2 +- .../move-cli/src/utils/movey_credential.rs | 81 +++++++++- language/tools/move-cli/tests/cli_tests.rs | 138 ++++++++++++++++-- .../upload_tests/valid_package/Move.toml | 6 - .../valid_package/sources/Dummy.move | 1 - .../Move.toml | 0 .../sources/Dummy.move | 0 .../Move.toml | 0 .../sources/Dummy.move | 0 .../Move.toml | 0 .../sources/Dummy.move | 0 14 files changed, 250 insertions(+), 74 deletions(-) delete mode 100644 language/tools/move-cli/tests/upload_tests/valid_package/Move.toml delete mode 100644 language/tools/move-cli/tests/upload_tests/valid_package/sources/Dummy.move rename language/tools/move-cli/tests/upload_tests/{bad_credential_package => valid_package1}/Move.toml (100%) rename language/tools/move-cli/tests/upload_tests/{bad_credential_package => valid_package1}/sources/Dummy.move (100%) rename language/tools/move-cli/tests/upload_tests/{no_commit_id_package => valid_package2}/Move.toml (100%) rename language/tools/move-cli/tests/upload_tests/{no_commit_id_package => valid_package2}/sources/Dummy.move (100%) rename language/tools/move-cli/tests/upload_tests/{no_credential_package => valid_package3}/Move.toml (100%) rename language/tools/move-cli/tests/upload_tests/{no_credential_package => valid_package3}/sources/Dummy.move (100%) diff --git a/devtools/x-core/Cargo.toml b/devtools/x-core/Cargo.toml index 710b0b403a..b02bb7fe89 100644 --- a/devtools/x-core/Cargo.toml +++ b/devtools/x-core/Cargo.toml @@ -14,7 +14,7 @@ determinator = "0.7.0" guppy = "0.12.3" indoc = "1.0.3" hex = "0.4.3" -log = "0.4.14" +log = "0.4.17" toml = "0.5.8" once_cell = "1.7.2" ouroboros = "0.9.2" diff --git a/language/tools/move-cli/Cargo.toml b/language/tools/move-cli/Cargo.toml index 6e6a1b856e..c8e7897e15 100644 --- a/language/tools/move-cli/Cargo.toml +++ b/language/tools/move-cli/Cargo.toml @@ -53,6 +53,7 @@ reqwest = { version = "0.10", features = ["blocking", "json"] } [dev-dependencies] datatest-stable = "0.1.1" +httpmock = "0.6.6" [[bin]] name = "move" diff --git a/language/tools/move-cli/src/base/movey_upload.rs b/language/tools/move-cli/src/base/movey_upload.rs index 5c2e45a1b1..7a4e33692c 100644 --- a/language/tools/move-cli/src/base/movey_upload.rs +++ b/language/tools/move-cli/src/base/movey_upload.rs @@ -1,13 +1,15 @@ // Copyright (c) The Move Contributors // SPDX-License-Identifier: Apache-2.0 -use crate::utils::movey_credential; +use std::{env, fs::File, path::PathBuf, process::Command}; + use anyhow::bail; use clap::*; -use move_command_line_common::{env::MOVE_HOME, movey}; -use move_package::BuildConfig; use reqwest::blocking::Client; -use std::{fs, process::Command}; + +use move_command_line_common::env::MOVE_HOME; + +use crate::utils::movey_credential; #[derive(serde::Serialize, Default)] pub struct MoveyUploadRequest { @@ -17,16 +19,30 @@ pub struct MoveyUploadRequest { subdir: String, } -/// Upload the package to Movey.net. +/// Upload the package metadata to Movey.net. #[derive(Parser)] #[clap(name = "movey-upload")] -pub struct MoveyUpload { - #[clap(long = "test-token")] - test_token: Option, -} +pub struct MoveyUpload; impl MoveyUpload { - pub fn execute(self, config: BuildConfig) -> anyhow::Result<()> { + pub fn execute(self, path: Option) -> anyhow::Result<()> { + if let Some(path) = path { + if path.exists() && path.is_dir() { + let _ = env::set_current_dir(&path); + } else { + bail!("invalid directory") + } + } + // make sure it's a Move project + let move_toml = File::open("Move.toml"); + if move_toml.is_err() { + bail!("Move.toml not found") + } + let metadata = move_toml.unwrap().metadata()?; + if metadata.len() == 0 { + bail!("Move.toml not found") + } + let mut movey_upload_request: MoveyUploadRequest = Default::default(); let mut output = Command::new("git") .current_dir(".") @@ -82,44 +98,31 @@ impl MoveyUpload { } } movey_upload_request.total_files = total_files; - movey_upload_request.token = if config.test_mode { - // if running in test mode, get token from CLI option or hardcoded fallback instead of reading from movey_api_key.toml - // to separate MoveyUpload::execute logic from others - if let Some(token) = self.test_token { - token - } else { - "test-token".to_string() - } - } else { - movey_credential::get_registry_api_token(&MOVE_HOME.clone())? - }; - - if config.test_mode { - fs::write( - "./request-body.txt", - serde_json::to_string(&movey_upload_request).expect("invalid request body"), - ) - .expect("unable to write file"); - } else { - let client = Client::new(); - let response = client - .post(&format!("{}/api/v1/post_package/", movey::MOVEY_URL)) - .json(&movey_upload_request) - .send(); - match response { - Ok(response) => { - if response.status().is_success() { - println!("Your package has been successfully uploaded to Movey") - } else if response.status().is_client_error() { - println!("Error: {}", response.text()?) - } else if response.status().is_server_error() { - println!("Error: An unexpected error occurred. Please try again later"); + movey_upload_request.token = movey_credential::get_registry_api_token(&MOVE_HOME)?; + let movey_url = movey_credential::get_movey_url(&MOVE_HOME); + match movey_url { + Ok(url) => { + let client = Client::new(); + let response = client + .post(&format!("{}/api/v1/post_package/", &url)) + .json(&movey_upload_request) + .send(); + match response { + Ok(response) => { + if response.status().is_success() { + println!("Your package has been successfully uploaded to Movey") + } else if response.status().is_client_error() { + bail!("Error: {}", response.text()?) + } else if response.status().is_server_error() { + bail!("Error: An unexpected error occurred. Please try again later"); + } + } + Err(_) => { + bail!("Error: An unexpected error occurred. Please try again later"); } - } - Err(_) => { - println!("Error: An unexpected error occurred. Please try again later"); } } + Err(_) => bail!("Error: An unexpected error occurred. Please try again later"), } Ok(()) } diff --git a/language/tools/move-cli/src/lib.rs b/language/tools/move-cli/src/lib.rs index 3a9029e2c1..cf46066b57 100644 --- a/language/tools/move-cli/src/lib.rs +++ b/language/tools/move-cli/src/lib.rs @@ -114,7 +114,7 @@ pub fn run_cli( Command::Docgen(c) => c.execute(move_args.package_path, move_args.build_config), Command::Errmap(c) => c.execute(move_args.package_path, move_args.build_config), Command::Info(c) => c.execute(move_args.package_path, move_args.build_config), - Command::MoveyUpload(c) => c.execute(move_args.build_config), + Command::MoveyUpload(c) => c.execute(move_args.package_path), Command::New(c) => c.execute_with_defaults(move_args.package_path), Command::Prove(c) => c.execute(move_args.package_path, move_args.build_config), Command::Test(c) => c.execute(move_args.package_path, move_args.build_config, natives), diff --git a/language/tools/move-cli/src/utils/movey_credential.rs b/language/tools/move-cli/src/utils/movey_credential.rs index b6c00197f6..b0cd313059 100644 --- a/language/tools/move-cli/src/utils/movey_credential.rs +++ b/language/tools/move-cli/src/utils/movey_credential.rs @@ -3,10 +3,11 @@ // SPDX-License-Identifier: Apache-2.0 use anyhow::{bail, Context, Result}; +use move_command_line_common::movey::MOVEY_URL; use std::fs; use toml_edit::easy::Value; -pub const MOVEY_API_KEY_PATH: &str = "/movey_api_key.toml"; +pub const MOVEY_API_KEY_PATH: &str = "/movey_credential.toml"; pub fn get_registry_api_token(move_home: &str) -> Result { if let Ok(content) = get_api_token(&move_home) { @@ -37,6 +38,26 @@ fn get_api_token(move_home: &str) -> Result { Ok(token.to_string().replace("\"", "")) } +pub fn get_movey_url(move_home: &str) -> Result { + let credential_path = format!("{}{}", move_home, MOVEY_API_KEY_PATH); + let contents = fs::read_to_string(&credential_path)?; + let mut toml: Value = contents.parse()?; + let registry = toml + .as_table_mut() + .context(format!("Error parsing {}", MOVEY_API_KEY_PATH))? + .get_mut("registry") + .context(format!("Error parsing {}", MOVEY_API_KEY_PATH))?; + let movey_url = registry + .as_table_mut() + .context("Error parsing url")? + .get_mut("url"); + if let Some(url) = movey_url { + Ok(url.to_string().replace("\"", "")) + } else { + Ok(MOVEY_URL.to_string()) + } +} + #[cfg(test)] mod tests { use super::*; @@ -62,11 +83,14 @@ mod tests { let _ = fs::create_dir_all(&move_home); File::create(&credential_path).unwrap(); - let content = "[registry]\ntoken = \"a sample token\""; + let content = r#" + [registry] + token = "test-token" + "#; fs::write(&credential_path, content).unwrap(); let token = get_registry_api_token(&move_home).unwrap(); - assert!(token.contains("a sample token")); + assert!(token.contains("test-token")); clean_up(&move_home) } @@ -104,16 +128,59 @@ mod tests { fs::create_dir_all(&move_home).unwrap(); File::create(&credential_path).unwrap(); - let content = "[registry]\ntoken = a sample token"; - fs::write(&credential_path, content).unwrap(); + let missing_double_quote = r#" + [registry] + token = test-token + "#; + fs::write(&credential_path, missing_double_quote).unwrap(); let token = get_registry_api_token(&move_home); assert!(token.is_err()); - let content = "[registry]\ntokens = \"a sample token\""; - fs::write(&credential_path, content).unwrap(); + let wrong_token_field = r#" + [registry] + tokens = "test-token" + "#; + fs::write(&credential_path, wrong_token_field).unwrap(); let token = get_registry_api_token(&move_home); assert!(token.is_err()); clean_up(&move_home) } + + #[test] + fn get_movey_url_works() { + let test_path = String::from("/get_movey_url_works"); + let (move_home, credential_path) = setup_move_home(&test_path); + let _ = fs::create_dir_all(&move_home); + File::create(&credential_path).unwrap(); + let content = r#" + [registry] + token = "test-token" + url = "test-url" + "#; + fs::write(&credential_path, content).unwrap(); + + let url = get_movey_url(&move_home).unwrap(); + assert_eq!(url, "test-url"); + + clean_up(&move_home) + } + + #[test] + fn get_movey_url_returns_default_url_if_url_field_not_existed() { + let test_path = String::from("/get_movey_url_returns_default_url_if_url_field_not_existed"); + let (move_home, credential_path) = setup_move_home(&test_path); + let _ = fs::create_dir_all(&move_home); + File::create(&credential_path).unwrap(); + let content = r#" + [registry] + token = "test-token" + "#; + fs::write(&credential_path, content).unwrap(); + + let url = get_movey_url(&move_home).unwrap(); + assert_eq!(url, MOVEY_URL); + + clean_up(&move_home) + } } diff --git a/language/tools/move-cli/tests/cli_tests.rs b/language/tools/move-cli/tests/cli_tests.rs index 8def34728c..a7201f9bc0 100644 --- a/language/tools/move-cli/tests/cli_tests.rs +++ b/language/tools/move-cli/tests/cli_tests.rs @@ -71,26 +71,123 @@ const UPLOAD_PACKAGE_PATH: &str = "./tests/upload_tests"; #[test] fn upload_package_to_movey_works() { - let package_path = format!("{}/valid_package", UPLOAD_PACKAGE_PATH); + let package_path = format!("{}/valid_package1", UPLOAD_PACKAGE_PATH); init_git(&package_path, true); + let server = MockServer::start(); + server.mock(|when, then| { + when.method(POST) + .path("/api/v1/post_package/") + .header("content-type", "application/json") + .json_body(json!({ + "github_repo_url":"https://github.com/move-language/move", + "total_files":2, + "token":"test-token", + "subdir":"\n" + })); + then.status(200); + }); + init_stub_registry_file(&package_path, &server.base_url()); + let relative_package_path = PathBuf::from(&package_path); + let absolute_package_path = + path_to_string(&relative_package_path.canonicalize().unwrap()).unwrap(); let cli_exe = env!("CARGO_BIN_EXE_move"); let output = Command::new(cli_exe) - .current_dir(&package_path) - .args(["movey-upload", "--test", "--test-token", "test-token"]) + .env("MOVE_HOME", &absolute_package_path) + .current_dir(&absolute_package_path) + .args(["movey-upload"]) .output() .unwrap(); assert!(output.status.success()); - let res_path = format!("{}/request-body.txt", &package_path); - let data = fs::read_to_string(&res_path).unwrap(); - assert!(data.contains(r#""total_files":2"#), "{}", data); - assert!(data.contains(r#""token":"test-token""#)); - assert!(data.contains(r#""subdir":"\n""#), "{}", data); - assert!(data.contains(r#""github_repo_url":"https://github.com/move-language/move""#)); - - fs::remove_file(&res_path).unwrap(); - clean_up(&package_path); + let output = String::from_utf8_lossy(output.stdout.as_slice()).to_string(); + assert!( + output.contains("Your package has been successfully uploaded to Movey"), + "{}", + output + ); + + clean_up(&absolute_package_path); +} + +#[test] +fn upload_package_to_movey_prints_error_message_if_server_respond_4xx() { + let package_path = format!("{}/valid_package2", UPLOAD_PACKAGE_PATH); + init_git(&package_path, true); + + let server = MockServer::start(); + server.mock(|when, then| { + when.method(POST) + .path("/api/v1/post_package/") + .header("content-type", "application/json") + .json_body(json!({ + "github_repo_url":"https://github.com/move-language/move", + "total_files":2, + "token":"test-token", + "subdir":"\n" + })); + then.status(400).body("Invalid Api token"); + }); + init_stub_registry_file(&package_path, &server.base_url()); + let relative_package_path = PathBuf::from(&package_path); + let absolute_package_path = + path_to_string(&relative_package_path.canonicalize().unwrap()).unwrap(); + + let cli_exe = env!("CARGO_BIN_EXE_move"); + let output = Command::new(cli_exe) + .env("MOVE_HOME", &absolute_package_path) + .current_dir(&absolute_package_path) + .args(["movey-upload"]) + .output() + .unwrap(); + + assert!(!output.status.success()); + let output = String::from_utf8_lossy(output.stderr.as_slice()).to_string(); + assert!(output.contains("Error: Invalid Api token"), "{}", output); + + clean_up(&absolute_package_path); +} + +#[test] +fn upload_package_to_movey_prints_hardcoded_error_message_if_server_respond_5xx() { + let package_path = format!("{}/valid_package3", UPLOAD_PACKAGE_PATH); + init_git(&package_path, true); + + let server = MockServer::start(); + server.mock(|when, then| { + when.method(POST) + .path("/api/v1/post_package/") + .header("content-type", "application/json") + .json_body(json!({ + "github_repo_url":"https://github.com/move-language/move", + "total_files":2, + "token":"test-token", + "subdir":"\n" + })); + then.status(500).body("Invalid Api token"); + }); + init_stub_registry_file(&package_path, &server.base_url()); + let relative_package_path = PathBuf::from(&package_path); + let absolute_package_path = + path_to_string(&relative_package_path.canonicalize().unwrap()).unwrap(); + + let cli_exe = env!("CARGO_BIN_EXE_move"); + let output = Command::new(cli_exe) + .env("MOVE_HOME", &absolute_package_path) + .current_dir(&absolute_package_path) + .args(["movey-upload"]) + .output() + .unwrap(); + + assert!(!output.status.success()); + let output = String::from_utf8_lossy(output.stderr.as_slice()).to_string(); + assert!( + output.contains("Error: An unexpected error occurred. Please try again later"), + "{}", + output + ); + + clean_up(&absolute_package_path); } #[test] @@ -101,7 +198,7 @@ fn upload_package_to_movey_with_no_remote_should_panic() { let cli_exe = env!("CARGO_BIN_EXE_move"); let output = Command::new(cli_exe) .current_dir(&package_path) - .args(["movey-upload", "--test"]) + .args(["movey-upload"]) .output() .unwrap(); @@ -270,4 +367,19 @@ fn clean_up(move_home: &str) { fn clean_up(package_path: &str) { let _ = fs::remove_file(format!("{}/simple_file", package_path)); fs::remove_dir_all(format!("{}/.git", package_path)).unwrap(); + let credential_path = format!("{}{}", package_path, MOVEY_API_KEY_PATH); + let _ = fs::remove_file(&credential_path); +} + +fn init_stub_registry_file(package_path: &str, base_url: &str) { + let credential_path = format!("{}{}", package_path, MOVEY_API_KEY_PATH); + let content = format!( + r#" + [registry] + token = "test-token" + url = "{}" + "#, + base_url + ); + fs::write(credential_path, content).expect("Unable to write file"); } diff --git a/language/tools/move-cli/tests/upload_tests/valid_package/Move.toml b/language/tools/move-cli/tests/upload_tests/valid_package/Move.toml deleted file mode 100644 index 637d99d854..0000000000 --- a/language/tools/move-cli/tests/upload_tests/valid_package/Move.toml +++ /dev/null @@ -1,6 +0,0 @@ -[package] -name = "Package1" -version = "0.0.0" - -[addresses] -Std = "0x1" diff --git a/language/tools/move-cli/tests/upload_tests/valid_package/sources/Dummy.move b/language/tools/move-cli/tests/upload_tests/valid_package/sources/Dummy.move deleted file mode 100644 index 45646f1b13..0000000000 --- a/language/tools/move-cli/tests/upload_tests/valid_package/sources/Dummy.move +++ /dev/null @@ -1 +0,0 @@ -module 0x1::Dummy {} diff --git a/language/tools/move-cli/tests/upload_tests/bad_credential_package/Move.toml b/language/tools/move-cli/tests/upload_tests/valid_package1/Move.toml similarity index 100% rename from language/tools/move-cli/tests/upload_tests/bad_credential_package/Move.toml rename to language/tools/move-cli/tests/upload_tests/valid_package1/Move.toml diff --git a/language/tools/move-cli/tests/upload_tests/bad_credential_package/sources/Dummy.move b/language/tools/move-cli/tests/upload_tests/valid_package1/sources/Dummy.move similarity index 100% rename from language/tools/move-cli/tests/upload_tests/bad_credential_package/sources/Dummy.move rename to language/tools/move-cli/tests/upload_tests/valid_package1/sources/Dummy.move diff --git a/language/tools/move-cli/tests/upload_tests/no_commit_id_package/Move.toml b/language/tools/move-cli/tests/upload_tests/valid_package2/Move.toml similarity index 100% rename from language/tools/move-cli/tests/upload_tests/no_commit_id_package/Move.toml rename to language/tools/move-cli/tests/upload_tests/valid_package2/Move.toml diff --git a/language/tools/move-cli/tests/upload_tests/no_commit_id_package/sources/Dummy.move b/language/tools/move-cli/tests/upload_tests/valid_package2/sources/Dummy.move similarity index 100% rename from language/tools/move-cli/tests/upload_tests/no_commit_id_package/sources/Dummy.move rename to language/tools/move-cli/tests/upload_tests/valid_package2/sources/Dummy.move diff --git a/language/tools/move-cli/tests/upload_tests/no_credential_package/Move.toml b/language/tools/move-cli/tests/upload_tests/valid_package3/Move.toml similarity index 100% rename from language/tools/move-cli/tests/upload_tests/no_credential_package/Move.toml rename to language/tools/move-cli/tests/upload_tests/valid_package3/Move.toml diff --git a/language/tools/move-cli/tests/upload_tests/no_credential_package/sources/Dummy.move b/language/tools/move-cli/tests/upload_tests/valid_package3/sources/Dummy.move similarity index 100% rename from language/tools/move-cli/tests/upload_tests/no_credential_package/sources/Dummy.move rename to language/tools/move-cli/tests/upload_tests/valid_package3/sources/Dummy.move From e98bb7327d7bafe3bd723c26125d5fc920e989b2 Mon Sep 17 00:00:00 2001 From: ea-open-source Date: Mon, 25 Jul 2022 22:35:08 +0700 Subject: [PATCH 16/22] Rename move_command_line_common::movey.rs to movey_constants.rs --- Cargo.lock | 1239 ++++++++++++++++- .../move-command-line-common/src/movey.rs | 8 - .../move-cli/src/utils/movey_credential.rs | 2 +- 3 files changed, 1191 insertions(+), 58 deletions(-) delete mode 100644 language/move-command-line-common/src/movey.rs diff --git a/Cargo.lock b/Cargo.lock index 8ccc186248..402d8c8667 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -98,7 +98,7 @@ version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" dependencies = [ - "winapi", + "winapi 0.3.9", ] [[package]] @@ -107,7 +107,7 @@ version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" dependencies = [ - "winapi", + "winapi 0.3.9", ] [[package]] @@ -134,6 +134,153 @@ version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" +[[package]] +name = "ascii-canvas" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8824ecca2e851cec16968d54a01dd372ef8f95b244fb84b84e70128be347c3c6" +dependencies = [ + "term 0.7.0", +] + +[[package]] +name = "assert-json-diff" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47e4f2b81832e72834d7518d8487a0396a28cc408186a2e8854c0f98011faf12" +dependencies = [ + "serde 1.0.130", + "serde_json", +] + +[[package]] +name = "async-channel" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2114d64672151c0c5eaa5e131ec84a74f06e1e559830dabba01ca30605d66319" +dependencies = [ + "concurrent-queue", + "event-listener", + "futures-core", +] + +[[package]] +name = "async-executor" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "871f9bb5e0a22eeb7e8cf16641feb87c9dc67032ccf8ff49e772eb9941d3a965" +dependencies = [ + "async-task", + "concurrent-queue", + "fastrand", + "futures-lite", + "once_cell", + "slab", +] + +[[package]] +name = "async-global-executor" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5262ed948da60dd8956c6c5aca4d4163593dddb7b32d73267c93dab7b2e98940" +dependencies = [ + "async-channel", + "async-executor", + "async-io", + "async-lock", + "blocking", + "futures-lite", + "num_cpus", + "once_cell", +] + +[[package]] +name = "async-io" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5e18f61464ae81cde0a23e713ae8fd299580c54d697a35820cfd0625b8b0e07" +dependencies = [ + "concurrent-queue", + "futures-lite", + "libc", + "log", + "once_cell", + "parking", + "polling", + "slab", + "socket2 0.4.4", + "waker-fn", + "winapi 0.3.9", +] + +[[package]] +name = "async-lock" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e97a171d191782fba31bb902b14ad94e24a68145032b7eedf871ab0bc0d077b6" +dependencies = [ + "event-listener", +] + +[[package]] +name = "async-object-pool" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aeb901c30ebc2fc4ab46395bbfbdba9542c16559d853645d75190c3056caf3bc" +dependencies = [ + "async-std", +] + +[[package]] +name = "async-process" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf2c06e30a24e8c78a3987d07f0930edf76ef35e027e7bdb063fccafdad1f60c" +dependencies = [ + "async-io", + "blocking", + "cfg-if 1.0.0", + "event-listener", + "futures-lite", + "libc", + "once_cell", + "signal-hook", + "winapi 0.3.9", +] + +[[package]] +name = "async-std" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62565bb4402e926b29953c785397c6dc0391b7b446e45008b0049eb43cec6f5d" +dependencies = [ + "async-channel", + "async-global-executor", + "async-io", + "async-lock", + "async-process", + "crossbeam-utils", + "futures-channel", + "futures-core", + "futures-io", + "futures-lite", + "gloo-timers", + "kv-log-macro", + "log", + "memchr", + "once_cell", + "pin-project-lite 0.2.7", + "pin-utils", + "slab", + "wasm-bindgen-futures", +] + +[[package]] +name = "async-task" +version = "4.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a40729d2133846d9ed0ea60a8b9541bccddab49cd30f0715a1da672fe9a2524" + [[package]] name = "async-trait" version = "0.1.48" @@ -145,6 +292,12 @@ dependencies = [ "syn 1.0.74", ] +[[package]] +name = "atomic-waker" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "065374052e7df7ee4047b1160cca5e1467a12351a40b3da123c870ba0b8eda2a" + [[package]] name = "atty" version = "0.2.14" @@ -153,7 +306,7 @@ checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" dependencies = [ "hermit-abi", "libc", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -180,6 +333,17 @@ version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" +[[package]] +name = "basic-cookies" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb53b6b315f924c7f113b162e53b3901c05fc9966baf84d201dfcc7432a4bb38" +dependencies = [ + "lalrpop", + "lalrpop-util", + "regex", +] + [[package]] name = "bcs" version = "0.1.3" @@ -333,6 +497,20 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8d696c370c750c948ada61c69a0ee2cbbb9c50b1019ddb86d9317157a99c2cae" +[[package]] +name = "blocking" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6ccb65d468978a086b69884437ded69a90faab3bbe6e67f242173ea728acccc" +dependencies = [ + "async-channel", + "async-task", + "atomic-waker", + "fastrand", + "futures-lite", + "once_cell", +] + [[package]] name = "bstr" version = "0.2.15" @@ -413,12 +591,24 @@ version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" +[[package]] +name = "bytes" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e4cec68f03f32e44924783795810fa50a7035d8c8ebe78580ad7e6c703fba38" + [[package]] name = "bytes" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b700ce4376041dcd0a327fd0097c41095743c4c8af8887265942faf1100bd040" +[[package]] +name = "cache-padded" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1db59621ec70f09c5e9b597b220c7a2b43611f4710dc03ceb8748637775692c" + [[package]] name = "camino" version = "1.0.5" @@ -465,6 +655,12 @@ dependencies = [ "rustc_version", ] +[[package]] +name = "castaway" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2698f953def977c68f935bb0dfa959375ad4638570e969e2f1e9f433cbf1af6" + [[package]] name = "cc" version = "1.0.67" @@ -503,7 +699,7 @@ dependencies = [ "num-integer", "num-traits 0.2.14", "time", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -620,7 +816,7 @@ checksum = "b3616f750b84d8f0de8a58bda93e08e2a81ad3f523089b05f1dffecab48c6cbd" dependencies = [ "atty", "lazy_static 1.4.0", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -644,6 +840,15 @@ dependencies = [ "memchr", ] +[[package]] +name = "concurrent-queue" +version = "1.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af4780a44ab5696ea9e28294517f1fffb421a83a25af521333c838635509db9c" +dependencies = [ + "cache-padded", +] + [[package]] name = "config" version = "0.11.0" @@ -688,6 +893,22 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" +[[package]] +name = "core-foundation" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" + [[package]] name = "cpuid-bool" version = "0.1.2" @@ -828,7 +1049,7 @@ dependencies = [ "parking_lot 0.11.1", "signal-hook", "signal-hook-mio", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -844,7 +1065,7 @@ dependencies = [ "parking_lot 0.11.1", "signal-hook", "signal-hook-mio", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -853,7 +1074,7 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3a6966607622438301997d3dac0d2f6e9a90c68bb6bc1785ea98456ab93c0507" dependencies = [ - "winapi", + "winapi 0.3.9", ] [[package]] @@ -862,7 +1083,7 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2ae1b35a484aa10e07fe0638d02301c5ad24de82d310ccbd2f3693da5f09bf1c" dependencies = [ - "winapi", + "winapi 0.3.9", ] [[package]] @@ -913,6 +1134,16 @@ dependencies = [ "memchr", ] +[[package]] +name = "ctor" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f877be4f7c9f246b183111634f75baa039715e3f46ce860677d3b19a69fb229c" +dependencies = [ + "quote 1.0.9", + "syn 1.0.74", +] + [[package]] name = "ctr" version = "0.6.0" @@ -929,7 +1160,38 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a19c6cedffdc8c03a3346d723eb20bd85a13362bb96dc2ac000842c6381ec7bf" dependencies = [ "nix", - "winapi", + "winapi 0.3.9", +] + +[[package]] +name = "curl" +version = "0.4.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "509bd11746c7ac09ebd19f0b17782eae80aadee26237658a6b4808afb5c11a22" +dependencies = [ + "curl-sys", + "libc", + "openssl-probe", + "openssl-sys", + "schannel", + "socket2 0.4.4", + "winapi 0.3.9", +] + +[[package]] +name = "curl-sys" +version = "0.4.56+curl-7.83.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6093e169dd4de29e468fa649fbae11cdcd5551c81fe5bf1b0677adad7ef3d26f" +dependencies = [ + "cc", + "libc", + "libnghttp2-sys", + "libz-sys", + "openssl-sys", + "pkg-config", + "vcpkg", + "winapi 0.3.9", ] [[package]] @@ -1034,7 +1296,7 @@ dependencies = [ "bcs", "bitvec 0.19.6", "byteorder", - "bytes", + "bytes 1.0.1", "criterion", "curve25519-dalek-fiat", "diem-crypto-derive", @@ -1084,6 +1346,12 @@ dependencies = [ "smallvec", ] +[[package]] +name = "diff" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8" + [[package]] name = "difference" version = "2.0.0" @@ -1153,7 +1421,7 @@ checksum = "3fd78930633bd1c6e35c4b42b1df7b0cbc6bc191146e512bb3bedf243fcc3901" dependencies = [ "libc", "redox_users 0.3.5", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -1174,7 +1442,7 @@ checksum = "03d86534ed367a67548dc68113a0f5db55432fdfbb6e6f9d77704397d95d5780" dependencies = [ "libc", "redox_users 0.4.0", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -1185,7 +1453,7 @@ checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d" dependencies = [ "libc", "redox_users 0.4.0", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -1249,12 +1517,30 @@ version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" +[[package]] +name = "ena" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7402b94a93c24e742487327a7cd839dc9d36fec9de9fb25b09f2dae459f36c3" +dependencies = [ + "log", +] + [[package]] name = "encode_unicode" version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" +[[package]] +name = "encoding_rs" +version = "0.8.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9852635589dc9f9ea1b6fe9f05b50ef208c85c834a562f0c6abb1c475736ec2b" +dependencies = [ + "cfg-if 1.0.0", +] + [[package]] name = "env_logger" version = "0.8.4" @@ -1324,7 +1610,7 @@ version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34c90e0a755da706ce0970ec0fa8cc48aabcc8e8efa1245336acf718dab06ffe" dependencies = [ - "bytes", + "bytes 1.0.1", "ethereum-types 0.12.1", "hash-db", "hash256-std-hasher", @@ -1372,6 +1658,12 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0f58da196a1fc8f14cb51f373f504efc66c434c577b777c2cd30d6fad16e4822" +[[package]] +name = "event-listener" +version = "2.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" + [[package]] name = "evm" version = "0.33.1" @@ -1480,6 +1772,15 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" +[[package]] +name = "fastrand" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7a407cfaa3385c4ae6b23e84623d48c2798d06e3e6a1878f7f59f17b3f86499" +dependencies = [ + "instant", +] + [[package]] name = "fiat-crypto" version = "0.1.6" @@ -1522,6 +1823,21 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + [[package]] name = "form_urlencoded" version = "1.0.1" @@ -1538,6 +1854,22 @@ version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d79238883cf0307100b90aba4a755d8051a3182305dfe7f649a1e9dc0517006f" +[[package]] +name = "fuchsia-zircon" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" +dependencies = [ + "bitflags", + "fuchsia-zircon-sys", +] + +[[package]] +name = "fuchsia-zircon-sys" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" + [[package]] name = "funty" version = "1.1.0" @@ -1598,6 +1930,21 @@ version = "0.3.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b0e06c393068f3a6ef246c75cdca793d6a46347e75286933e5e75fd2fd11582" +[[package]] +name = "futures-lite" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7694489acd39452c77daa48516b894c153f192c3578d5a839b62c58099fcbf48" +dependencies = [ + "fastrand", + "futures-core", + "futures-io", + "memchr", + "parking", + "pin-project-lite 0.2.7", + "waker-fn", +] + [[package]] name = "futures-macro" version = "0.3.16" @@ -1637,7 +1984,7 @@ dependencies = [ "futures-sink", "futures-task", "memchr", - "pin-project-lite", + "pin-project-lite 0.2.7", "pin-utils", "proc-macro-hack", "proc-macro-nested", @@ -1725,6 +2072,18 @@ dependencies = [ "walkdir", ] +[[package]] +name = "gloo-timers" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fb7d06c1c8cc2a29bee7ec961009a0b2caa0793ee4900c2ffb348734ba1c8f9" +dependencies = [ + "futures-channel", + "futures-core", + "js-sys", + "wasm-bindgen", +] + [[package]] name = "guppy" version = "0.12.6" @@ -1773,6 +2132,26 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "92620684d99f750bae383ecb3be3748142d6095760afd5cbcf2261e9a279d780" +[[package]] +name = "h2" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e4728fd124914ad25e99e3d15a9361a879f6620f63cb56bbb08f95abb97a535" +dependencies = [ + "bytes 0.5.6", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http", + "indexmap", + "slab", + "tokio 0.2.25", + "tokio-util", + "tracing", + "tracing-futures", +] + [[package]] name = "half" version = "1.7.1" @@ -1859,6 +2238,84 @@ dependencies = [ "digest 0.9.0", ] +[[package]] +name = "http" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75f43d41e26995c17e71ee126451dd3941010b0514a81a9d11f3b341debc2399" +dependencies = [ + "bytes 1.0.1", + "fnv", + "itoa 1.0.1", +] + +[[package]] +name = "http-body" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13d5ff830006f7646652e057693569bfe0d51760c0085a071769d142a205111b" +dependencies = [ + "bytes 0.5.6", + "http", +] + +[[package]] +name = "http-body" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1" +dependencies = [ + "bytes 1.0.1", + "http", + "pin-project-lite 0.2.7", +] + +[[package]] +name = "httparse" +version = "1.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "496ce29bb5a52785b44e0f7ca2847ae0bb839c9bd28f69acac9b99d461c0c04c" + +[[package]] +name = "httpdate" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "494b4d60369511e7dea41cf646832512a94e542f68bb9c49e54518e0f468eb47" + +[[package]] +name = "httpdate" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" + +[[package]] +name = "httpmock" +version = "0.6.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c159c4fc205e6c1a9b325cb7ec135d13b5f47188ce175dabb76ec847f331d9bd" +dependencies = [ + "assert-json-diff", + "async-object-pool", + "async-trait", + "base64", + "basic-cookies", + "crossbeam-utils", + "form_urlencoded", + "futures-util", + "hyper 0.14.20", + "isahc", + "lazy_static 1.4.0", + "levenshtein", + "log", + "regex", + "serde 1.0.130", + "serde_json", + "serde_regex", + "similar", + "tokio 1.19.2", + "url", +] + [[package]] name = "humansize" version = "1.1.0" @@ -1881,6 +2338,66 @@ dependencies = [ "serde 1.0.130", ] +[[package]] +name = "hyper" +version = "0.13.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a6f157065790a3ed2f88679250419b5cdd96e714a0d65f7797fd337186e96bb" +dependencies = [ + "bytes 0.5.6", + "futures-channel", + "futures-core", + "futures-util", + "h2", + "http", + "http-body 0.3.1", + "httparse", + "httpdate 0.3.2", + "itoa 0.4.7", + "pin-project", + "socket2 0.3.19", + "tokio 0.2.25", + "tower-service", + "tracing", + "want", +] + +[[package]] +name = "hyper" +version = "0.14.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02c929dc5c39e335a03c405292728118860721b10190d98c2a0f0efd5baafbac" +dependencies = [ + "bytes 1.0.1", + "futures-channel", + "futures-core", + "futures-util", + "http", + "http-body 0.4.5", + "httparse", + "httpdate 1.0.2", + "itoa 1.0.1", + "pin-project-lite 0.2.7", + "socket2 0.4.4", + "tokio 1.19.2", + "tower-service", + "tracing", + "want", +] + +[[package]] +name = "hyper-tls" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d979acc56dcb5b8dddba3917601745e877576475aa046df3226eabdecef78eed" +dependencies = [ + "bytes 0.5.6", + "hyper 0.13.10", + "native-tls", + "tokio 0.2.25", + "tokio-tls", +] + [[package]] name = "idna" version = "0.2.2" @@ -2025,12 +2542,54 @@ dependencies = [ "proptest", ] +[[package]] +name = "iovec" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e" +dependencies = [ + "libc", +] + +[[package]] +name = "ipnet" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "879d54834c8c76457ef4293a689b2a8c59b076067ad77b15efafbb05f92a592b" + [[package]] name = "is_ci" version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "616cde7c720bb2bb5824a224687d8f77bfd38922027f01d825cd7453be5099fb" +[[package]] +name = "isahc" +version = "1.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "334e04b4d781f436dc315cb1e7515bd96826426345d498149e4bde36b67f8ee9" +dependencies = [ + "async-channel", + "castaway", + "crossbeam-utils", + "curl", + "curl-sys", + "encoding_rs", + "event-listener", + "futures-lite", + "http", + "log", + "mime", + "once_cell", + "polling", + "slab", + "sluice", + "tracing", + "tracing-futures", + "url", + "waker-fn", +] + [[package]] name = "itertools" version = "0.9.0" @@ -2076,6 +2635,57 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "67c21572b4949434e4fc1e1978b99c5f77064153c59d998bf13ecd96fb5ecba7" +[[package]] +name = "kernel32-sys" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" +dependencies = [ + "winapi 0.2.8", + "winapi-build", +] + +[[package]] +name = "kv-log-macro" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0de8b303297635ad57c9f5059fd9cee7a47f8e8daa09df0fcd07dd39fb22977f" +dependencies = [ + "log", +] + +[[package]] +name = "lalrpop" +version = "0.19.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b30455341b0e18f276fa64540aff54deafb54c589de6aca68659c63dd2d5d823" +dependencies = [ + "ascii-canvas", + "atty", + "bit-set", + "diff", + "ena", + "itertools 0.10.1", + "lalrpop-util", + "petgraph 0.6.0", + "pico-args", + "regex", + "regex-syntax", + "string_cache", + "term 0.7.0", + "tiny-keccak", + "unicode-xid 0.2.2", +] + +[[package]] +name = "lalrpop-util" +version = "0.19.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bcf796c978e9b4d983414f4caedc9273aa33ee214c5b887bd55fde84c85d2dc4" +dependencies = [ + "regex", +] + [[package]] name = "language-benchmarks" version = "0.1.0" @@ -2107,6 +2717,12 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +[[package]] +name = "levenshtein" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db13adb97ab515a3691f56e4dbab09283d0b86cb45abd991d8634a9d6f501760" + [[package]] name = "lexical-core" version = "0.7.6" @@ -2126,6 +2742,28 @@ version = "0.2.126" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" +[[package]] +name = "libnghttp2-sys" +version = "0.1.7+1.45.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57ed28aba195b38d5ff02b9170cbff627e336a20925e43b4945390401c5dc93f" +dependencies = [ + "cc", + "libc", +] + +[[package]] +name = "libz-sys" +version = "1.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9702761c3935f8cc2f101793272e202c72b99da8f4224a19ddcf1279a6450bbf" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + [[package]] name = "linked-hash-map" version = "0.5.4" @@ -2152,12 +2790,13 @@ dependencies = [ [[package]] name = "log" -version = "0.4.14" +version = "0.4.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" +checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" dependencies = [ "cfg-if 1.0.0", "serde 1.0.130", + "value-bag", ] [[package]] @@ -2221,6 +2860,41 @@ dependencies = [ "autocfg", ] +[[package]] +name = "mime" +version = "0.3.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" + +[[package]] +name = "mime_guess" +version = "2.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4192263c238a5f0d0c6bfd21f336a313a4ce1c450542449ca191bb657b4642ef" +dependencies = [ + "mime", + "unicase", +] + +[[package]] +name = "mio" +version = "0.6.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4afd66f5b91bf2a3bc13fad0e21caedac168ca4c707504e75585648ae80e4cc4" +dependencies = [ + "cfg-if 0.1.10", + "fuchsia-zircon", + "fuchsia-zircon-sys", + "iovec", + "kernel32-sys", + "libc", + "log", + "miow 0.2.2", + "net2", + "slab", + "winapi 0.2.8", +] + [[package]] name = "mio" version = "0.7.13" @@ -2229,9 +2903,9 @@ checksum = "8c2bdb6314ec10835cd3293dd268473a835c02b7b352e788be788b3c6ca6bb16" dependencies = [ "libc", "log", - "miow", + "miow 0.3.7", "ntapi", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -2246,13 +2920,25 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "miow" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebd808424166322d4a38da87083bfddd3ac4c131334ed55856112eb06d46944d" +dependencies = [ + "kernel32-sys", + "net2", + "winapi 0.2.8", + "ws2_32-sys", +] + [[package]] name = "miow" version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b9f1c5b025cda876f66ef43a113f91ebc9f4ccef34843000e0adf6ebbab84e21" dependencies = [ - "winapi", + "winapi 0.3.9", ] [[package]] @@ -2425,6 +3111,7 @@ dependencies = [ "colored", "datatest-stable", "difference", + "httpmock", "itertools 0.10.1", "move-binary-format", "move-bytecode-source-map", @@ -2451,7 +3138,9 @@ dependencies = [ "once_cell", "read-write-set", "read-write-set-dynamic", + "reqwest", "serde 1.0.130", + "serde_json", "serde_yaml", "tempfile", "toml_edit", @@ -2796,7 +3485,7 @@ dependencies = [ "shell-words", "simplelog", "tempfile", - "tokio", + "tokio 1.19.2", "toml", "walkdir", ] @@ -2825,7 +3514,7 @@ dependencies = [ "serde 1.0.130", "serde_json", "tera", - "tokio", + "tokio 1.19.2", ] [[package]] @@ -3161,7 +3850,25 @@ dependencies = [ "parking_lot 0.10.2", "thiserror", "widestring", - "winapi", + "winapi 0.3.9", +] + +[[package]] +name = "native-tls" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd7e2f3618557f980e0b17e8856252eee3c97fa12c54dff0ca290fb6266ca4a9" +dependencies = [ + "lazy_static 1.4.0", + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", ] [[package]] @@ -3170,6 +3877,23 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca2b420f638f07fe83056b55ea190bb815f609ec5a35e7017884a10f78839c9e" +[[package]] +name = "net2" +version = "0.2.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "391630d12b68002ae1e25e8f974306474966550ad82dac6886fb8910c19568ae" +dependencies = [ + "cfg-if 0.1.10", + "libc", + "winapi 0.3.9", +] + +[[package]] +name = "new_debug_unreachable" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4a24736216ec316047a1fc4252e27dabb04218aa4a3f37c6e7ddbf1f9782b54" + [[package]] name = "nextest-config" version = "0.1.0" @@ -3249,7 +3973,7 @@ version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f6bb902e437b6d86e03cce10a7e2af662292c5dfef23b65899ea3ac9354ad44" dependencies = [ - "winapi", + "winapi 0.3.9", ] [[package]] @@ -3406,16 +4130,61 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575" [[package]] -name = "opaque-debug" -version = "0.2.3" +name = "opaque-debug" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c" + +[[package]] +name = "opaque-debug" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" + +[[package]] +name = "openssl" +version = "0.10.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "618febf65336490dfcf20b73f885f5651a0c89c64c2d4a8c3662585a70bf5bd0" +dependencies = [ + "bitflags", + "cfg-if 1.0.0", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b501e44f11665960c7e7fcf062c7d96a14ade4aa98116c004b2e37b5be7d736c" +dependencies = [ + "proc-macro2 1.0.28", + "quote 1.0.9", + "syn 1.0.74", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] -name = "opaque-debug" -version = "0.3.0" +name = "openssl-sys" +version = "0.9.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" +checksum = "e5f9bd0c2710541a3cda73d6f9ac4f1b240de4ae261065d309dbe73d9dceb42f" +dependencies = [ + "autocfg", + "cc", + "libc", + "pkg-config", + "vcpkg", +] [[package]] name = "ordered-float" @@ -3433,7 +4202,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fb233f06c2307e1f5ce2ecad9f8121cffbbee2c95428f44ea85222e460d0d213" dependencies = [ "libc", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -3526,6 +4295,12 @@ dependencies = [ "syn 1.0.74", ] +[[package]] +name = "parking" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "427c3892f9e783d91cc128285287e70a59e206ca452770ece88a76f7a3eddd72" + [[package]] name = "parking_lot" version = "0.10.2" @@ -3568,7 +4343,7 @@ dependencies = [ "libc", "redox_syscall 0.1.57", "smallvec", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -3582,7 +4357,7 @@ dependencies = [ "libc", "redox_syscall 0.2.10", "smallvec", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -3730,6 +4505,38 @@ dependencies = [ "uncased", ] +[[package]] +name = "pico-args" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db8bcd96cb740d03149cbad5518db9fd87126a10ab519c011893b1754134c468" + +[[package]] +name = "pin-project" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78203e83c48cffbe01e4a2d35d566ca4de445d79a85372fc64e378bfc812a260" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "710faf75e1b33345361201d36d04e98ac1ed8909151a017ed384700836104c74" +dependencies = [ + "proc-macro2 1.0.28", + "quote 1.0.9", + "syn 1.0.74", +] + +[[package]] +name = "pin-project-lite" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "257b64915a082f7811703966789728173279bdebb956b143dbcd23f6f970a777" + [[package]] name = "pin-project-lite" version = "0.2.7" @@ -3742,6 +4549,12 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +[[package]] +name = "pkg-config" +version = "0.3.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1df8c4ec4b0627e53bdf214615ad287367e482558cf84b109250b37464dc03ae" + [[package]] name = "plotters" version = "0.3.0" @@ -3770,6 +4583,19 @@ dependencies = [ "plotters-backend", ] +[[package]] +name = "polling" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "685404d509889fade3e86fe3a5803bca2ec09b0c0778d5ada6ec8bf7a8de5259" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "log", + "wepoll-ffi", + "winapi 0.3.9", +] + [[package]] name = "polyval" version = "0.4.5" @@ -3807,6 +4633,12 @@ version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" +[[package]] +name = "precomputed-hash" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" + [[package]] name = "pretty" version = "0.10.0" @@ -3838,7 +4670,7 @@ dependencies = [ "csv", "encode_unicode", "lazy_static 1.4.0", - "term", + "term 0.5.2", "unicode-width", ] @@ -4329,7 +5161,43 @@ version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" dependencies = [ - "winapi", + "winapi 0.3.9", +] + +[[package]] +name = "reqwest" +version = "0.10.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0718f81a8e14c4dbb3b34cf23dc6aaf9ab8a0dfec160c534b3dbca1aaa21f47c" +dependencies = [ + "base64", + "bytes 0.5.6", + "encoding_rs", + "futures-core", + "futures-util", + "http", + "http-body 0.3.1", + "hyper 0.13.10", + "hyper-tls", + "ipnet", + "js-sys", + "lazy_static 1.4.0", + "log", + "mime", + "mime_guess", + "native-tls", + "percent-encoding", + "pin-project-lite 0.2.7", + "serde 1.0.130", + "serde_json", + "serde_urlencoded", + "tokio 0.2.25", + "tokio-tls", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "winreg", ] [[package]] @@ -4349,7 +5217,7 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "999508abb0ae792aabed2460c45b89106d97fe4adac593bdaef433c2605847b5" dependencies = [ - "bytes", + "bytes 1.0.1", "rustc-hex", ] @@ -4397,6 +5265,12 @@ dependencies = [ "semver 0.9.0", ] +[[package]] +name = "rustversion" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24c8ad4f0c00e1eb5bc7614d236a7f1300e3dbd76b68cac8e06fb00b015ad8d8" + [[package]] name = "rusty-fork" version = "0.3.0" @@ -4449,12 +5323,45 @@ dependencies = [ "syn 1.0.74", ] +[[package]] +name = "schannel" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88d6731146462ea25d9244b2ed5fd1d716d25c52e4d54aa4fb0f3c4e9854dbe2" +dependencies = [ + "lazy_static 1.4.0", + "windows-sys", +] + [[package]] name = "scopeguard" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" +[[package]] +name = "security-framework" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dc14f172faf8a0194a3aded622712b0de276821addc574fa54fc0a1167e10dc" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0160a13a177a45bfb43ce71c01580998474f556ad854dcbca936dd2841a5c556" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "semver" version = "0.9.0" @@ -4578,6 +5485,16 @@ dependencies = [ "serde 1.0.130", ] +[[package]] +name = "serde_regex" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8136f1a4ea815d7eac4101cfd0b16dc0cb5e1fe1b8609dfd728058656b7badf" +dependencies = [ + "regex", + "serde 1.0.130", +] + [[package]] name = "serde_repr" version = "0.1.6" @@ -4589,6 +5506,18 @@ dependencies = [ "syn 1.0.74", ] +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa 1.0.1", + "ryu", + "serde 1.0.130", +] + [[package]] name = "serde_yaml" version = "0.8.17" @@ -4686,7 +5615,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6be9f7d5565b1483af3e72975e2dee33879b3b86bd48c0929fccf6585d79e65a" dependencies = [ "libc", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -4731,6 +5660,12 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0f0242b8e50dd9accdd56170e94ca1ebd223b098eb9c83539a6e367d0f36ae68" +[[package]] +name = "similar" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e24979f63a11545f5f2c60141afe249d4f19f84581ea2138065e400941d83d3" + [[package]] name = "simplelog" version = "0.9.0" @@ -4773,6 +5708,17 @@ dependencies = [ "deunicode", ] +[[package]] +name = "sluice" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d7400c0eff44aa2fcb5e31a5f24ba9716ed90138769e4977a2ba6014ae63eb5" +dependencies = [ + "async-channel", + "futures-core", + "futures-io", +] + [[package]] name = "smallvec" version = "1.7.0" @@ -4791,6 +5737,17 @@ dependencies = [ "structopt 0.3.25", ] +[[package]] +name = "socket2" +version = "0.3.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "122e570113d28d773067fab24266b66753f6ea915758651696b6e35e49f88d6e" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "winapi 0.3.9", +] + [[package]] name = "socket2" version = "0.4.4" @@ -4798,7 +5755,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "66d72b759436ae32898a2af0a14218dbf55efde3feeb170eb623637db85ee1e0" dependencies = [ "libc", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -4827,6 +5784,19 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" +[[package]] +name = "string_cache" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "213494b7a2b503146286049378ce02b482200519accc31872ee8be91fa820a08" +dependencies = [ + "new_debug_unreachable", + "once_cell", + "parking_lot 0.12.1", + "phf_shared", + "precomputed-hash", +] + [[package]] name = "strip-ansi-escapes" version = "0.1.1" @@ -4978,7 +5948,7 @@ dependencies = [ "rand 0.8.4", "redox_syscall 0.2.10", "remove_dir_all", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -5011,7 +5981,18 @@ checksum = "edd106a334b7657c10b7c540a0106114feadeb4dc314513e97df481d5d966f42" dependencies = [ "byteorder", "dirs", - "winapi", + "winapi 0.3.9", +] + +[[package]] +name = "term" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c59df8ac95d96ff9bede18eb7300b0fda5e5d8d90960e76f8e14ae765eedbf1f" +dependencies = [ + "dirs-next", + "rustversion", + "winapi 0.3.9", ] [[package]] @@ -5100,7 +6081,7 @@ checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" dependencies = [ "libc", "wasi 0.10.0+wasi-snapshot-preview1", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -5146,24 +6127,42 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" +[[package]] +name = "tokio" +version = "0.2.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6703a273949a90131b290be1fe7b039d0fc884aa1935860dfcbe056f28cd8092" +dependencies = [ + "bytes 0.5.6", + "fnv", + "futures-core", + "iovec", + "lazy_static 1.4.0", + "memchr", + "mio 0.6.23", + "num_cpus", + "pin-project-lite 0.1.12", + "slab", +] + [[package]] name = "tokio" version = "1.19.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c51a52ed6686dd62c320f9b89299e9dfb46f730c7a48e635c19f21d116cb1439" dependencies = [ - "bytes", + "bytes 1.0.1", "libc", "memchr", "mio 0.8.4", "num_cpus", "once_cell", "parking_lot 0.12.1", - "pin-project-lite", + "pin-project-lite 0.2.7", "signal-hook-registry", - "socket2", + "socket2 0.4.4", "tokio-macros", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -5177,6 +6176,30 @@ dependencies = [ "syn 1.0.74", ] +[[package]] +name = "tokio-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a70f4fcd7b3b24fb194f837560168208f669ca8cb70d0c4b862944452396343" +dependencies = [ + "native-tls", + "tokio 0.2.25", +] + +[[package]] +name = "tokio-util" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be8242891f2b6cbef26a2d7e8605133c2c554cd35b3e4948ea892d6d68436499" +dependencies = [ + "bytes 0.5.6", + "futures-core", + "futures-sink", + "log", + "pin-project-lite 0.1.12", + "tokio 0.2.25", +] + [[package]] name = "toml" version = "0.5.8" @@ -5199,6 +6222,12 @@ dependencies = [ "serde 1.0.130", ] +[[package]] +name = "tower-service" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" + [[package]] name = "tracing" version = "0.1.26" @@ -5206,7 +6235,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09adeb8c97449311ccd28a427f96fb563e7fd31aabf994189879d9da2394b89d" dependencies = [ "cfg-if 1.0.0", - "pin-project-lite", + "log", + "pin-project-lite 0.2.7", "tracing-attributes", "tracing-core", ] @@ -5232,6 +6262,16 @@ dependencies = [ "valuable", ] +[[package]] +name = "tracing-futures" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97d095ae15e245a057c8e8451bab9b3ee1e1f68e9ba2b4fbc18d0ac5237835f2" +dependencies = [ + "pin-project", + "tracing", +] + [[package]] name = "tracing-log" version = "0.1.2" @@ -5271,6 +6311,12 @@ dependencies = [ "rlp", ] +[[package]] +name = "try-lock" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" + [[package]] name = "trybuild" version = "1.0.53" @@ -5397,6 +6443,15 @@ dependencies = [ "unic-common", ] +[[package]] +name = "unicase" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6" +dependencies = [ + "version_check", +] + [[package]] name = "unicode-bidi" version = "0.3.4" @@ -5480,6 +6535,16 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" +[[package]] +name = "value-bag" +version = "1.0.0-alpha.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2209b78d1249f7e6f3293657c9779fe31ced465df091bbd433a1cf88e916ec55" +dependencies = [ + "ctor", + "version_check", +] + [[package]] name = "variant_count" version = "1.1.0" @@ -5490,6 +6555,12 @@ dependencies = [ "syn 1.0.74", ] +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + [[package]] name = "vec_map" version = "0.8.2" @@ -5532,6 +6603,12 @@ dependencies = [ "libc", ] +[[package]] +name = "waker-fn" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d5b2c62b4012a3e1eca5a7e077d13b3bf498c4073e33ccd58626607748ceeca" + [[package]] name = "walkdir" version = "2.3.2" @@ -5539,10 +6616,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "808cf2735cd4b6866113f648b791c6adc5714537bc222d9347bb203386ffda56" dependencies = [ "same-file", - "winapi", + "winapi 0.3.9", "winapi-util", ] +[[package]] +name = "want" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" +dependencies = [ + "log", + "try-lock", +] + [[package]] name = "wasi" version = "0.9.0+wasi-snapshot-preview1" @@ -5568,6 +6655,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ee1280240b7c461d6a0071313e08f34a60b0365f14260362e5a2b17d1d31aa7" dependencies = [ "cfg-if 1.0.0", + "serde 1.0.130", + "serde_json", "wasm-bindgen-macro", ] @@ -5586,6 +6675,18 @@ dependencies = [ "wasm-bindgen-shared", ] +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e67a5806118af01f0d9045915676b22aaebecf4178ae7021bc171dab0b897ab" +dependencies = [ + "cfg-if 1.0.0", + "js-sys", + "wasm-bindgen", + "web-sys", +] + [[package]] name = "wasm-bindgen-macro" version = "0.2.71" @@ -5625,12 +6726,27 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "wepoll-ffi" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d743fdedc5c64377b5fc2bc036b01c7fd642205a0d96356034ae3404d49eb7fb" +dependencies = [ + "cc", +] + [[package]] name = "widestring" version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c168940144dd21fd8046987c16a46a33d5fc84eec29ef9dcddc2ac9e31526b7c" +[[package]] +name = "winapi" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" + [[package]] name = "winapi" version = "0.3.9" @@ -5641,6 +6757,12 @@ dependencies = [ "winapi-x86_64-pc-windows-gnu", ] +[[package]] +name = "winapi-build" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" + [[package]] name = "winapi-i686-pc-windows-gnu" version = "0.4.0" @@ -5653,7 +6775,7 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" dependencies = [ - "winapi", + "winapi 0.3.9", ] [[package]] @@ -5705,6 +6827,25 @@ version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" +[[package]] +name = "winreg" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0120db82e8a1e0b9fb3345a539c478767c0048d842860994d96113d5b667bd69" +dependencies = [ + "winapi 0.3.9", +] + +[[package]] +name = "ws2_32-sys" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e" +dependencies = [ + "winapi 0.2.8", + "winapi-build", +] + [[package]] name = "wyz" version = "0.2.0" diff --git a/language/move-command-line-common/src/movey.rs b/language/move-command-line-common/src/movey.rs deleted file mode 100644 index 2308ed33cf..0000000000 --- a/language/move-command-line-common/src/movey.rs +++ /dev/null @@ -1,8 +0,0 @@ -// Copyright (c) The Diem Core Contributors -// Copyright (c) The Move Contributors -// SPDX-License-Identifier: Apache-2.0 - -#[cfg(debug_assertions)] -pub const MOVEY_URL: &str = "https://movey-app-staging.herokuapp.com"; -#[cfg(not(debug_assertions))] -pub const MOVEY_URL: &str = "https://www.movey.net"; diff --git a/language/tools/move-cli/src/utils/movey_credential.rs b/language/tools/move-cli/src/utils/movey_credential.rs index b0cd313059..bb9700ad9b 100644 --- a/language/tools/move-cli/src/utils/movey_credential.rs +++ b/language/tools/move-cli/src/utils/movey_credential.rs @@ -3,7 +3,7 @@ // SPDX-License-Identifier: Apache-2.0 use anyhow::{bail, Context, Result}; -use move_command_line_common::movey::MOVEY_URL; +use move_command_line_common::movey_constants::MOVEY_URL; use std::fs; use toml_edit::easy::Value; From 9680b912e57eaa3a067fbc06d828e11a01b87d42 Mon Sep 17 00:00:00 2001 From: ea-open-source Date: Tue, 2 Aug 2022 17:41:31 +0700 Subject: [PATCH 17/22] Change movey api url, refactor getting credential key, refactor tests --- language/tools/move-cli/Cargo.toml | 2 +- .../tools/move-cli/src/base/movey_upload.rs | 19 +++--- .../move-cli/src/utils/movey_credential.rs | 50 +++++++------- language/tools/move-cli/tests/cli_tests.rs | 67 ++++++++----------- 4 files changed, 60 insertions(+), 78 deletions(-) diff --git a/language/tools/move-cli/Cargo.toml b/language/tools/move-cli/Cargo.toml index c8e7897e15..bc83397d64 100644 --- a/language/tools/move-cli/Cargo.toml +++ b/language/tools/move-cli/Cargo.toml @@ -23,6 +23,7 @@ codespan-reporting = "0.11.1" itertools = "0.10.0" serde_json = "1.0" toml_edit = { version = "0.14.3", features = ["easy"] } +reqwest = { version = "0.10", features = ["blocking", "json"] } bcs = "0.1.2" move-bytecode-verifier = { path = "../../move-bytecode-verifier" } @@ -49,7 +50,6 @@ move-unit-test = { path = "../move-unit-test" } move-errmapgen = { path = "../../move-prover/move-errmapgen" } move-bytecode-source-map = { path = "../../move-ir-compiler/move-bytecode-source-map" } move-bytecode-viewer = { path = "../move-bytecode-viewer" } -reqwest = { version = "0.10", features = ["blocking", "json"] } [dev-dependencies] datatest-stable = "0.1.1" diff --git a/language/tools/move-cli/src/base/movey_upload.rs b/language/tools/move-cli/src/base/movey_upload.rs index 7a4e33692c..1d4ed5659c 100644 --- a/language/tools/move-cli/src/base/movey_upload.rs +++ b/language/tools/move-cli/src/base/movey_upload.rs @@ -1,15 +1,12 @@ // Copyright (c) The Move Contributors // SPDX-License-Identifier: Apache-2.0 -use std::{env, fs::File, path::PathBuf, process::Command}; - +use crate::utils::movey_credential; use anyhow::bail; use clap::*; -use reqwest::blocking::Client; - use move_command_line_common::env::MOVE_HOME; - -use crate::utils::movey_credential; +use reqwest::blocking::Client; +use std::{env, fs::File, path::PathBuf, process::Command}; #[derive(serde::Serialize, Default)] pub struct MoveyUploadRequest { @@ -104,7 +101,7 @@ impl MoveyUpload { Ok(url) => { let client = Client::new(); let response = client - .post(&format!("{}/api/v1/post_package/", &url)) + .post(&format!("{}/api/v1/packages/register", &url)) .json(&movey_upload_request) .send(); match response { @@ -112,17 +109,17 @@ impl MoveyUpload { if response.status().is_success() { println!("Your package has been successfully uploaded to Movey") } else if response.status().is_client_error() { - bail!("Error: {}", response.text()?) + bail!("{}", response.text()?) } else if response.status().is_server_error() { - bail!("Error: An unexpected error occurred. Please try again later"); + bail!("An unexpected error occurred. Please try again later"); } } Err(_) => { - bail!("Error: An unexpected error occurred. Please try again later"); + bail!("An unexpected error occurred. Please try again later"); } } } - Err(_) => bail!("Error: An unexpected error occurred. Please try again later"), + Err(_) => bail!("An unexpected error occurred. Please try again later"), } Ok(()) } diff --git a/language/tools/move-cli/src/utils/movey_credential.rs b/language/tools/move-cli/src/utils/movey_credential.rs index bb9700ad9b..77f5012e18 100644 --- a/language/tools/move-cli/src/utils/movey_credential.rs +++ b/language/tools/move-cli/src/utils/movey_credential.rs @@ -7,7 +7,7 @@ use move_command_line_common::movey_constants::MOVEY_URL; use std::fs; use toml_edit::easy::Value; -pub const MOVEY_API_KEY_PATH: &str = "/movey_credential.toml"; +pub const MOVEY_CREDENTIAL_PATH: &str = "/movey_credential.toml"; pub fn get_registry_api_token(move_home: &str) -> Result { if let Ok(content) = get_api_token(&move_home) { @@ -20,44 +20,42 @@ pub fn get_registry_api_token(move_home: &str) -> Result { } } -fn get_api_token(move_home: &str) -> Result { - let credential_path = format!("{}{}", move_home, MOVEY_API_KEY_PATH); - +pub fn get_api_token(move_home: &str) -> Result { + let credential_path = format!("{}{}", move_home, MOVEY_CREDENTIAL_PATH); let contents = fs::read_to_string(&credential_path)?; let mut toml: Value = contents.parse()?; - let registry = toml - .as_table_mut() - .context(format!("Error parsing {}", MOVEY_API_KEY_PATH))? - .get_mut("registry") - .context(format!("Error parsing {}", MOVEY_API_KEY_PATH))?; - let token = registry - .as_table_mut() - .context("Error parsing token")? - .get_mut("token") - .context("Error parsing token")?; + + let token = get_registry_field(&mut toml, "token")?; Ok(token.to_string().replace("\"", "")) } pub fn get_movey_url(move_home: &str) -> Result { - let credential_path = format!("{}{}", move_home, MOVEY_API_KEY_PATH); + let credential_path = format!("{}{}", move_home, MOVEY_CREDENTIAL_PATH); let contents = fs::read_to_string(&credential_path)?; let mut toml: Value = contents.parse()?; - let registry = toml - .as_table_mut() - .context(format!("Error parsing {}", MOVEY_API_KEY_PATH))? - .get_mut("registry") - .context(format!("Error parsing {}", MOVEY_API_KEY_PATH))?; - let movey_url = registry - .as_table_mut() - .context("Error parsing url")? - .get_mut("url"); - if let Some(url) = movey_url { + + let movey_url = get_registry_field(&mut toml, "url"); + if let Ok(url) = movey_url { Ok(url.to_string().replace("\"", "")) } else { Ok(MOVEY_URL.to_string()) } } +fn get_registry_field<'a>(toml: &'a mut Value, field: &'a str) -> Result<&'a mut Value> { + let registry = toml + .as_table_mut() + .context(format!("Error parsing {}", MOVEY_CREDENTIAL_PATH))? + .get_mut("registry") + .context(format!("Error parsing {}", MOVEY_CREDENTIAL_PATH))?; + let value = registry + .as_table_mut() + .context("Error parsing registry table")? + .get_mut(field) + .context("Error parsing token")?; + Ok(value) +} + #[cfg(test)] mod tests { use super::*; @@ -67,7 +65,7 @@ mod tests { let cwd = env::current_dir().unwrap(); let mut move_home: String = String::from(cwd.to_string_lossy()); move_home.push_str(&test_path); - let credential_path = move_home.clone() + MOVEY_API_KEY_PATH; + let credential_path = move_home.clone() + MOVEY_CREDENTIAL_PATH; (move_home, credential_path) } diff --git a/language/tools/move-cli/tests/cli_tests.rs b/language/tools/move-cli/tests/cli_tests.rs index a7201f9bc0..682f6d0898 100644 --- a/language/tools/move-cli/tests/cli_tests.rs +++ b/language/tools/move-cli/tests/cli_tests.rs @@ -74,18 +74,7 @@ fn upload_package_to_movey_works() { let package_path = format!("{}/valid_package1", UPLOAD_PACKAGE_PATH); init_git(&package_path, true); let server = MockServer::start(); - server.mock(|when, then| { - when.method(POST) - .path("/api/v1/post_package/") - .header("content-type", "application/json") - .json_body(json!({ - "github_repo_url":"https://github.com/move-language/move", - "total_files":2, - "token":"test-token", - "subdir":"\n" - })); - then.status(200); - }); + let server_mock = init_server_mock(&server, 200, None); init_stub_registry_file(&package_path, &server.base_url()); let relative_package_path = PathBuf::from(&package_path); let absolute_package_path = @@ -99,6 +88,7 @@ fn upload_package_to_movey_works() { .output() .unwrap(); + server_mock.assert(); assert!(output.status.success()); let output = String::from_utf8_lossy(output.stdout.as_slice()).to_string(); assert!( @@ -114,20 +104,8 @@ fn upload_package_to_movey_works() { fn upload_package_to_movey_prints_error_message_if_server_respond_4xx() { let package_path = format!("{}/valid_package2", UPLOAD_PACKAGE_PATH); init_git(&package_path, true); - let server = MockServer::start(); - server.mock(|when, then| { - when.method(POST) - .path("/api/v1/post_package/") - .header("content-type", "application/json") - .json_body(json!({ - "github_repo_url":"https://github.com/move-language/move", - "total_files":2, - "token":"test-token", - "subdir":"\n" - })); - then.status(400).body("Invalid Api token"); - }); + let server_mock = init_server_mock(&server, 400, Some("Invalid Api token")); init_stub_registry_file(&package_path, &server.base_url()); let relative_package_path = PathBuf::from(&package_path); let absolute_package_path = @@ -141,6 +119,7 @@ fn upload_package_to_movey_prints_error_message_if_server_respond_4xx() { .output() .unwrap(); + server_mock.assert(); assert!(!output.status.success()); let output = String::from_utf8_lossy(output.stderr.as_slice()).to_string(); assert!(output.contains("Error: Invalid Api token"), "{}", output); @@ -152,20 +131,8 @@ fn upload_package_to_movey_prints_error_message_if_server_respond_4xx() { fn upload_package_to_movey_prints_hardcoded_error_message_if_server_respond_5xx() { let package_path = format!("{}/valid_package3", UPLOAD_PACKAGE_PATH); init_git(&package_path, true); - let server = MockServer::start(); - server.mock(|when, then| { - when.method(POST) - .path("/api/v1/post_package/") - .header("content-type", "application/json") - .json_body(json!({ - "github_repo_url":"https://github.com/move-language/move", - "total_files":2, - "token":"test-token", - "subdir":"\n" - })); - then.status(500).body("Invalid Api token"); - }); + let server_mock = init_server_mock(&server, 500, Some("Invalid Api token")); init_stub_registry_file(&package_path, &server.base_url()); let relative_package_path = PathBuf::from(&package_path); let absolute_package_path = @@ -179,6 +146,7 @@ fn upload_package_to_movey_prints_hardcoded_error_message_if_server_respond_5xx( .output() .unwrap(); + server_mock.assert(); assert!(!output.status.success()); let output = String::from_utf8_lossy(output.stderr.as_slice()).to_string(); assert!( @@ -367,12 +335,12 @@ fn clean_up(move_home: &str) { fn clean_up(package_path: &str) { let _ = fs::remove_file(format!("{}/simple_file", package_path)); fs::remove_dir_all(format!("{}/.git", package_path)).unwrap(); - let credential_path = format!("{}{}", package_path, MOVEY_API_KEY_PATH); + let credential_path = format!("{}{}", package_path, MOVEY_CREDENTIAL_PATH); let _ = fs::remove_file(&credential_path); } fn init_stub_registry_file(package_path: &str, base_url: &str) { - let credential_path = format!("{}{}", package_path, MOVEY_API_KEY_PATH); + let credential_path = format!("{}{}", package_path, MOVEY_CREDENTIAL_PATH); let content = format!( r#" [registry] @@ -383,3 +351,22 @@ fn init_stub_registry_file(package_path: &str, base_url: &str) { ); fs::write(credential_path, content).expect("Unable to write file"); } + +fn init_server_mock<'a>( + server: &'a MockServer, + status_code: u16, + response_body: Option<&str>, +) -> Mock<'a> { + server.mock(|when, then| { + when.method(POST) + .path("/api/v1/packages/register") + .header("content-type", "application/json") + .json_body(json!({ + "github_repo_url": "https://github.com/move-language/move", + "total_files": 2, + "token": "test-token", + "subdir": "\n" + })); + then.status(status_code).body(response_body.unwrap_or("")); + }) +} From 41d429874023ea0b3a2bbf21b455ac621e0fa59c Mon Sep 17 00:00:00 2001 From: ea-open-source Date: Fri, 5 Aug 2022 15:14:22 +0700 Subject: [PATCH 18/22] Rename movey api, change the message of successful upload request --- language/tools/move-cli/src/base/movey_upload.rs | 8 ++++++-- language/tools/move-cli/tests/cli_tests.rs | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/language/tools/move-cli/src/base/movey_upload.rs b/language/tools/move-cli/src/base/movey_upload.rs index 1d4ed5659c..24c1d07987 100644 --- a/language/tools/move-cli/src/base/movey_upload.rs +++ b/language/tools/move-cli/src/base/movey_upload.rs @@ -101,13 +101,17 @@ impl MoveyUpload { Ok(url) => { let client = Client::new(); let response = client - .post(&format!("{}/api/v1/packages/register", &url)) + .post(&format!("{}/api/v1/packages/upload", &url)) .json(&movey_upload_request) .send(); match response { Ok(response) => { if response.status().is_success() { - println!("Your package has been successfully uploaded to Movey") + println!( + "Your package has been successfully uploaded to Movey at {}/packages/{}", + url, + response.text()? + ); } else if response.status().is_client_error() { bail!("{}", response.text()?) } else if response.status().is_server_error() { diff --git a/language/tools/move-cli/tests/cli_tests.rs b/language/tools/move-cli/tests/cli_tests.rs index 682f6d0898..9e973462e3 100644 --- a/language/tools/move-cli/tests/cli_tests.rs +++ b/language/tools/move-cli/tests/cli_tests.rs @@ -359,7 +359,7 @@ fn init_server_mock<'a>( ) -> Mock<'a> { server.mock(|when, then| { when.method(POST) - .path("/api/v1/packages/register") + .path("/api/v1/packages/upload") .header("content-type", "application/json") .json_body(json!({ "github_repo_url": "https://github.com/move-language/move", From 6fd45f53995f4dcca0208a5305c50d9d346649d6 Mon Sep 17 00:00:00 2001 From: ea-open-source Date: Mon, 8 Aug 2022 16:55:02 +0700 Subject: [PATCH 19/22] Refactor and add comments for movey tests --- .../tools/move-cli/src/base/movey_upload.rs | 24 +++++++++++-------- language/tools/move-cli/tests/cli_tests.rs | 2 ++ 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/language/tools/move-cli/src/base/movey_upload.rs b/language/tools/move-cli/src/base/movey_upload.rs index 24c1d07987..5393e571ad 100644 --- a/language/tools/move-cli/src/base/movey_upload.rs +++ b/language/tools/move-cli/src/base/movey_upload.rs @@ -8,6 +8,7 @@ use move_command_line_common::env::MOVE_HOME; use reqwest::blocking::Client; use std::{env, fs::File, path::PathBuf, process::Command}; +// Metadata that will be collected by Movey #[derive(serde::Serialize, Default)] pub struct MoveyUploadRequest { github_repo_url: String, @@ -40,6 +41,7 @@ impl MoveyUpload { bail!("Move.toml not found") } + // use git command to get the repository url let mut movey_upload_request: MoveyUploadRequest = Default::default(); let mut output = Command::new("git") .current_dir(".") @@ -59,19 +61,20 @@ impl MoveyUpload { bail!("invalid remote url") } // convert ssh url to https - if tokens[1].starts_with("git@github.com") { - let https_url = tokens[1] - .replace(":", "/") - .replace("git@", "https://") - .replace(".git", ""); - movey_upload_request.github_repo_url = https_url; - break; - } - movey_upload_request.github_repo_url = String::from(tokens[1]); - break; + let https_url = if tokens[1].starts_with("git@github.com") { + tokens[1].replace(":", "/").replace("git@", "https://") + } else { + String::from(tokens[1]) + }; + movey_upload_request.github_repo_url = if https_url.ends_with(".git") { + https_url[..https_url.len() - 4].to_string() + } else { + https_url + }; } } + // use git command to get the subdir if move package is not on the top level output = Command::new("git") .current_dir(".") .args(&["rev-parse", "--show-prefix"]) @@ -80,6 +83,7 @@ impl MoveyUpload { let subdir = String::from_utf8_lossy(output.stdout.as_slice()); movey_upload_request.subdir = String::from(subdir); + // use git command to count total files output = Command::new("git") .current_dir(".") .args(&["ls-files"]) diff --git a/language/tools/move-cli/tests/cli_tests.rs b/language/tools/move-cli/tests/cli_tests.rs index 9e973462e3..cdd8a1ac57 100644 --- a/language/tools/move-cli/tests/cli_tests.rs +++ b/language/tools/move-cli/tests/cli_tests.rs @@ -339,6 +339,7 @@ fn clean_up(package_path: &str) { let _ = fs::remove_file(&credential_path); } +// create a dummy move_credential.toml file for testing fn init_stub_registry_file(package_path: &str, base_url: &str) { let credential_path = format!("{}{}", package_path, MOVEY_CREDENTIAL_PATH); let content = format!( @@ -352,6 +353,7 @@ fn init_stub_registry_file(package_path: &str, base_url: &str) { fs::write(credential_path, content).expect("Unable to write file"); } +// create a mock server to check if the request is sent or not, also returns a stub response for testing fn init_server_mock<'a>( server: &'a MockServer, status_code: u16, From 190f3a2ca9315a21ef1f5fd6ac222fb0c3aa8ccd Mon Sep 17 00:00:00 2001 From: ea-open-source Date: Tue, 9 Aug 2022 16:28:37 +0700 Subject: [PATCH 20/22] Refactor and rebase according to #226 changes --- Cargo.lock | 2 +- language/move-command-line-common/Cargo.toml | 1 - .../tools/move-cli/src/base/movey_upload.rs | 2 +- language/tools/move-cli/src/lib.rs | 3 +- language/tools/move-cli/tests/cli_tests.rs | 39 ++++++++----------- 5 files changed, 20 insertions(+), 27 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 402d8c8667..c494257cab 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -836,7 +836,7 @@ version = "4.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a604e93b79d1808327a6fca85a6f2d69de66461e7620f5a4cbf5fb4d1d7c948" dependencies = [ - "bytes", + "bytes 1.0.1", "memchr", ] diff --git a/language/move-command-line-common/Cargo.toml b/language/move-command-line-common/Cargo.toml index 5ac0d36668..4fb12ae3a1 100644 --- a/language/move-command-line-common/Cargo.toml +++ b/language/move-command-line-common/Cargo.toml @@ -12,7 +12,6 @@ edition = "2021" [dependencies] anyhow = "1.0.52" difference = "2.0.0" -dirs-next = "2.0.0" walkdir = "2.3.1" sha2 = "0.9.3" hex = "0.4.3" diff --git a/language/tools/move-cli/src/base/movey_upload.rs b/language/tools/move-cli/src/base/movey_upload.rs index 5393e571ad..2c9dadb437 100644 --- a/language/tools/move-cli/src/base/movey_upload.rs +++ b/language/tools/move-cli/src/base/movey_upload.rs @@ -112,7 +112,7 @@ impl MoveyUpload { Ok(response) => { if response.status().is_success() { println!( - "Your package has been successfully uploaded to Movey at {}/packages/{}", + "Your package has been successfully uploaded to Movey at {}/packages/{}.", url, response.text()? ); diff --git a/language/tools/move-cli/src/lib.rs b/language/tools/move-cli/src/lib.rs index cf46066b57..7bea681310 100644 --- a/language/tools/move-cli/src/lib.rs +++ b/language/tools/move-cli/src/lib.rs @@ -4,7 +4,8 @@ use base::{ build::Build, coverage::Coverage, disassemble::Disassemble, docgen::Docgen, errmap::Errmap, - info::Info, movey_login::MoveyLogin, movey_upload::MoveyUpload, new::New, prove::Prove, test::Test, + info::Info, movey_login::MoveyLogin, movey_upload::MoveyUpload, new::New, prove::Prove, + test::Test, }; use move_package::BuildConfig; diff --git a/language/tools/move-cli/tests/cli_tests.rs b/language/tools/move-cli/tests/cli_tests.rs index cdd8a1ac57..82f917f3b1 100644 --- a/language/tools/move-cli/tests/cli_tests.rs +++ b/language/tools/move-cli/tests/cli_tests.rs @@ -2,22 +2,21 @@ // Copyright (c) The Move Contributors // SPDX-License-Identifier: Apache-2.0 -use move_cli::sandbox::commands::test; -use std::fs::{self, File}; -use std::io::Write; -use move_cli::sandbox::commands::test; +use httpmock::{prelude::*, Mock}; use move_cli::{base::movey_login::MOVEY_CREDENTIAL_PATH, sandbox::commands::test}; -use move_command_line_common::movey_constants::MOVEY_URL; +use move_command_line_common::{files, movey_constants::MOVEY_URL}; +use serde_json::json; #[cfg(unix)] use std::fs::File; -use std::{env, fs, io::Write}; - -use std::path::PathBuf; #[cfg(unix)] use std::os::unix::fs::PermissionsExt; -use std::{path::PathBuf, process::Stdio}; +use std::{ + env, fs, + io::Write, + path::PathBuf, + process::{Command, Stdio}, +}; use toml_edit::easy::Value; -use std::process::Command; pub const CLI_METATEST_PATH: [&str; 3] = ["tests", "metatests", "args.txt"]; @@ -78,7 +77,7 @@ fn upload_package_to_movey_works() { init_stub_registry_file(&package_path, &server.base_url()); let relative_package_path = PathBuf::from(&package_path); let absolute_package_path = - path_to_string(&relative_package_path.canonicalize().unwrap()).unwrap(); + files::path_to_string(&relative_package_path.canonicalize().unwrap()).unwrap(); let cli_exe = env!("CARGO_BIN_EXE_move"); let output = Command::new(cli_exe) @@ -109,7 +108,7 @@ fn upload_package_to_movey_prints_error_message_if_server_respond_4xx() { init_stub_registry_file(&package_path, &server.base_url()); let relative_package_path = PathBuf::from(&package_path); let absolute_package_path = - path_to_string(&relative_package_path.canonicalize().unwrap()).unwrap(); + files::path_to_string(&relative_package_path.canonicalize().unwrap()).unwrap(); let cli_exe = env!("CARGO_BIN_EXE_move"); let output = Command::new(cli_exe) @@ -136,7 +135,7 @@ fn upload_package_to_movey_prints_hardcoded_error_message_if_server_respond_5xx( init_stub_registry_file(&package_path, &server.base_url()); let relative_package_path = PathBuf::from(&package_path); let absolute_package_path = - path_to_string(&relative_package_path.canonicalize().unwrap()).unwrap(); + files::path_to_string(&relative_package_path.canonicalize().unwrap()).unwrap(); let cli_exe = env!("CARGO_BIN_EXE_move"); let output = Command::new(cli_exe) @@ -201,8 +200,6 @@ fn init_git(package_path: &str, is_valid: bool) { ]) .output() .unwrap(); - } - if flag != 2 { Command::new("git") .current_dir(package_path) .args(&["config", "user.email", "\"you@example.com\""]) @@ -219,13 +216,14 @@ fn init_git(package_path: &str, is_valid: bool) { .output() .unwrap(); } +} #[test] fn save_credential_works() { let cli_exe = env!("CARGO_BIN_EXE_move"); let (move_home, credential_path) = setup_move_home("/save_credential_works"); assert!(fs::read_to_string(&credential_path).is_err()); - match std::process::Command::new(cli_exe) + match Command::new(cli_exe) .env("MOVE_HOME", &move_home) .current_dir(".") .args(["movey-login"]) @@ -262,7 +260,7 @@ fn save_credential_works() { let token = registry.as_table_mut().unwrap().get_mut("token").unwrap(); assert!(token.to_string().contains("test_token")); - clean_up(&move_home) + let _ = fs::remove_dir_all(move_home); } #[cfg(unix)] @@ -315,7 +313,7 @@ fn save_credential_fails_if_undeletable_credential_file_exists() { file.set_permissions(perms).unwrap(); let _ = fs::remove_file(&credential_path); - clean_up(&move_home) + let _ = fs::remove_dir_all(move_home); } fn setup_move_home(test_path: &str) -> (String, String) { @@ -328,12 +326,7 @@ fn setup_move_home(test_path: &str) -> (String, String) { (move_home, credential_path) } -fn clean_up(move_home: &str) { - let _ = fs::remove_dir_all(move_home); -} - fn clean_up(package_path: &str) { - let _ = fs::remove_file(format!("{}/simple_file", package_path)); fs::remove_dir_all(format!("{}/.git", package_path)).unwrap(); let credential_path = format!("{}{}", package_path, MOVEY_CREDENTIAL_PATH); let _ = fs::remove_file(&credential_path); From 7a632835bbb91662f807c64f0ce8b84419589202 Mon Sep 17 00:00:00 2001 From: ea-open-source Date: Wed, 10 Aug 2022 14:40:18 +0700 Subject: [PATCH 21/22] Refactor mock movey server function, remove unnecessary license - change `init_server_mock` to `mock_movey_server_with_response_body_and_status_code` to be more inline with the comment - remove `// Copyright (c) The Diem Core Contributors` --- language/tools/move-cli/src/utils/mod.rs | 1 - .../move-cli/src/utils/movey_credential.rs | 1 - language/tools/move-cli/tests/cli_tests.rs | 17 ++++++++++++----- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/language/tools/move-cli/src/utils/mod.rs b/language/tools/move-cli/src/utils/mod.rs index 343ff840f5..e304f0120b 100644 --- a/language/tools/move-cli/src/utils/mod.rs +++ b/language/tools/move-cli/src/utils/mod.rs @@ -1,4 +1,3 @@ -// Copyright (c) The Diem Core Contributors // Copyright (c) The Move Contributors // SPDX-License-Identifier: Apache-2.0 diff --git a/language/tools/move-cli/src/utils/movey_credential.rs b/language/tools/move-cli/src/utils/movey_credential.rs index 77f5012e18..ef8ff8f943 100644 --- a/language/tools/move-cli/src/utils/movey_credential.rs +++ b/language/tools/move-cli/src/utils/movey_credential.rs @@ -1,4 +1,3 @@ -// Copyright (c) The Diem Core Contributors // Copyright (c) The Move Contributors // SPDX-License-Identifier: Apache-2.0 diff --git a/language/tools/move-cli/tests/cli_tests.rs b/language/tools/move-cli/tests/cli_tests.rs index 82f917f3b1..bf536ab916 100644 --- a/language/tools/move-cli/tests/cli_tests.rs +++ b/language/tools/move-cli/tests/cli_tests.rs @@ -67,13 +67,12 @@ fn cross_process_locking_git_deps() { } const UPLOAD_PACKAGE_PATH: &str = "./tests/upload_tests"; - #[test] fn upload_package_to_movey_works() { let package_path = format!("{}/valid_package1", UPLOAD_PACKAGE_PATH); init_git(&package_path, true); let server = MockServer::start(); - let server_mock = init_server_mock(&server, 200, None); + let server_mock = mock_movey_upload_with_response_body_and_status_code(&server, 200, None); init_stub_registry_file(&package_path, &server.base_url()); let relative_package_path = PathBuf::from(&package_path); let absolute_package_path = @@ -104,7 +103,11 @@ fn upload_package_to_movey_prints_error_message_if_server_respond_4xx() { let package_path = format!("{}/valid_package2", UPLOAD_PACKAGE_PATH); init_git(&package_path, true); let server = MockServer::start(); - let server_mock = init_server_mock(&server, 400, Some("Invalid Api token")); + let server_mock = mock_movey_upload_with_response_body_and_status_code( + &server, + 400, + Some("Invalid Api token"), + ); init_stub_registry_file(&package_path, &server.base_url()); let relative_package_path = PathBuf::from(&package_path); let absolute_package_path = @@ -131,7 +134,11 @@ fn upload_package_to_movey_prints_hardcoded_error_message_if_server_respond_5xx( let package_path = format!("{}/valid_package3", UPLOAD_PACKAGE_PATH); init_git(&package_path, true); let server = MockServer::start(); - let server_mock = init_server_mock(&server, 500, Some("Invalid Api token")); + let server_mock = mock_movey_upload_with_response_body_and_status_code( + &server, + 500, + Some("Invalid Api token"), + ); init_stub_registry_file(&package_path, &server.base_url()); let relative_package_path = PathBuf::from(&package_path); let absolute_package_path = @@ -347,7 +354,7 @@ fn init_stub_registry_file(package_path: &str, base_url: &str) { } // create a mock server to check if the request is sent or not, also returns a stub response for testing -fn init_server_mock<'a>( +fn mock_movey_upload_with_response_body_and_status_code<'a>( server: &'a MockServer, status_code: u16, response_body: Option<&str>, From e94be27dcf78d2b1b2551fd3443798720b2b98a0 Mon Sep 17 00:00:00 2001 From: ea-open-source Date: Thu, 11 Aug 2022 23:15:55 +0700 Subject: [PATCH 22/22] Move `MOVEY_CREDENTIAL_PATH` to common package, refactor logic of reading credential file --- .../src/movey_constants.rs | 1 + .../tools/move-cli/src/base/movey_login.rs | 23 +++++-------------- .../move-cli/src/utils/movey_credential.rs | 21 ++++++++++++----- language/tools/move-cli/tests/cli_tests.rs | 7 ++++-- 4 files changed, 27 insertions(+), 25 deletions(-) diff --git a/language/move-command-line-common/src/movey_constants.rs b/language/move-command-line-common/src/movey_constants.rs index 4567bdbf4d..de98638301 100644 --- a/language/move-command-line-common/src/movey_constants.rs +++ b/language/move-command-line-common/src/movey_constants.rs @@ -5,3 +5,4 @@ pub const MOVEY_URL: &str = "https://movey-app-staging.herokuapp.com"; #[cfg(not(debug_assertions))] pub const MOVEY_URL: &str = "https://www.movey.net"; +pub const MOVEY_CREDENTIAL_PATH: &str = "/movey_credential.toml"; diff --git a/language/tools/move-cli/src/base/movey_login.rs b/language/tools/move-cli/src/base/movey_login.rs index 214f5ae9c6..6fd3c8313f 100644 --- a/language/tools/move-cli/src/base/movey_login.rs +++ b/language/tools/move-cli/src/base/movey_login.rs @@ -1,14 +1,16 @@ // Copyright (c) The Move Contributors // SPDX-License-Identifier: Apache-2.0 +use crate::utils::movey_credential::read_credential_file; use anyhow::{bail, Result}; use clap::Parser; -use move_command_line_common::{env::MOVE_HOME, movey_constants::MOVEY_URL}; +use move_command_line_common::{ + env::MOVE_HOME, + movey_constants::{MOVEY_CREDENTIAL_PATH, MOVEY_URL}, +}; use std::{fs, fs::File, io, path::PathBuf}; use toml_edit::easy::{map::Map, Value}; -pub const MOVEY_CREDENTIAL_PATH: &str = "/movey_credential.toml"; - #[derive(Parser)] #[clap(name = "movey-login")] pub struct MoveyLogin; @@ -47,20 +49,7 @@ impl MoveyLogin { create_credential_file(&credential_path)?; } - let old_contents: String; - match fs::read_to_string(&credential_path) { - Ok(contents) => { - old_contents = contents; - } - Err(error) => bail!("Error reading input: {}", error), - } - let mut toml: Value = old_contents.parse().map_err(|e| { - anyhow::Error::from(e).context(format!( - "could not parse input at {} as TOML", - &credential_path - )) - })?; - + let mut toml: Value = read_credential_file(&credential_path)?; // only update token key, keep the rest of the file intact if let Some(registry) = toml.as_table_mut().unwrap().get_mut("registry") { if let Some(toml_token) = registry.as_table_mut().unwrap().get_mut("token") { diff --git a/language/tools/move-cli/src/utils/movey_credential.rs b/language/tools/move-cli/src/utils/movey_credential.rs index ef8ff8f943..f18bcdda13 100644 --- a/language/tools/move-cli/src/utils/movey_credential.rs +++ b/language/tools/move-cli/src/utils/movey_credential.rs @@ -2,12 +2,10 @@ // SPDX-License-Identifier: Apache-2.0 use anyhow::{bail, Context, Result}; -use move_command_line_common::movey_constants::MOVEY_URL; +use move_command_line_common::movey_constants::{MOVEY_CREDENTIAL_PATH, MOVEY_URL}; use std::fs; use toml_edit::easy::Value; -pub const MOVEY_CREDENTIAL_PATH: &str = "/movey_credential.toml"; - pub fn get_registry_api_token(move_home: &str) -> Result { if let Ok(content) = get_api_token(&move_home) { Ok(content) @@ -21,9 +19,7 @@ pub fn get_registry_api_token(move_home: &str) -> Result { pub fn get_api_token(move_home: &str) -> Result { let credential_path = format!("{}{}", move_home, MOVEY_CREDENTIAL_PATH); - let contents = fs::read_to_string(&credential_path)?; - let mut toml: Value = contents.parse()?; - + let mut toml: Value = read_credential_file(&credential_path)?; let token = get_registry_field(&mut toml, "token")?; Ok(token.to_string().replace("\"", "")) } @@ -55,6 +51,19 @@ fn get_registry_field<'a>(toml: &'a mut Value, field: &'a str) -> Result<&'a mut Ok(value) } +pub fn read_credential_file(credential_path: &str) -> Result { + let content = match fs::read_to_string(&credential_path) { + Ok(content) => content, + Err(error) => bail!("Error reading input: {}", error), + }; + content.parse().map_err(|e| { + anyhow::Error::from(e).context(format!( + "could not parse input at {} as TOML", + &credential_path + )) + }) +} + #[cfg(test)] mod tests { use super::*; diff --git a/language/tools/move-cli/tests/cli_tests.rs b/language/tools/move-cli/tests/cli_tests.rs index bf536ab916..3d901a9d3d 100644 --- a/language/tools/move-cli/tests/cli_tests.rs +++ b/language/tools/move-cli/tests/cli_tests.rs @@ -3,8 +3,11 @@ // SPDX-License-Identifier: Apache-2.0 use httpmock::{prelude::*, Mock}; -use move_cli::{base::movey_login::MOVEY_CREDENTIAL_PATH, sandbox::commands::test}; -use move_command_line_common::{files, movey_constants::MOVEY_URL}; +use move_cli::sandbox::commands::test; +use move_command_line_common::{ + files, + movey_constants::{MOVEY_CREDENTIAL_PATH, MOVEY_URL}, +}; use serde_json::json; #[cfg(unix)] use std::fs::File;