diff --git a/.github/workflows/build-test-contracts-common.yaml b/.github/workflows/build-test-contracts-common.yaml index 6a5dee651..fdf5035c9 100644 --- a/.github/workflows/build-test-contracts-common.yaml +++ b/.github/workflows/build-test-contracts-common.yaml @@ -7,19 +7,25 @@ on: paths: - 'smart-contracts/contracts-common/**/*.rs' - 'smart-contracts/contracts-common/**/*.toml' + - '.github/workflows/build-test-contracts-common.yaml' + pull_request: branches: - main paths: - 'smart-contracts/contracts-common/**/*.rs' - 'smart-contracts/contracts-common/**/*.toml' + - '.github/workflows/build-test-contracts-common.yaml' name: Clippy & fmt env: RUST_VERSION: "1.65" RUST_FMT: "nightly-2023-04-01" - WORKING_DIRECTORY: "./smart-contracts/contracts-common" + +defaults: + run: + working-directory: "./smart-contracts/contracts-common" jobs: rustfmt: @@ -29,17 +35,10 @@ jobs: - name: Checkout sources uses: actions/checkout@v2 - - name: Install nightly toolchain with rustfmt available - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: ${{ env.RUST_FMT }} - override: true - components: rustfmt - - name: Run cargo fmt - working-directory: ${{ env.WORKING_DIRECTORY }} run: | + rustup default ${{ env.RUST_FMT }} + rustup component add rustfmt cargo fmt --all --check rustdoc: @@ -49,16 +48,10 @@ jobs: - name: Checkout sources uses: actions/checkout@v2 - - name: Install Rust - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: ${{ env.RUST_VERSION }} - override: true - - name: Run cargo doc - working-directory: ${{ env.WORKING_DIRECTORY }} run: | + rustup default ${{ env.RUST_VERSION }} + rustup component add rust-docs RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --all-features --color=always clippy: @@ -82,21 +75,12 @@ jobs: - name: Checkout sources uses: actions/checkout@v2 - - name: Install nightly toolchain with clippy available - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: ${{ env.RUST_VERSION }} - target: ${{ matrix.target }} - override: true - components: clippy - - name: Run cargo clippy - uses: actions-rs/cargo@v1 - working-directory: ${{ env.WORKING_DIRECTORY }} - with: - command: clippy - args: --manifest-path=concordium-contracts-common/Cargo.toml --target=${{ matrix.target }} --features=${{ matrix.features }} --no-default-features -- -D warnings + run: | + rustup default ${{ env.RUST_VERSION }} + rustup component add clippy + rustup target add ${{ matrix.target }} + cargo clippy --manifest-path=concordium-contracts-common/Cargo.toml --target=${{ matrix.target }} --features=${{ matrix.features }} --no-default-features -- -D warnings clippy-on-derive: name: Clippy on concordium-contracts-common-derive @@ -115,21 +99,12 @@ jobs: - name: Checkout sources uses: actions/checkout@v2 - - name: Install nightly toolchain with clippy available - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: ${{ env.RUST_VERSION }} - target: ${{ matrix.target }} - override: true - components: clippy - - name: Run cargo clippy - uses: actions-rs/cargo@v1 - working-directory: ${{ env.WORKING_DIRECTORY }} - with: - command: clippy - args: --manifest-path=concordium-contracts-common-derive/Cargo.toml --target=${{ matrix.target }} --no-default-features -- -D warnings + run: | + rustup default ${{ env.RUST_VERSION }} + rustup component add clippy + rustup target add ${{ matrix.target }} + cargo clippy --manifest-path=concordium-contracts-common-derive/Cargo.toml --target=${{ matrix.target }} --no-default-features -- -D warnings test: name: x86_64 tests @@ -138,16 +113,7 @@ jobs: - name: Checkout sources uses: actions/checkout@v2 - - name: Install stable toolchain - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: ${{ env.RUST_VERSION }} - override: true - - name: Run cargo test - uses: actions-rs/cargo@v1 - working-directory: ${{ env.WORKING_DIRECTORY }} - with: - command: test - args: --workspace --all-features + run: | + rustup default ${{ env.RUST_VERSION }} + cargo test --workspace --all-features diff --git a/.github/workflows/build-test-smart-contracts.yaml b/.github/workflows/build-test-smart-contracts.yaml index 9229f394b..462c4c16d 100644 --- a/.github/workflows/build-test-smart-contracts.yaml +++ b/.github/workflows/build-test-smart-contracts.yaml @@ -23,7 +23,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Install WABT run: sudo apt-get update && sudo apt-get -y install wabt - name: Check consistency @@ -41,17 +41,12 @@ jobs: - 'wasm-chain-integration' steps: - name: Checkout - uses: actions/checkout@v2 - - name: Install Rust - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: ${{ env.RUST_FMT }} - override: true - components: rustfmt + uses: actions/checkout@v4 - name: Format working-directory: smart-contracts/${{ matrix.build-dir }} run: | + rustup default ${{ env.RUST_FMT }} + rustup component add rustfmt cargo fmt -- --color=always --check "lint_doc": @@ -66,19 +61,14 @@ jobs: - 'wasm-chain-integration' steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: submodules: recursive - - name: Install Rust - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: ${{ env.RUST_CLIPPY }} - override: true - components: clippy - name: Format working-directory: smart-contracts/${{ matrix.build-dir }} run: | + rustup default ${{ env.RUST_CLIPPY }} + rustup component add rust-docs RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --all-features "lint_fmt_example_contracts": @@ -98,18 +88,12 @@ jobs: - 'fib' steps: - name: Checkout - uses: actions/checkout@v2 - - name: Install Rust - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: ${{ env.RUST_FMT }} - override: true - target: wasm32-unknown-unknown - components: rustfmt + uses: actions/checkout@v4 - name: Format working-directory: smart-contracts/rust-contracts/example-contracts/${{ matrix.example-contract }} run: | + rustup default ${{ env.RUST_FMT }} + rustup component add rustfmt cargo fmt -- --color=always --check "lint_clippy_wasm_transform": @@ -123,20 +107,15 @@ jobs: - 'wasm-transform' steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: submodules: recursive - - name: Install Rust - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: ${{ env.RUST_CLIPPY }} - override: true - components: clippy - name: Clippy working-directory: smart-contracts/${{ matrix.build-dir }} run: | git config --global url."https://github.com/".insteadOf "git@github.com:" + rustup default ${{ env.RUST_CLIPPY }} + rustup component add clippy cargo clippy --color=always --tests --benches -- -Dclippy::all "lint_clippy_wasm_chain_integration": @@ -154,20 +133,15 @@ jobs: - 'async' steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: submodules: recursive - - name: Install Rust - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: ${{ env.RUST_CLIPPY }} - override: true - components: clippy - name: Clippy working-directory: smart-contracts/${{ matrix.build-dir }} run: | git config --global url."https://github.com/".insteadOf "git@github.com:" + rustup default ${{ env.RUST_CLIPPY }} + rustup component add clippy cargo clippy --locked --features ${{ matrix.features }} --no-default-features --color=always --tests --benches -- -Dclippy::all "lint_clippy_example_contracts": @@ -187,19 +161,14 @@ jobs: - 'fib' steps: - name: Checkout - uses: actions/checkout@v2 - - name: Install Rust - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: ${{ env.RUST_CLIPPY }} - override: true - target: wasm32-unknown-unknown - components: clippy + uses: actions/checkout@v4 - name: Clippy working-directory: smart-contracts/rust-contracts/example-contracts/${{ matrix.example-contract }} run: | git config --global url."https://github.com/".insteadOf "git@github.com:" + rustup default ${{ env.RUST_CLIPPY }} + rustup component add clippy + rustup target add wasm32-unknown-unknown cargo clippy --locked --color=always --tests -- -Dclippy::all "cargo_test": @@ -212,18 +181,14 @@ jobs: - 'wasm-chain-integration' steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: submodules: recursive - - name: Install Rust - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: ${{ env.RUST_CLIPPY }} - override: true - name: Test working-directory: smart-contracts/${{ matrix.build-dir }} - run: cargo test + run: | + rustup default ${{ env.RUST_CLIPPY }} + cargo test "cargo_test_example_contracts": name: ${{ matrix.example-contract }} cargo:test @@ -243,17 +208,12 @@ jobs: #Remaining example contracts have not yet been added to ci steps: - name: Checkout - uses: actions/checkout@v2 - - name: Install Rust - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: ${{ env.RUST_CLIPPY }} - override: true + uses: actions/checkout@v4 - name: Test working-directory: smart-contracts/rust-contracts/example-contracts/${{ matrix.example-contract }} run: | git config --global url."https://github.com/".insteadOf "git@github.com:" + rustup default ${{ env.RUST_CLIPPY }} cargo test --target x86_64-unknown-linux-gnu "wasm-core-spec_cargo_test": @@ -261,17 +221,12 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: submodules: recursive - - name: Install Rust - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: ${{ env.RUST_CLIPPY }} - override: true - name: Test working-directory: smart-contracts/wasm-test run: | + rustup default ${{ env.RUST_CLIPPY }} cargo build ./target/debug/wasm-test --dir ../testdata/wasm-spec-test-suite/core/ diff --git a/.github/workflows/build-test-sources.yaml b/.github/workflows/build-test-sources.yaml index 1fbd7d3f1..e5a960bf1 100644 --- a/.github/workflows/build-test-sources.yaml +++ b/.github/workflows/build-test-sources.yaml @@ -59,6 +59,12 @@ jobs: matrix: plan: - rust: "nightly-2023-04-01-x86_64-unknown-linux-gnu" + crates: + - rust-src + - rust-bins + - idiss + - mobile_wallet + - identity-provider-service steps: - name: Checkout @@ -66,21 +72,11 @@ jobs: with: submodules: recursive - - name: Install Rust - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: ${{ matrix.plan.rust }} - override: true - components: rustfmt - - name: Run rustfmt run: | - cargo fmt --manifest-path rust-src/Cargo.toml --all -- --check - cargo fmt --manifest-path rust-bins/Cargo.toml -- --check - cargo fmt --manifest-path idiss/Cargo.toml -- --check - cargo fmt --manifest-path mobile_wallet/Cargo.toml -- --check - cargo fmt --manifest-path identity-provider-service/Cargo.toml -- --check + rustup default ${{ matrix.plan.rust }} + rustup component add rustfmt + cargo fmt --manifest-path ${{ matrix.crates }}/Cargo.toml --all -- --check rustdoc: runs-on: ubuntu-latest @@ -103,16 +99,11 @@ jobs: with: submodules: recursive - - name: Install Rust - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: ${{ matrix.plan.rust }} - override: true - - name: Run cargo doc working-directory: ${{ matrix.crates }} run: | + rustup default ${{ matrix.plan.rust }} + rustup component add rust-docs RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --all-features --color=always fourmolu: @@ -156,18 +147,9 @@ jobs: submodules: recursive # RUST # - # Set up Rust and restore dependencies and targets from cache. - # This must be done before checking the Rust sources. - - name: Install Rust - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: ${{ matrix.plan.rust }} - override: true - components: clippy - - name: Check that concordium base compiles with older Rust version. run: | + rustup default ${{ matrix.plan.rust }} cargo check --manifest-path rust-src/concordium_base/Cargo.toml build-test: @@ -206,13 +188,11 @@ jobs: restore-keys: | ${{ runner.os }}-{{ env.dummy }}-rust-deps-${{ matrix.plan.rust }} - name: Install Rust - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: ${{ matrix.plan.rust }} - override: true - components: clippy - target: aarch64-linux-android + run: | + rustup default ${{ matrix.plan.rust }} + rustup component add clippy rust-docs + rustup target add aarch64-linux-android + # Lightweight check that Rust code compiles. # Catching failure here avoids restoring of Haskell caches. - name: Check that all Rust targets build diff --git a/smart-contracts/contracts-common/concordium-contracts-common/src/schema.rs b/smart-contracts/contracts-common/concordium-contracts-common/src/schema.rs index e9ceb9c79..665e459bc 100644 --- a/smart-contracts/contracts-common/concordium-contracts-common/src/schema.rs +++ b/smart-contracts/contracts-common/concordium-contracts-common/src/schema.rs @@ -1223,15 +1223,14 @@ mod impls { pub fn get_event_schema(&self, contract_name: &str) -> Result { let versioned_contract_schema = get_versioned_contract_schema(self, contract_name)?; - let param_event = match versioned_contract_schema { + match versioned_contract_schema { VersionedContractSchema::V0(_) => Err(VersionedSchemaError::EventNotSupported)?, VersionedContractSchema::V1(_) => Err(VersionedSchemaError::EventNotSupported)?, VersionedContractSchema::V2(_) => Err(VersionedSchemaError::EventNotSupported)?, VersionedContractSchema::V3(contract_schema) => { contract_schema.event.ok_or(VersionedSchemaError::NoEventInContract) } - }; - param_event + } } /// Returns a receive function's error schema from a versioned module diff --git a/smart-contracts/contracts-common/concordium-contracts-common/src/schema_json.rs b/smart-contracts/contracts-common/concordium-contracts-common/src/schema_json.rs index 4973c724f..c1b3765c8 100644 --- a/smart-contracts/contracts-common/concordium-contracts-common/src/schema_json.rs +++ b/smart-contracts/contracts-common/concordium-contracts-common/src/schema_json.rs @@ -2110,7 +2110,7 @@ Contract: MySecondContract #[test] fn test_serial_account_address() { let account_bytes = [0u8; ACCOUNT_ADDRESS_SIZE]; - let account = AccountAddress(account_bytes.clone()); + let account = AccountAddress(account_bytes); let schema = Type::AccountAddress; let bytes = schema.serial_value(&json!(format!("{}", &account))).expect("Serializing failed"); @@ -2124,7 +2124,7 @@ Contract: MySecondContract #[test] fn test_serial_account_address_wrong_address_fails() { let account_bytes = [0u8; ACCOUNT_ADDRESS_SIZE]; - let account = AccountAddress(account_bytes.clone()); + let account = AccountAddress(account_bytes); let schema = Type::AccountAddress; let json = json!(format!("{}", &account).get(1..)); let err = schema.serial_value(&json).expect_err("Serializing should fail"); @@ -2149,7 +2149,7 @@ Contract: MySecondContract #[test] fn test_serial_list_fails_with_trace() { let account_bytes = [0u8; ACCOUNT_ADDRESS_SIZE]; - let account = AccountAddress(account_bytes.clone()); + let account = AccountAddress(account_bytes); let schema = Type::List(SizeLength::U8, Box::new(Type::AccountAddress)); let json = json!([format!("{}", account), 123]); let err = schema.serial_value(&json).expect_err("Serializing should fail"); @@ -2170,7 +2170,7 @@ Contract: MySecondContract #[test] fn test_serial_object_fails_with_trace() { let account_bytes = [0u8; ACCOUNT_ADDRESS_SIZE]; - let account = AccountAddress(account_bytes.clone()); + let account = AccountAddress(account_bytes); let schema = Type::Struct(Fields::Named(vec![ ("account".into(), Type::AccountAddress), ("contract".into(), Type::ContractAddress), @@ -2194,7 +2194,7 @@ Contract: MySecondContract #[test] fn test_serial_fails_with_nested_trace() { let account_bytes = [0u8; ACCOUNT_ADDRESS_SIZE]; - let account = AccountAddress(account_bytes.clone()); + let account = AccountAddress(account_bytes); let schema_object = Type::Struct(Fields::Named(vec![ ("account".into(), Type::AccountAddress), ("contract".into(), Type::ContractAddress), diff --git a/smart-contracts/contracts-common/concordium-contracts-common/src/types.rs b/smart-contracts/contracts-common/concordium-contracts-common/src/types.rs index debe6e480..5251d92df 100644 --- a/smart-contracts/contracts-common/concordium-contracts-common/src/types.rs +++ b/smart-contracts/contracts-common/concordium-contracts-common/src/types.rs @@ -2860,7 +2860,7 @@ mod test { #[cfg(feature = "derive-serde")] fn test_given_rfc3339_format_when_string_to_timestamp_then_map() { let datetime = "1970-01-01T00:00:00.042+00:00"; - if let Ok(timestamp) = Timestamp::from_str(&datetime) { + if let Ok(timestamp) = Timestamp::from_str(datetime) { assert_eq!(timestamp.milliseconds, 42); } else { assert!(false)