diff --git a/Cargo.lock b/Cargo.lock index 19363d9ecbc..808b25af9cc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3703,8 +3703,6 @@ dependencies = [ "schnorrkel 0.9.1", "serde", "serde_json", - "sp-core", - "sp-io", "thiserror", "tokio", "wasmi 0.30.0 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/gcli/Cargo.toml b/gcli/Cargo.toml index 2db1a7dec7d..ce0163b3799 100644 --- a/gcli/Cargo.toml +++ b/gcli/Cargo.toml @@ -40,8 +40,6 @@ tokio = { workspace = true, features = [ "full" ] } whoami.workspace = true reqwest = { workspace = true, default-features = false, features = [ "json", "rustls-tls" ] } etc.workspace = true -sp-io = { workspace = true, features = [ "std" ] } -sp-core = { workspace = true, features = [ "std" ] } runtime-primitives.workspace = true # TODO: use wasmi from workspace (#3214) wasmi = { version = "0.30.0", features = ["std"] } diff --git a/gcli/src/app.rs b/gcli/src/app.rs index b78274f3e7b..946ec3d3b24 100644 --- a/gcli/src/app.rs +++ b/gcli/src/app.rs @@ -22,7 +22,7 @@ use crate::keystore; use clap::Parser; use color_eyre::{eyre::eyre, Result}; use env_logger::{Builder, Env}; -use gsdk::{signer::Signer, Api}; +use gsdk::{ext::sp_core, signer::Signer, Api}; /// Command line gear program application abstraction. /// diff --git a/gcli/tests/gear.rs b/gcli/tests/gear.rs index 9be81626459..110ab8d488e 100644 --- a/gcli/tests/gear.rs +++ b/gcli/tests/gear.rs @@ -17,24 +17,11 @@ // along with this program. If not, see . use common::env; -use gsdk::{result::Error, Api}; use std::path::PathBuf; mod cmd; mod common; -#[tokio::test] -async fn api_timeout() { - let error = Api::new_with_timeout(None, Some(0)).await.err(); - assert!( - matches!( - error, - Some(Error::SubxtRpc(jsonrpsee::core::Error::Transport(..))) - ), - "Unexpected error occurred: {error:?}" - ); -} - #[test] fn paths() { [ diff --git a/gsdk/tests/main.rs b/gsdk/tests/main.rs new file mode 100644 index 00000000000..b97d56256d7 --- /dev/null +++ b/gsdk/tests/main.rs @@ -0,0 +1,34 @@ +// This file is part of Gear. + +// Copyright (C) 2022-2024 Gear Technologies Inc. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +use gsdk::Api; + +#[tokio::test] +async fn timeout() { + let error = Api::new_with_timeout(None, Some(0)).await.err(); + // NOTE: + // + // There are two kinds of timeout error provided by subxt: + // + // - client request timeout + // - transport timeout + assert!( + format!("{error:?}").to_lowercase().contains("timeout"), + "Unexpected error occurred: {error:?}" + ); +} diff --git a/utils/crates-io/src/handler.rs b/utils/crates-io/src/handler.rs index 67514ccdbab..3a434923cec 100644 --- a/utils/crates-io/src/handler.rs +++ b/utils/crates-io/src/handler.rs @@ -23,6 +23,9 @@ use anyhow::Result; use cargo_metadata::Package; use toml_edit::Document; +/// The working version of sp-wasm-interface. +pub const GP_RUNTIME_INTERFACE_VERSION: &str = "18.0.0"; + /// Get the crates-io name of the provided package. pub fn crates_io_name(pkg: &str) -> &str { // `gear-core-processor` is taken by others, see the docs @@ -65,7 +68,12 @@ pub fn patch_alias(index: &mut Vec<&str>) { pub fn patch_workspace(name: &str, table: &mut toml_edit::InlineTable) { match name { "core-processor" | "gear-core-processor" => core_processor::patch_workspace(name, table), - sub if sub.starts_with("sp-") => substrate::patch_workspace(name, table), + sub if ["sc-", "sp-", "frame-", "try-runtime-cli"] + .iter() + .any(|p| sub.starts_with(p)) => + { + substrate::patch_workspace(name, table) + } _ => {} } } @@ -138,7 +146,7 @@ mod gmeta_codegen { } mod runtime_interface { - use crate::GP_RUNTIME_INTERFACE_VERSION; + use super::GP_RUNTIME_INTERFACE_VERSION; use toml_edit::Document; /// Patch the manifest of runtime-interface. @@ -189,40 +197,86 @@ mod sandbox_host { /// substrate handler. mod substrate { - use crate::GP_RUNTIME_INTERFACE_VERSION; + use super::GP_RUNTIME_INTERFACE_VERSION; use toml_edit::InlineTable; /// Patch the substrate packages in the manifest of workspace. /// + /// Substrate packages on crates-io currently have no version management + /// (), + /// the following versions are pinned to frame-support-v22.0.0 on crates-io + /// now, for + /// the details. + /// /// NOTE: The packages inside of this function are located at - /// . + /// . pub fn patch_workspace(name: &str, table: &mut InlineTable) { match name { + "frame-support" | "frame-system" | "sp-core" => { + table.insert("version", "22.0.0".into()); + } + "frame-support-test" => return, + "frame-benchmarking-cli" => { + table.insert("version", "26.0.0".into()); + } + "sc-cli" => { + table.insert("version", "0.30.0".into()); + } + "sc-client-db" | "sc-service" => { + table.insert("version", "0.29.0".into()); + } + "sp-api" | "sp-rpc" => { + table.insert("version", "20.0.0".into()); + } + "sp-arithmetic" => { + table.insert("version", "17.0.0".into()); + } + "sp-debug-derive" | "sp-std" => { + table.insert("version", "9.0.0".into()); + } + "sp-io" => { + table.insert("version", "24.0.0".into()); + } + "sp-runtime" => { + table.insert("version", "25.0.0".into()); + } + "sp-version" => { + table.insert("version", "23.0.0".into()); + } + "sp-weights" => { + table.insert("version", "21.0.0".into()); + } + "try-runtime-cli" => { + table.insert("version", "0.32.0".into()); + } // sp-allocator is outdated on crates.io, last // 3.0.0 forever, here we use gp-allocator instead. "sp-allocator" => { - table.insert("version", "4.1.1".into()); + table.insert("version", "4.1.2".into()); table.insert("package", "gp-allocator".into()); } - // Our sp-wasm-interface is different from the - // original one. + // Our sp-wasm-interface is different from the substrate one. + // + // ref: sp-wasm-interface-15.0.0 "sp-wasm-interface" => { table.insert("package", "gp-wasm-interface".into()); - table.insert("version", "7.0.1".into()); + table.insert("version", "15.0.0".into()); } // Related to sp-wasm-interface. + // + // no ref bcz we own this package. "sp-wasm-interface-common" => { - table.insert("version", "7.0.1".into()); + table.insert("version", "15.0.0".into()); } // Related to sp-wasm-interface. + // + // ref: + // - sp-runtime-interface-18.0.0 + // - sp-runtime-interface-proc-macro-12.0.0 "sp-runtime-interface" => { table.insert("version", GP_RUNTIME_INTERFACE_VERSION.into()); table.insert("package", "gp-runtime-interface".into()); } - // The versions of these packages on crates.io are incorrect. - "sp-arithmetic" | "sp-core" | "sp-rpc" | "sp-version" => { - table.insert("version", "21.0.0".into()); - } _ => {} } diff --git a/utils/crates-io/src/lib.rs b/utils/crates-io/src/lib.rs index 029d9536f08..a19b8739530 100644 --- a/utils/crates-io/src/lib.rs +++ b/utils/crates-io/src/lib.rs @@ -81,16 +81,18 @@ pub const PACKAGE_ALIAS: [(&str, &str); 2] = [ ("gear-runtime-primitives", "runtime-primitives"), ]; -/// The working version of sp-wasm-interface. -pub const GP_RUNTIME_INTERFACE_VERSION: &str = "7.0.5"; - /// Check the input package pub fn check(manifest: &str) -> Result { Command::new("cargo") - .arg("check") - .arg("--lib") - .arg("--manifest-path") - .arg(manifest) + .args(["check", "--lib", "--manifest-path", manifest]) + .status() + .map_err(Into::into) +} + +/// Test the input package +pub fn test(package: &str, test: &str) -> Result { + Command::new("cargo") + .args(["test", "-p", package, "--", test]) .status() .map_err(Into::into) } @@ -98,10 +100,7 @@ pub fn check(manifest: &str) -> Result { /// Publish the input package pub fn publish(manifest: &str) -> Result { Command::new("cargo") - .arg("publish") - .arg("--manifest-path") - .arg(manifest) - .arg("--allow-dirty") + .args(["publish", "--manifest-path", manifest, "--allow-dirty"]) .status() .map_err(Into::into) } diff --git a/utils/crates-io/src/publisher.rs b/utils/crates-io/src/publisher.rs index 7a2d79d504c..4f9f3271c73 100644 --- a/utils/crates-io/src/publisher.rs +++ b/utils/crates-io/src/publisher.rs @@ -114,6 +114,16 @@ impl Publisher { panic!("Packages {failed:?} failed to pass the check ..."); } + // Post tests for gtest and gclient + for (pkg, test) in [ + ("demo-syscall-error", "program_can_be_initialized"), + ("gsdk", "timeout"), + ] { + if !crate::test(pkg, test)?.success() { + panic!("{pkg}:{test} failed to pass the test ..."); + } + } + Ok(()) }