Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Credential registry template #332

Merged
merged 46 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
6e5b420
Initial version of the template
annenkov Aug 24, 2023
85476b7
Add credential registry template ot CI. Fix sed script to allow addit…
annenkov Aug 24, 2023
730103a
Check credential-registry template with clippy in CI
annenkov Aug 25, 2023
c83ba05
Add template parameter 'restorable'; add comparison with example; twe…
annenkov Aug 28, 2023
5fa0f0e
Update CI: fix sed scripts; add restorable param for template generation
annenkov Aug 29, 2023
1dd2c44
Move template project description to an env variable
annenkov Aug 29, 2023
889a636
Usesingle quotes for project description
annenkov Aug 29, 2023
babf2bc
Tweak project description in template generation
annenkov Aug 29, 2023
b5dadef
Change credential registry description so it does not contain whitesp…
annenkov Aug 29, 2023
34a5d0c
Fix sed script: keep std version
annenkov Aug 29, 2023
294d6d9
Change concordium-std config in credential registry example and template
annenkov Aug 29, 2023
0687268
Add spaces around concordium-std version
annenkov Aug 29, 2023
a1e11ab
Add spaces around concordium-std version in the example
annenkov Aug 29, 2023
61071f8
Remove redundant space
annenkov Aug 29, 2023
800998b
Add revocable_by_others to the credential registry template; test it …
annenkov Aug 30, 2023
f7322c0
Fix diplicate entry in the CI config
annenkov Aug 30, 2023
56ddaaa
Remove credential register template from all contracts templates in C…
annenkov Aug 30, 2023
a987a03
Set revocable_by_others=true in CI config
annenkov Aug 30, 2023
588a2a9
Update templates/credential-registry/cargo-generate.toml
annenkov Aug 31, 2023
d800085
Change credential registry template flow: default and custom; run cli…
annenkov Aug 31, 2023
52ec691
Fix typo in template var
annenkov Aug 31, 2023
7cc6d45
Bump cagro_generate version
annenkov Aug 31, 2023
6fa6d0b
Tweak cargo generate version
annenkov Aug 31, 2023
9b9df72
Change cagro generate to 0.17.0; add comment
annenkov Aug 31, 2023
31e8f7f
Change cagro generate to 0.17.5
annenkov Aug 31, 2023
9fe55bc
Add upgradability to credential registry example and template; use 50…
annenkov Sep 5, 2023
4177f10
Formatting
annenkov Sep 5, 2023
8b26e8c
Rename error
annenkov Sep 5, 2023
9113f63
Fix comments/descriptions in CI config
annenkov Sep 5, 2023
2465782
Add CIS-0 support to credential registry example and template
annenkov Sep 6, 2023
9e58b2b
Use checkout action v3 for templates in CI
annenkov Sep 6, 2023
8a7c015
Bump minimum cargo-generate version to 0.17.0; this one supports requ…
annenkov Sep 6, 2023
1244dc8
Fix concordium_cis2 usage in sed script and credential template toml
annenkov Sep 6, 2023
9b705e6
Fix sed script
annenkov Sep 6, 2023
120cbbb
Fix clippy warnings; fix sed script
annenkov Sep 6, 2023
4309e4d
Change default to full in registry template; fix rust compiler versio…
annenkov Sep 6, 2023
fb3cad7
Comment on cargo-generate version
annenkov Sep 6, 2023
b1fdddb
Try whitespace in template description
annenkov Sep 6, 2023
125436d
Try fix description
annenkov Sep 6, 2023
44f0a14
Try fix description
annenkov Sep 6, 2023
fd566a0
Try fix description
annenkov Sep 6, 2023
53c99d1
Try fix description
annenkov Sep 6, 2023
f8b15f2
Try fix description
annenkov Sep 6, 2023
63c9ce3
Try fix description
annenkov Sep 6, 2023
d7aa22a
Try fix description
annenkov Sep 6, 2023
eb3ae36
Back to project description with dashes
annenkov Sep 6, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
annenkov marked this conversation as resolved.
Show resolved Hide resolved

[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
Loading