Skip to content

Commit

Permalink
Credential registry template (#332)
Browse files Browse the repository at this point in the history
* Initial version of the template

* Add credential registry template ot CI. Fix sed script to allow additional attributes, like features for concordium-std and concordium-cis2

* Check credential-registry template with clippy in CI

* Add template parameter 'restorable'; add comparison with example; tweak example registry contract

* Update CI: fix sed scripts; add restorable param for template generation

* Move template project description to an env variable

* Usesingle quotes for project description

* Tweak project description in template generation

* Change credential registry description so it does not contain whitespace chars

* Fix sed script: keep std version

* Change concordium-std config in credential registry example and template

* Add spaces around concordium-std version

* Add spaces around concordium-std version in the example

* Remove redundant space

* Add revocable_by_others to the credential registry template; test it for all combination of parameters

* Fix diplicate entry in the CI config

* Remove credential register template from all contracts templates in CI (it is tested separately)

* Set revocable_by_others=true in CI config

* Update templates/credential-registry/cargo-generate.toml

Co-authored-by: Doris Benda <[email protected]>

* Change credential registry template flow: default and custom; run clippy on all combinations of parameters

* Fix typo in template var

* Bump cagro_generate version

* Tweak cargo generate version

* Change cagro generate to 0.17.0; add comment

* Change cagro generate to 0.17.5

* Add upgradability to credential registry example and template; use 500 quickcheck tests vs 100 by default; slight refactoring in tests

* Formatting

* Rename error

* Fix comments/descriptions in CI config

* Add CIS-0 support to credential registry example and template

* Use checkout action v3 for templates in CI

* Bump minimum cargo-generate version to 0.17.0; this one supports required rhai functionality

* Fix concordium_cis2 usage in sed script and credential template toml

* Fix sed script

* Fix clippy warnings; fix sed script

* Change default to full in registry template; fix rust compiler version for templates CI

* Comment on cargo-generate version

* Try whitespace in template description


---------

Co-authored-by: Doris Benda <[email protected]>
  • Loading branch information
annenkov and DOBEN authored Sep 6, 2023
1 parent 825da2d commit 1c4eb86
Show file tree
Hide file tree
Showing 9 changed files with 2,855 additions and 46 deletions.
174 changes: 160 additions & 14 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,14 @@ jobs:

steps:
- name: Checkout sources
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
submodules: true

- name: Run cargo-generate
uses: cargo-generate/[email protected]
# we use v0.17.5 here because the minimal supported version is 0.17.0 and the closest
# available version of `cargo-generate-action` is 0.17.5
uses: cargo-generate/[email protected]
with:
name: ${{ env.PROJECT_NAME }}
template: ${{ matrix.crates }}
Expand All @@ -98,7 +100,7 @@ jobs:
- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
toolchain: ${{ env.RUST_VERSION }}

# we need to move the generated project to a temp folder, away from the template project
# otherwise `cargo` runs would fail
Expand All @@ -108,8 +110,49 @@ jobs:
run: |
# TEMPLATE_DIR=`pwd`
mv $PROJECT_NAME ${{ runner.temp }}/
# sed -i "s/{version = \"7.0\", default-features = false}/{path = \"${TEMPLATE_DIR//\//\\\/}\/concordium-std\", default-features = false}/g" ${{ runner.temp }}/$PROJECT_NAME/Cargo.toml
# sed -i "s/{version = \"4.0\", default-features = false}/{path = \"${TEMPLATE_DIR//\//\\\/}\/concordium-cis2\", default-features = false}/g" ${{ runner.temp }}/$PROJECT_NAME/Cargo.toml
cd ${{ runner.temp }}/$PROJECT_NAME
cargo test
# The credential registry template is used to generate code for all combinations of parameters
# with the `cargo-generate` and it is checked that the 'cargo test' command can be executed
# without errors on the generated smart contracts.
cargo-generate-credential-registry-template:
name: Credential registry template tests
runs-on: ubuntu-latest
strategy:
matrix:
restorable: ["true", "false"]
revocable_by_others: ["true", "false"]
env:
PROJECT_NAME: my-project

steps:
- name: Checkout sources
uses: actions/checkout@v3
with:
submodules: true

- name: Run cargo-generate
# we use v0.17.5 here because the minimal supported version is 0.17.0 and the closest
# available version of `cargo-generate-action` is 0.17.5
uses: cargo-generate/[email protected]
with:
name: ${{ env.PROJECT_NAME }}
template: templates/credential-registry
other: "-d description=myProject -d template_type=custom -d restorable=${{ matrix.restorable }} -d revocable_by_others=${{ matrix.revocable_by_others }}"

- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ env.RUST_VERSION }}

# we need to move the generated project to a temp folder, away from the template project
# otherwise `cargo` runs would fail
# see https://github.com/rust-lang/cargo/issues/9922
# Run all tests, including doc tests.
- name: Run cargo test
run: |
mv $PROJECT_NAME ${{ runner.temp }}/
cd ${{ runner.temp }}/$PROJECT_NAME
cargo test
Expand All @@ -127,22 +170,77 @@ jobs:
crates:
- templates/default
- templates/cis2-nft
- templates/credential-registry

env:
PROJECT_NAME: cis2-nft
PROJECT_NAME: my-project

steps:
- name: Checkout sources
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
submodules: true

- name: Run cargo-generate
uses: cargo-generate/[email protected]
# we use v0.17.5 here because the minimal supported version is 0.17.0 and the closest
# available version of `cargo-generate-action` is 0.17.5
uses: cargo-generate/[email protected]
with:
name: ${{ env.PROJECT_NAME }}
template: ${{ matrix.crates }}
other: "-d description=cis2-nft-project -d tokenMetadataBaseURL=https://some.example/token/"
other: "-d description=myProject -d tokenMetadataBaseURL=https://some.example/token/ -d template_type=full"

- name: Install toolchain with clippy available
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ env.RUST_VERSION }}
target: ${{ matrix.target }}
override: true
components: clippy

# we need to move the generated project to a temp folder, away from the template project
# otherwise `cargo` runs would fail
# see https://github.com/rust-lang/cargo/issues/9922
- name: Run clippy with build-schema
run: |
mv $PROJECT_NAME ${{ runner.temp }}/
cd ${{ runner.temp }}/$PROJECT_NAME
rustup target add wasm32-unknown-unknown
cargo clippy --manifest-path ./Cargo.toml --target=${{ matrix.target }} --features concordium-std/build-schema -- -D warnings
# The credential registry template is used to generate code for all combinations of parameters
# with the `cargo-generate` command and it is checked that the schemas can be built as part
# of the 'clippy' command.
clippy-credential-registry-template:
name: Clippy on credential registry template
runs-on: ubuntu-latest
needs: rustfmt
strategy:
matrix:
target:
- wasm32-unknown-unknown

restorable: ["true", "false"]
revocable_by_others: ["true", "false"]

env:
PROJECT_NAME: my-project

steps:
- name: Checkout sources
uses: actions/checkout@v3
with:
submodules: true

- name: Run cargo-generate
# we use v0.17.5 here because the minimal supported version is 0.17.0 and the closest
# available version of `cargo-generate-action` is 0.17.5
uses: cargo-generate/[email protected]
with:
name: ${{ env.PROJECT_NAME }}
template: templates/credential-registry
other: "-d description=myProject -d template_type=custom -d restorable=${{ matrix.restorable }} -d revocable_by_others=${{ matrix.revocable_by_others }}"

- name: Install toolchain with clippy available
uses: actions-rs/toolchain@v1
Expand All @@ -165,8 +263,8 @@ jobs:
# The cis2-nft template is generated with the `cargo-generate` command
# and it is checked that the code is equivalent to the cis2-nft smart contract in the example folder.
cargo-generate-templates-comparison:
name: Smart contract template comparison
cargo-generate-cis2-nft-template-comparison:
name: Cis2-nft smart contract template comparison
runs-on: ubuntu-latest
strategy:
matrix:
Expand All @@ -177,12 +275,14 @@ jobs:

steps:
- name: Checkout sources
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
submodules: true

- name: Run cargo-generate
uses: cargo-generate/[email protected]
# we use v0.17.5 here because the minimal supported version is 0.17.0 and the closest
# available version of `cargo-generate-action` is 0.17.5
uses: cargo-generate/[email protected]
with:
name: ${{ env.PROJECT_NAME }}
template: ${{ matrix.crates }}
Expand All @@ -191,7 +291,7 @@ jobs:
- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
toolchain: ${{ env.RUST_VERSION }}

# Run diff to check if there are any differences between the generated smart contracts
# and the example smart contracts. The templates have hardcoded versions of `concordium-std`
Expand All @@ -207,6 +307,52 @@ jobs:
diff ${{ runner.temp }}/$PROJECT_NAME/Cargo.toml examples/cis2-nft/Cargo.toml
diff ${{ runner.temp }}/$PROJECT_NAME/src/lib.rs examples/cis2-nft/src/lib.rs
# The credential-registry template is generated with the `cargo-generate` command
# and it is checked that the code is equivalent to the credential-registry smart contract in the example folder.
cargo-generate-credential-registry-template-comparison:
name: Credential registry smart contract template comparison
runs-on: ubuntu-latest
strategy:
matrix:
crates:
- templates/credential-registry
env:
PROJECT_NAME: credential-registry

steps:
- name: Checkout sources
uses: actions/checkout@v3
with:
submodules: true

- name: Run cargo-generate
# at least version 0.17.0 is required for the rhai pre-script to work correctly;
# the closest available version of `cargo-generate-action` is 0.17.5
uses: cargo-generate/[email protected]
with:
name: ${{ env.PROJECT_NAME }}
template: ${{ matrix.crates }}
other: "-d description=Example-credential-registry -d template_type=full"

- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ env.RUST_VERSION }}

# Run diff to check if there are any differences between the generated smart contract
# and the example smart contract. The template have hardcoded versions of `concordium-std`
# which needs to be replaced with the path used in the smart contract example folder.
# This CI pipeline uses `root` as the author which needs to be replaced with the author
# `Concordium <[email protected]>` of the smart contract examples.
- name: Run diff
run: |
mv $PROJECT_NAME ${{ runner.temp }}/
sed -i "s/root/Concordium <[email protected]>/g" ${{ runner.temp }}/$PROJECT_NAME/Cargo.toml
sed -i "s/version = \"8.0\", default-features = false/path = \"..\/..\/concordium-std\", version = \"8.0\", default-features = false/g" ${{ runner.temp }}/$PROJECT_NAME/Cargo.toml
sed -i "s/version = \"5.0\", default-features = false/path = \"..\/..\/concordium-cis2\", version = \"5.0\", default-features = false/g" ${{ runner.temp }}/$PROJECT_NAME/Cargo.toml
diff ${{ runner.temp }}/$PROJECT_NAME/Cargo.toml examples/credential-registry/Cargo.toml
diff ${{ runner.temp }}/$PROJECT_NAME/src/lib.rs examples/credential-registry/src/lib.rs
clippy-cis2:
name: Clippy
runs-on: ubuntu-latest
Expand Down
7 changes: 4 additions & 3 deletions examples/credential-registry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ version = "0.1.0"
edition = "2021"
license = "MPL-2.0"
authors = [ "Concordium <[email protected]>" ]
description = "An example credential registry smart contract"
description = "Example-credential-registry"

[features]
default = ["std", "crypto-primitives", "wee_alloc"]
std = ["concordium-std/std"]
std = ["concordium-std/std", "concordium-cis2/std"]
wee_alloc = ["concordium-std/wee_alloc"]
crypto-primitives = ["concordium-std/crypto-primitives"]

[dependencies]
concordium-std = {path = "../../concordium-std", version="8.0", features = ["concordium-quickcheck"], default-features = false}
concordium-std = {path = "../../concordium-std", version = "8.0", default-features = false, features = ["concordium-quickcheck"]}
concordium-cis2 = {path = "../../concordium-cis2", version = "5.0", default-features = false}
quickcheck = {version = "1"}

[lib]
Expand Down
Loading

0 comments on commit 1c4eb86

Please sign in to comment.