Skip to content

Commit

Permalink
Target pallet-revive/PolkaVM instead of pallet-contracts/Wasm (#1910
Browse files Browse the repository at this point in the history
)

* Migrate to `pallet-revive`

* Bump versions to `6.0.0-alpha`

* Add compatibility matrix

* Use Docker image `useink/ci` for CI

* Clean up CI

* Remove `debug-ci`

* Fix `cargo fmt` in CI

* Fix CI

* Fix CI

* Fix tests

* Reduce code duplication

* Fix CI

* Fix CI

* Fix issues with `CARGO_TARGET_DIR`

* Use ink! `master`

* Remove generic `Hash` where possible

* Use `polkadot-sdk` compatible deps

* Implement `contract info` + `contract storage`

* Upgrade to scale `3.1.2`

* Revert "Upgrade to scale `3.1.2`"

This reverts commit 3a7c635.

* Fix issue with `parity-scale-codec-derive` dep

* Overwrite dep version everywhere

* Remove `[replace]`

* Revert "Remove `[replace]`"

This reverts commit 3c86c9c.

* Fix patch

* Revert to `scale` 3.6.12

* Update `Cargo.lock`

* Use particular ink! branch

* Use `scale` 3.7.3

* Use `scale` 3.6.2 again

* Use `scale` 3.6.12

* Use `ink` branch

* Use ink! `master`

* Make clippy happy

* Apply `cargo fmt`

* Add `default-features`

* Fix `contract info` tests

* Make clippy happy

* Add test for adhering to limits

* Add `cargo contract account` for resolving H160 addr

* Clean up code

* Clean up + update deps

* Make clippy happy

* Add integration tests

* Clean up

* Replace WebAssembly/Wasm terms with appropriate PolkaVM ones

* Fix CI

* Fix CI

* Fix naming

* Fix field names
  • Loading branch information
cmichi authored Feb 4, 2025
1 parent ea745c0 commit d13aafc
Show file tree
Hide file tree
Showing 72 changed files with 5,724 additions and 4,335 deletions.
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ updates:
- package-ecosystem: "cargo"
directory: "/"
schedule:
interval: "daily"
interval: "monthly"
# ignore Substrate pallets major updates.
# automated Substrate releases cause dependabot PR spam, so these must be updated manually when required.
ignore:
Expand Down
195 changes: 80 additions & 115 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: ci

on:
pull_request:
push:
Expand All @@ -9,26 +10,43 @@ on:
paths-ignore:
- 'README.md'
- 'CHANGELOG.md'

env:
# Image can be edited at https://github.com/use-ink/docker-images
IMAGE: useink/ci
CARGO_TARGET_DIR: /ci-cache/${{ github.repository }}/targets/${{ github.ref_name }}/${{ github.job }}

concurrency:
# Cancel in-progress jobs triggered only on pull_requests
group: ${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
fmt:
set-image:
# GitHub Actions does not allow using 'env' in a container context.
# This workaround sets the container image for each job using the 'set-image' job output.
runs-on: ubuntu-latest
outputs:
IMAGE: ${{ steps.set_image.outputs.IMAGE }}
steps:
- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
default: true
components: rustfmt
- id: set_image
run: echo "IMAGE=${{ env.IMAGE }}" >> $GITHUB_OUTPUT

fmt:
runs-on: ubuntu-latest
defaults:
run:
shell: bash
needs: [set-image]
container:
image: ${{ needs.set-image.outputs.IMAGE }}
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Check Formatting
uses: actions-rs/cargo@v1
with:
command: fmt
args: --check
run: |
cargo +nightly fmt --all -- --check
# Runs `cargo check` on each individual crate in the `crates` directory.
#
Expand All @@ -48,13 +66,13 @@ jobs:
# `clippy` commands which operate on the workspace and enable all targets.
check:
runs-on: ubuntu-latest
defaults:
run:
shell: bash
needs: [set-image]
container:
image: ${{ needs.set-image.outputs.IMAGE }}
steps:
- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable

- name: Cache
uses: Swatinem/rust-cache@v2

Expand All @@ -70,15 +88,13 @@ jobs:
clippy:
runs-on: ubuntu-latest
defaults:
run:
shell: bash
needs: [set-image]
container:
image: ${{ needs.set-image.outputs.IMAGE }}
steps:
- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
default: true
components: clippy

- name: Cache
uses: Swatinem/rust-cache@v2

Expand All @@ -96,96 +112,72 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Clippy with features
uses: actions-rs/clippy-check@v1
if: ${{ steps.check_permissions.outputs.has-permission }}
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --profile debug-ci --all-features --all-targets -- -D warnings
run: cargo +nightly clippy --all-features --all-targets -- -D warnings

- name: Clippy without features
if: ${{ steps.check_permissions.outputs.has-permission }}
uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --profile debug-ci --all-targets -- -D warnings
run: cargo +nightly clippy --all-targets -- -D warnings

# Runs if the GITHUB_TOKEN does not have `write` permissions e.g. @dependabot
- name: Clippy with features (no annotations)
if: ${{ !steps.check_permissions.outputs.has-permission }}
run: cargo clippy --profile debug-ci --all-features --all-targets -- -D warnings
run: cargo +nightly clippy --all-features --all-targets -- -D warnings

# Runs if the GITHUB_TOKEN does not have `write` permissions e.g. @dependabot
- name: Clippy without features (no annotations)
if: ${{ !steps.check_permissions.outputs.has-permission }}
run: cargo clippy --profile debug-ci --all-targets -- -D warnings
run: cargo +nightly clippy --all-targets -- -D warnings

build-tests:
strategy:
fail-fast: false
matrix:
# We want newer versions than 'latest' here to have current wasm-opt
os: ["ubuntu-22.04", "macos-15"]
runs-on: ${{ matrix.os }}
env:
RUST_BACKTRACE: full
runs-on: ubuntu-latest
defaults:
run:
shell: bash
needs: [ set-image ]
container:
image: ${{ needs.set-image.outputs.IMAGE }}
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
default: true
target: wasm32-unknown-unknown
components: rust-src, clippy

- name: Cache
uses: Swatinem/rust-cache@v2

- name: Install nextest
uses: taiki-e/install-action@v2.45.15
uses: taiki-e/install-action@v2.48.1
with:
tool: nextest

- name: Build and archive tests
run: cargo nextest archive --cargo-profile debug-ci --workspace --all-features --archive-file nextest-archive-${{ matrix.os }}.tar.zst
run: cargo nextest archive --workspace --all-features --archive-file nextest-archive-${{ matrix.os }}.tar.zst
- name: Upload archive to workflow
uses: actions/upload-artifact@v4
with:
name: nextest-archive-${{ matrix.os }}
path: nextest-archive-${{ matrix.os }}.tar.zst

run-tests:
needs: build-tests
needs: [ set-image, build-tests ]
runs-on: ubuntu-latest
defaults:
run:
shell: bash
container:
image: ${{ needs.set-image.outputs.IMAGE }}
strategy:
fail-fast: false
matrix:
# We want newer versions than 'latest' here to have current wasm-opt
os: ["ubuntu-22.04", "macos-15"]
partition: [1, 2]
runs-on: ${{ matrix.os }}
env:
RUST_BACKTRACE: full
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
default: true
target: wasm32-unknown-unknown
components: rust-src, clippy

- name: Cache
uses: Swatinem/rust-cache@v2

- name: Install nextest
uses: taiki-e/install-action@v2.45.15
uses: taiki-e/install-action@v2.48.1
with:
tool: nextest

Expand All @@ -202,34 +194,26 @@ jobs:
run: cargo nextest run --archive-file nextest-archive-${{ matrix.os }}.tar.zst --partition count:${{ matrix.partition }}/2 -j 1 -E 'package(contract-build)'

run-integration-test:
needs: build-tests
needs: [ set-image, build-tests ]
runs-on: ubuntu-latest
defaults:
run:
shell: bash
container:
image: ${{ needs.set-image.outputs.IMAGE }}
strategy:
fail-fast: false
matrix:
# We want newer versions than 'latest' here to have current wasm-opt
os: ["ubuntu-22.04", "macos-15"]
partition: [1, 2]
runs-on: ${{ matrix.os }}
env:
RUST_BACKTRACE: full
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
default: true
target: wasm32-unknown-unknown
components: rust-src, clippy

- name: Cache
uses: Swatinem/rust-cache@v2

- name: Install nextest
uses: taiki-e/install-action@v2.45.15
uses: taiki-e/install-action@v2.48.1
with:
tool: nextest

Expand All @@ -238,24 +222,6 @@ jobs:
with:
name: nextest-archive-${{ matrix.os }}

- name: Install latest `substrate-contracts-node` binary
env:
CONTRACTS_NODE_URL: https://github.com/paritytech/substrate-contracts-node/releases/latest/download/substrate-contracts-node-
run: |
if [ "$RUNNER_OS" == "Linux" ]; then
CONTRACTS_NODE_OS=linux
elif [ "$RUNNER_OS" == "macOS" ]; then
CONTRACTS_NODE_OS=mac-universal
else
echo "$RUNNER_OS not supported"
exit 1
fi
curl -L -o substrate-contracts-node.tar.gz "$CONTRACTS_NODE_URL$CONTRACTS_NODE_OS.tar.gz"
tar xfzv substrate-contracts-node.tar.gz
chmod +x substrate-contracts-node-*/substrate-contracts-node &&
mv substrate-contracts-node-*/substrate-contracts-node /usr/local/bin
shell: bash

- name: Run integration tests
# The integration tests cannot be run in parallel
run: cargo nextest run --archive-file nextest-archive-${{ matrix.os }}.tar.zst --partition count:${{ matrix.partition }}/2 -j 1 -E 'test(integration_tests)'
Expand All @@ -264,13 +230,15 @@ jobs:
strategy:
fail-fast: false
matrix:
# We want newer versions than 'latest' here to have current wasm-opt
os: ["ubuntu-22.04", "macos-15", "windows-2022"]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Cache
uses: Swatinem/rust-cache@v2

- name: Install nightly toolchain
uses: actions-rs/toolchain@v1
with:
Expand All @@ -285,19 +253,16 @@ jobs:
default: true
components: rust-src

- name: Cache
uses: Swatinem/rust-cache@v2

- name: Check Template
run: >-
# The linter requires two crates
cargo install cargo-dylint dylint-link
cargo -vV &&
cargo run --profile debug-ci -- contract --version &&
cargo run --profile debug-ci -- contract new --target-dir ${{ runner.temp }} foobar &&
cargo run -- contract --version &&
cargo run -- contract new --target-dir ${{ runner.temp }} foobar &&
# Build with linting
cargo run --profile debug-ci -- contract build --lint --manifest-path=${{ runner.temp }}/foobar/Cargo.toml &&
cargo run --profile debug-ci -- contract check --manifest-path=${{ runner.temp }}/foobar/Cargo.toml &&
cargo run --profile debug-ci -- contract build --manifest-path=${{ runner.temp }}/foobar/Cargo.toml --release &&
cargo run -- contract build --lint --manifest-path=${{ runner.temp }}/foobar/Cargo.toml &&
cargo run -- contract check --manifest-path=${{ runner.temp }}/foobar/Cargo.toml &&
cargo run -- contract build --manifest-path=${{ runner.temp }}/foobar/Cargo.toml --release &&
# Run tests
cargo test --profile debug-ci --all-features -- --test-threads=1
cargo test --all-features -- --test-threads=1
2 changes: 1 addition & 1 deletion .rustfmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ wrap_comments = true # changed
format_code_in_doc_comments = true # changed
doc_comment_code_block_width = 100 # changed
comment_width = 90 # changed
normalize_comments = true # changed
#normalize_comments = true # changed # todo change back
normalize_doc_attributes = false
format_strings = false
format_macro_matchers = false
Expand Down
Loading

0 comments on commit d13aafc

Please sign in to comment.