From c84ace8ab97d5259146d47000ecd3bae3892c825 Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Mon, 3 Feb 2020 09:33:50 +0000 Subject: [PATCH 1/5] Check default features build in CI --- .gitlab-ci.yml | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 100dbe52..50f9bad3 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -8,7 +8,8 @@ stages: - check - test - - build + - build-df + - build-af variables: GIT_STRATEGY: fetch @@ -72,10 +73,21 @@ test: script: - cargo test --verbose --all-features --release -#### stage: build +#### stage: build (default features) build: - stage: build + stage: build-df + <<: *docker-env + only: + - schedules + - master + script: + - cargo build --verbose --release + +#### stage: build (all features) + +build-af: + stage: build-af <<: *docker-env only: - schedules -- GitLab From 94f74448278895b0a718ef155502bc2c0e640ae6 Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Mon, 3 Feb 2020 09:45:45 +0000 Subject: [PATCH 2/5] Hide extrinsics only stuff behind feature --- src/cmd/extrinsics.rs | 59 +++++++++++++++++++++++++++++++++++++++++++ src/cmd/mod.rs | 51 +++++-------------------------------- src/main.rs | 6 ++--- 3 files changed, 69 insertions(+), 47 deletions(-) create mode 100644 src/cmd/extrinsics.rs diff --git a/src/cmd/extrinsics.rs b/src/cmd/extrinsics.rs new file mode 100644 index 00000000..b309d746 --- /dev/null +++ b/src/cmd/extrinsics.rs @@ -0,0 +1,59 @@ +// Copyright 2018-2019 Parity Technologies (UK) Ltd. +// This file is part of ink!. +// +// ink! 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. +// +// ink! 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 ink!. If not, see . + +use anyhow::Result; +use subxt::{ClientBuilder, DefaultNodeRuntime, ExtrinsicSuccess}; + +use crate::ExtrinsicOpts; + +/// Submits an extrinsic to a substrate node, waits for it to succeed and returns an event expected +/// to have been triggered by the extrinsic. +pub fn submit_extrinsic( + extrinsic_opts: &ExtrinsicOpts, + call: subxt::Call, + event_mod: &str, + event_name: &str, +) -> Result + where + C: codec::Encode, + E: codec::Decode, +{ + let result: Result> = async_std::task::block_on(async move { + let cli = ClientBuilder::::new() + .set_url(&extrinsic_opts.url.to_string()) + .build() + .await?; + let signer = extrinsic_opts.signer()?; + let xt = cli.xt(signer, None).await?; + let success = xt.watch().submit(call).await?; + Ok(success) + }); + + match result?.find_event::(event_mod, event_name) { + Some(Ok(hash)) => Ok(hash), + Some(Err(err)) => Err(anyhow::anyhow!( + "Failed to decode event '{} {}': {}", + event_mod, + event_name, + err + )), + None => Err(anyhow::anyhow!( + "Failed to find '{} {}' Event", + event_mod, + event_name + )), + } +} diff --git a/src/cmd/mod.rs b/src/cmd/mod.rs index 78b76625..56e0d4dd 100644 --- a/src/cmd/mod.rs +++ b/src/cmd/mod.rs @@ -14,27 +14,29 @@ // You should have received a copy of the GNU General Public License // along with ink!. If not, see . -use crate::ExtrinsicOpts; use anyhow::Result; use std::{ io::{self, Write}, path::PathBuf, process::Command, }; -use subxt::{ClientBuilder, DefaultNodeRuntime, ExtrinsicSuccess}; mod build; #[cfg(feature = "extrinsics")] mod deploy; #[cfg(feature = "extrinsics")] +mod extrinsics; +#[cfg(feature = "extrinsics")] mod instantiate; mod metadata; mod new; #[cfg(feature = "extrinsics")] -pub(crate) use self::deploy::execute_deploy; -#[cfg(feature = "extrinsics")] -pub(crate) use self::instantiate::execute_instantiate; +pub(crate) use self::{ + deploy::execute_deploy, + extrinsics::submit_extrinsic, + instantiate::execute_instantiate, +}; pub(crate) use self::{ build::execute_build, metadata::execute_generate_metadata, new::execute_new, }; @@ -71,45 +73,6 @@ fn exec_cargo(command: &str, args: &[&'static str], working_dir: Option<&PathBuf Ok(()) } -/// Submits an extrinsic to a substrate node, waits for it to succeed and returns an event expected -/// to have been triggered by the extrinsic. -fn submit_extrinsic( - extrinsic_opts: &ExtrinsicOpts, - call: subxt::Call, - event_mod: &str, - event_name: &str, -) -> Result -where - C: codec::Encode, - E: codec::Decode, -{ - let result: Result> = async_std::task::block_on(async move { - let cli = ClientBuilder::::new() - .set_url(&extrinsic_opts.url.to_string()) - .build() - .await?; - let signer = extrinsic_opts.signer()?; - let xt = cli.xt(signer, None).await?; - let success = xt.watch().submit(call).await?; - Ok(success) - }); - - match result?.find_event::(event_mod, event_name) { - Some(Ok(hash)) => Ok(hash), - Some(Err(err)) => Err(anyhow::anyhow!( - "Failed to decode event '{} {}': {}", - event_mod, - event_name, - err - )), - None => Err(anyhow::anyhow!( - "Failed to find '{} {}' Event", - event_mod, - event_name - )), - } -} - #[cfg(test)] mod tests { use std::path::PathBuf; diff --git a/src/main.rs b/src/main.rs index 2274c3dc..361847de 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,7 +18,7 @@ mod cmd; #[cfg(feature = "extrinsics")] use sp_core::{crypto::Pair, sr25519, H256}; -use std::{path::PathBuf, result::Result as StdResult, str::FromStr}; +use std::path::PathBuf; use anyhow::Result; use structopt::{clap, StructOpt}; @@ -44,10 +44,10 @@ pub(crate) struct ContractArgs { pub(crate) struct HexData(pub Vec); #[cfg(feature = "extrinsics")] -impl FromStr for HexData { +impl std::str::FromStr for HexData { type Err = hex::FromHexError; - fn from_str(input: &str) -> StdResult { + fn from_str(input: &str) -> std::result::Result { hex::decode(input).map(HexData) } } -- GitLab From 3f036281c1e4b5843d814c4ec752880e37d063d7 Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Mon, 3 Feb 2020 09:55:26 +0000 Subject: [PATCH 3/5] Make submit_extrinsic crate public --- src/cmd/extrinsics.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cmd/extrinsics.rs b/src/cmd/extrinsics.rs index b309d746..be236456 100644 --- a/src/cmd/extrinsics.rs +++ b/src/cmd/extrinsics.rs @@ -21,7 +21,7 @@ use crate::ExtrinsicOpts; /// Submits an extrinsic to a substrate node, waits for it to succeed and returns an event expected /// to have been triggered by the extrinsic. -pub fn submit_extrinsic( +pub(crate) fn submit_extrinsic( extrinsic_opts: &ExtrinsicOpts, call: subxt::Call, event_mod: &str, -- GitLab From 4b0a89256248df3007635183795687b4b6fddbee Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Mon, 3 Feb 2020 10:08:11 +0000 Subject: [PATCH 4/5] Fmt --- src/cmd/extrinsics.rs | 44 +++++++++++++++++++++---------------------- src/cmd/mod.rs | 8 +++----- 2 files changed, 25 insertions(+), 27 deletions(-) diff --git a/src/cmd/extrinsics.rs b/src/cmd/extrinsics.rs index be236456..ffdabda4 100644 --- a/src/cmd/extrinsics.rs +++ b/src/cmd/extrinsics.rs @@ -22,38 +22,38 @@ use crate::ExtrinsicOpts; /// Submits an extrinsic to a substrate node, waits for it to succeed and returns an event expected /// to have been triggered by the extrinsic. pub(crate) fn submit_extrinsic( - extrinsic_opts: &ExtrinsicOpts, - call: subxt::Call, - event_mod: &str, - event_name: &str, + extrinsic_opts: &ExtrinsicOpts, + call: subxt::Call, + event_mod: &str, + event_name: &str, ) -> Result - where - C: codec::Encode, - E: codec::Decode, +where + C: codec::Encode, + E: codec::Decode, { - let result: Result> = async_std::task::block_on(async move { - let cli = ClientBuilder::::new() - .set_url(&extrinsic_opts.url.to_string()) - .build() - .await?; - let signer = extrinsic_opts.signer()?; - let xt = cli.xt(signer, None).await?; - let success = xt.watch().submit(call).await?; - Ok(success) - }); + let result: Result> = async_std::task::block_on(async move { + let cli = ClientBuilder::::new() + .set_url(&extrinsic_opts.url.to_string()) + .build() + .await?; + let signer = extrinsic_opts.signer()?; + let xt = cli.xt(signer, None).await?; + let success = xt.watch().submit(call).await?; + Ok(success) + }); - match result?.find_event::(event_mod, event_name) { - Some(Ok(hash)) => Ok(hash), - Some(Err(err)) => Err(anyhow::anyhow!( + match result?.find_event::(event_mod, event_name) { + Some(Ok(hash)) => Ok(hash), + Some(Err(err)) => Err(anyhow::anyhow!( "Failed to decode event '{} {}': {}", event_mod, event_name, err )), - None => Err(anyhow::anyhow!( + None => Err(anyhow::anyhow!( "Failed to find '{} {}' Event", event_mod, event_name )), - } + } } diff --git a/src/cmd/mod.rs b/src/cmd/mod.rs index 56e0d4dd..a7f99882 100644 --- a/src/cmd/mod.rs +++ b/src/cmd/mod.rs @@ -31,14 +31,12 @@ mod instantiate; mod metadata; mod new; -#[cfg(feature = "extrinsics")] pub(crate) use self::{ - deploy::execute_deploy, - extrinsics::submit_extrinsic, - instantiate::execute_instantiate, + build::execute_build, metadata::execute_generate_metadata, new::execute_new, }; +#[cfg(feature = "extrinsics")] pub(crate) use self::{ - build::execute_build, metadata::execute_generate_metadata, new::execute_new, + deploy::execute_deploy, extrinsics::submit_extrinsic, instantiate::execute_instantiate, }; fn exec_cargo(command: &str, args: &[&'static str], working_dir: Option<&PathBuf>) -> Result<()> { -- GitLab From 6f851ccf30b61ce2c3453f86c5c5693425c29a52 Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Mon, 3 Feb 2020 10:27:31 +0000 Subject: [PATCH 5/5] Make build run on CI with default features --- .gitlab-ci.yml | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 50f9bad3..0884d535 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -8,8 +8,7 @@ stages: - check - test - - build-df - - build-af + - build variables: GIT_STRATEGY: fetch @@ -65,7 +64,7 @@ fmt: script: - cargo fmt --verbose --all -- --check -#### stage: test +#### stage: test (all features) test: stage: test @@ -76,21 +75,10 @@ test: #### stage: build (default features) build: - stage: build-df + stage: build <<: *docker-env only: - schedules - master script: - cargo build --verbose --release - -#### stage: build (all features) - -build-af: - stage: build-af - <<: *docker-env - only: - - schedules - - master - script: - - cargo build --verbose --all-features --release -- GitLab