From 715f0f4dc61e412a8d4f7ec1d46c19ce2e9d9e1f Mon Sep 17 00:00:00 2001 From: Patrick Kuo Date: Fri, 8 Jul 2022 19:01:19 +0100 Subject: [PATCH] [cleanup] change generate-json-rpc-spec to cargo example instead of binary (#3103) * don't need to build generate-json-rpc-spec binary * fixup after rebase * fixup after rebase * minor doc fix * minor doc fix --- Cargo.lock | 36 ++++++++----------- Cargo.toml | 1 - crates/generate-json-rpc-spec/Cargo.toml | 27 -------------- .../tests/generate-spec.rs | 15 -------- crates/sui-open-rpc/Cargo.toml | 23 ++++++++++++ .../src/generate_json_rpc_spec.rs} | 28 +++++---------- crates/sui-open-rpc/tests/generate-spec.rs | 21 +++++++++++ 7 files changed, 67 insertions(+), 84 deletions(-) delete mode 100644 crates/generate-json-rpc-spec/Cargo.toml delete mode 100644 crates/generate-json-rpc-spec/tests/generate-spec.rs rename crates/{generate-json-rpc-spec/src/main.rs => sui-open-rpc/src/generate_json_rpc_spec.rs} (96%) create mode 100644 crates/sui-open-rpc/tests/generate-spec.rs diff --git a/Cargo.lock b/Cargo.lock index 112e0e9bfb0a4..c51628eb8194c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2173,28 +2173,6 @@ dependencies = [ "slab", ] -[[package]] -name = "generate-json-rpc-spec" -version = "0.0.0" -dependencies = [ - "anyhow", - "clap 3.1.18", - "hyper", - "move-package", - "pretty_assertions", - "serde 1.0.138", - "serde_json", - "sui", - "sui-config", - "sui-json", - "sui-json-rpc", - "sui-json-rpc-api", - "sui-types", - "test-utils", - "tokio", - "workspace-hack 0.1.0", -] - [[package]] name = "generic-array" version = "0.12.4" @@ -6790,8 +6768,22 @@ dependencies = [ name = "sui-open-rpc" version = "0.1.0" dependencies = [ + "anyhow", + "clap 3.1.18", + "hyper", + "move-package", + "pretty_assertions", "schemars", "serde 1.0.138", + "serde_json", + "sui", + "sui-config", + "sui-json", + "sui-json-rpc", + "sui-json-rpc-api", + "sui-types", + "test-utils", + "tokio", "workspace-hack 0.1.0", ] diff --git a/Cargo.toml b/Cargo.toml index ef13937593bf7..6e55d4792f71e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,6 @@ [workspace] resolver = "2" members = [ - "crates/generate-json-rpc-spec", "crates/sui", "crates/sui-adapter", "crates/sui-adapter-transactional-tests", diff --git a/crates/generate-json-rpc-spec/Cargo.toml b/crates/generate-json-rpc-spec/Cargo.toml deleted file mode 100644 index d05fb8d02745c..0000000000000 --- a/crates/generate-json-rpc-spec/Cargo.toml +++ /dev/null @@ -1,27 +0,0 @@ -[package] -name = "generate-json-rpc-spec" -version = "0.0.0" -authors = ["Mysten Labs "] -license = "Apache-2.0" -publish = false -edition = "2021" - -[dependencies] -anyhow = { version = "1.0.58", features = ["backtrace"] } -clap = { version = "3.1.17", features = ["derive"] } -pretty_assertions = "1.2.0" -serde = { version = "1.0.138", features = ["derive"] } -serde_json = "1.0.80" -tokio = { version = "1.18.2", features = ["full"] } -hyper = { version = "0.14.18", features = ["full"] } - -sui = { path = "../sui" } -sui-json-rpc = { path = "../sui-json-rpc" } -sui-json-rpc-api = { path = "../sui-json-rpc-api" } -sui-json = { path = "../sui-json" } -sui-types = { path = "../sui-types" } -sui-config = { path = "../sui-config" } -test-utils = { path = "../test-utils" } - -move-package = { git = "https://github.com/move-language/move", rev = "7733658048a8bc80e9ba415b8c99aed9234eaa5f" } -workspace-hack = { path = "../workspace-hack"} diff --git a/crates/generate-json-rpc-spec/tests/generate-spec.rs b/crates/generate-json-rpc-spec/tests/generate-spec.rs deleted file mode 100644 index 791032c58db0c..0000000000000 --- a/crates/generate-json-rpc-spec/tests/generate-spec.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) 2022, Mysten Labs, Inc. -// SPDX-License-Identifier: Apache-2.0 - -const GENERATE_JSON_RPC_SPEC_BIN: &str = env!("CARGO_BIN_EXE_generate-json-rpc-spec"); - -#[test] -fn test_json_rpc_spec() { - // If this test breaks and you intended a json rpc schema change, you need to run to get the fresh schema: - // # cargo -q run --bin generate-json-rpc-spec -- record - let status = std::process::Command::new(GENERATE_JSON_RPC_SPEC_BIN) - .arg("test") - .status() - .expect("failed to execute process"); - assert!(status.success()); -} diff --git a/crates/sui-open-rpc/Cargo.toml b/crates/sui-open-rpc/Cargo.toml index 25c1c89185ad8..f6b2bf0d13703 100644 --- a/crates/sui-open-rpc/Cargo.toml +++ b/crates/sui-open-rpc/Cargo.toml @@ -10,3 +10,26 @@ edition = "2021" schemars = "0.8.10" serde = "1.0.138" workspace-hack = { path = "../workspace-hack"} + +[dev-dependencies] +anyhow = { version = "1.0.58", features = ["backtrace"] } +clap = { version = "3.1.17", features = ["derive"] } +pretty_assertions = "1.2.0" +serde_json = "1.0.80" +tokio = { version = "1.18.2", features = ["full"] } +hyper = { version = "0.14.18", features = ["full"] } + +sui = { path = "../sui" } +sui-json-rpc = { path = "../sui-json-rpc" } +sui-json-rpc-api = { path = "../sui-json-rpc-api" } +sui-json = { path = "../sui-json" } +sui-types = { path = "../sui-types" } +sui-config = { path = "../sui-config" } +test-utils = { path = "../test-utils" } + +move-package = { git = "https://github.com/move-language/move", rev = "7733658048a8bc80e9ba415b8c99aed9234eaa5f" } + +[[example]] +name = "generate-json-rpc-spec" +path = "src/generate_json_rpc_spec.rs" +test = false \ No newline at end of file diff --git a/crates/generate-json-rpc-spec/src/main.rs b/crates/sui-open-rpc/src/generate_json_rpc_spec.rs similarity index 96% rename from crates/generate-json-rpc-spec/src/main.rs rename to crates/sui-open-rpc/src/generate_json_rpc_spec.rs index 4e9d8edfaf427..67f7d155dea30 100644 --- a/crates/generate-json-rpc-spec/src/main.rs +++ b/crates/sui-open-rpc/src/generate_json_rpc_spec.rs @@ -55,25 +55,15 @@ struct Options { action: Action, } -const FILE_PATH: &str = concat!( - env!("CARGO_MANIFEST_DIR"), - "/../sui-open-rpc/spec/openrpc.json", -); - -const OBJECT_SAMPLE_FILE_PATH: &str = concat!( - env!("CARGO_MANIFEST_DIR"), - "/../sui-open-rpc/samples/objects.json", -); - -const TRANSACTION_SAMPLE_FILE_PATH: &str = concat!( - env!("CARGO_MANIFEST_DIR"), - "/../sui-open-rpc/samples/transactions.json", -); - -const OWNED_OBJECT_SAMPLE_FILE_PATH: &str = concat!( - env!("CARGO_MANIFEST_DIR"), - "/../sui-open-rpc/samples/owned_objects.json", -); +const FILE_PATH: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/spec/openrpc.json",); + +const OBJECT_SAMPLE_FILE_PATH: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/samples/objects.json",); + +const TRANSACTION_SAMPLE_FILE_PATH: &str = + concat!(env!("CARGO_MANIFEST_DIR"), "/samples/transactions.json",); + +const OWNED_OBJECT_SAMPLE_FILE_PATH: &str = + concat!(env!("CARGO_MANIFEST_DIR"), "/samples/owned_objects.json",); #[tokio::main] async fn main() { diff --git a/crates/sui-open-rpc/tests/generate-spec.rs b/crates/sui-open-rpc/tests/generate-spec.rs new file mode 100644 index 0000000000000..80612674bfe77 --- /dev/null +++ b/crates/sui-open-rpc/tests/generate-spec.rs @@ -0,0 +1,21 @@ +// Copyright (c) 2022, Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + +#[test] +fn test_json_rpc_spec() { + // If this test breaks and you intended a json rpc schema change, you need to run to get the fresh schema: + // # cargo -q run --example generate-json-rpc-spec -- record + let status = std::process::Command::new("cargo") + .current_dir("..") + .args(&["run", "--example", "generate-json-rpc-spec", "--"]) + .arg("test") + .status() + .expect("failed to execute process"); + assert!( + status.success(), + "\n\ +If this test breaks and you intended a json rpc schema change, you need to run to get the fresh schema:\n\ +cargo -q run --example generate-json-rpc-spec -- record\n\ + " + ); +}