From ac6903c92441f4f16de7e824537b40b99d677e4b Mon Sep 17 00:00:00 2001 From: Gianfranco Date: Thu, 2 May 2024 11:49:19 -0300 Subject: [PATCH] conditionally run test, initial workflow --- .github/workflows/test.yml | 65 ++++++++++++++++++++ src/lib.rs | 4 +- src/xdr/impls/claimable_balance_id.rs | 6 +- src/xdr/impls/error.rs | 2 +- src/xdr/impls/generalized_transaction_set.rs | 2 +- src/xdr/xdr_codec.rs | 7 ++- 6 files changed, 77 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..c1b4c91 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,65 @@ +on: + pull_request: + branches: + - 'polkadot-v0.9.42' + +name: continuous-integration-cargo-test +jobs: + ci: + runs-on: ubuntu-20.04 + env: + RUST_BACKTRACE: full + # Make sure CI fails on all warnings, including Clippy lints + RUSTFLAGS: "-Dwarnings" + + steps: + - name: Freeing up more disk space + run: | + free -h + sudo rm -rf /usr/local/lib/android # will release about 10 GB if you don't need Android + sudo rm -rf /usr/share/dotnet # will release about 20GB if you don't need .NET + sudo rm -rf /opt/ghc + sudo rm -rf /usr/local/share/boost + sudo rm -rf /opt/hostedtoolcache/CodeQL + sudo rm -rf "$AGENT_TOOLSDIRECTORY" + sudo apt-get remove -y 'php.*' --fix-missing + sudo apt-get remove -y '^mongodb-.*' --fix-missing + sudo apt-get remove -y '^mysql-.*' --fix-missing + sudo apt-get clean + df -h + - uses: actions/checkout@v2 + + - name: Install package + run: | + sudo docker image prune --all --force + echo 'APT::Get::Always-Include-Phased-Updates "false";' | sudo tee /etc/apt/apt.conf.d/99-phased-updates + sudo apt-get update && sudo apt-get upgrade -y + sudo apt-get install -y protobuf-compiler libprotobuf-dev + + - name: Setup Rust toolchain + # Call `rustup show` as a hack so that the toolchain defined in rust-toolchain.toml is installed + run: rustup show + + - name: Use Cache + uses: Swatinem/rust-cache@v2 + with: + cache-on-failure: true + key: "ubuntu-latest-cargo-${{ hashFiles('**/Cargo.lock') }}" + shared-key: "shared" + + - name: Install Protoc + uses: arduino/setup-protoc@v1 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + + - name: Build + uses: actions-rs/cargo@v1 + with: + command: build + args: --all-features + + - name: Test + uses: actions-rs/cargo@v1 + with: + command: test + args: --all --all-features diff --git a/src/lib.rs b/src/lib.rs index d8022d7..88c47ac 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,9 +8,9 @@ extern crate alloc; mod lib { #[cfg(not(feature = "std"))] - pub use alloc::string::{String, ToString, FromUtf8Error}; + pub use alloc::string::{FromUtf8Error, String, ToString}; #[cfg(feature = "std")] - pub use std::string::{String, ToString, FromUtf8Error}; + pub use std::string::{FromUtf8Error, String, ToString}; } mod amount; diff --git a/src/xdr/impls/claimable_balance_id.rs b/src/xdr/impls/claimable_balance_id.rs index 1602b0f..f51cab9 100644 --- a/src/xdr/impls/claimable_balance_id.rs +++ b/src/xdr/impls/claimable_balance_id.rs @@ -1,5 +1,7 @@ -use crate::{AsBinary, ClaimableBalanceId, StellarSdkError, XdrCodec}; -use crate::lib::{String, ToString}; +use crate::{ + lib::{String, ToString}, + AsBinary, ClaimableBalanceId, StellarSdkError, XdrCodec, +}; pub trait IntoClaimbleBalanceId { fn into_claimable_balance_id(self) -> Result; diff --git a/src/xdr/impls/error.rs b/src/xdr/impls/error.rs index 5219a15..386d4a3 100644 --- a/src/xdr/impls/error.rs +++ b/src/xdr/impls/error.rs @@ -7,4 +7,4 @@ impl> crate::StellarTypeToString for Er let msg = sp_std::str::from_utf8(msg).map_err(E::from)?; Ok(format!("Error{{ code:{:?} message:{msg} }}", self.code)) } -} \ No newline at end of file +} diff --git a/src/xdr/impls/generalized_transaction_set.rs b/src/xdr/impls/generalized_transaction_set.rs index 54c01c5..bdfadb4 100644 --- a/src/xdr/impls/generalized_transaction_set.rs +++ b/src/xdr/impls/generalized_transaction_set.rs @@ -1,6 +1,6 @@ use crate::{ - lib::{String, FromUtf8Error}, compound_types::UnlimitedVarArray, + lib::{FromUtf8Error, String}, types::{GeneralizedTransactionSet, TransactionPhase, TxSetComponent}, Hash, IntoHash, StellarSdkError, TransactionEnvelope, XdrCodec, }; diff --git a/src/xdr/xdr_codec.rs b/src/xdr/xdr_codec.rs index e1e564d..d5c397c 100644 --- a/src/xdr/xdr_codec.rs +++ b/src/xdr/xdr_codec.rs @@ -210,8 +210,9 @@ impl XdrCodec for Box { /// /// Basic usage: /// -/// ``` -/// use crate::types::Auth; +#[cfg_attr(feature = "all-types", doc = "```")] +#[cfg_attr(not(feature = "all-types"), doc = "```ignore")] +/// use substrate_stellar_sdk::{types::Auth, parse_stellar_type}; /// let auth_xdr = [0, 0, 0, 1]; /// let result = parse_stellar_type!(auth_xdr,Auth); /// assert_eq!(result, Ok(Auth { flags: 1 })) @@ -219,7 +220,7 @@ impl XdrCodec for Box { #[macro_export] macro_rules! parse_stellar_type { ($ref:ident, $struct_str:ident) => {{ - use $crate::{types::$struct_str, StellarSdkError}; + use $crate::{types::$struct_str, StellarSdkError, XdrCodec}; let ret: Result<$struct_str, StellarSdkError> = $struct_str::from_xdr($ref).map_err(|_| StellarSdkError::DecodeError(stringify!($struct_str).into()));