Skip to content

Commit

Permalink
Merge pull request #347 from Concordium/kb/migrate-tests
Browse files Browse the repository at this point in the history
Migrate tests for example contracts
  • Loading branch information
abizjak committed Oct 27, 2023
2 parents 870502c + ee531fd commit 461d390
Show file tree
Hide file tree
Showing 89 changed files with 7,055 additions and 6,798 deletions.
106 changes: 66 additions & 40 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ name: Clippy & fmt
env:
RUST_FMT: nightly-2023-04-01
RUST_VERSION: "1.66"
CARGO_CONCORDIUM_VERSION: "3.0.0"

jobs:
rustfmt:
Expand Down Expand Up @@ -130,16 +131,22 @@ jobs:
with:
toolchain: ${{ env.RUST_VERSION }}

- name: Install Wasm target
run: rustup target install wasm32-unknown-unknown

# 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: |
# TEMPLATE_DIR=`pwd`
CARGO_CCD=cargo-concordium_${{ env.CARGO_CONCORDIUM_VERSION }}
wget https://distribution.concordium.software/tools/linux/$CARGO_CCD
chmod +x $CARGO_CCD
sudo mv $CARGO_CCD /usr/bin/cargo-concordium
mv $PROJECT_NAME ${{ runner.temp }}/
cd ${{ runner.temp }}/$PROJECT_NAME
cargo test
cargo concordium test --out "./concordium-out/module.wasm.v1"
# 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
Expand Down Expand Up @@ -174,15 +181,22 @@ jobs:
with:
toolchain: ${{ env.RUST_VERSION }}

- name: Install Wasm target
run: rustup target install wasm32-unknown-unknown

# 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: |
CARGO_CCD=cargo-concordium_${{ env.CARGO_CONCORDIUM_VERSION }}
wget https://distribution.concordium.software/tools/linux/$CARGO_CCD
chmod +x $CARGO_CCD
sudo mv $CARGO_CCD /usr/bin/cargo-concordium
mv $PROJECT_NAME ${{ runner.temp }}/
cd ${{ runner.temp }}/$PROJECT_NAME
cargo test
cargo concordium test --out "./concordium-out/module.wasm.v1"
# All templates are generated with the `cargo-generate` command
# and it is checked that the schemas can be built as part of the 'clippy' command.
Expand Down Expand Up @@ -330,10 +344,12 @@ jobs:
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\", default-features = false}/g" ${{ runner.temp }}/$PROJECT_NAME/Cargo.toml
sed -i "s/{version = \"5.0\", default-features = false}/{path = \"..\/..\/concordium-cis2\", default-features = false}/g" ${{ runner.temp }}/$PROJECT_NAME/Cargo.toml
sed -i "s/{version = \"8.1\", default-features = false}/{path = \"..\/..\/concordium-std\", default-features = false}/g" ${{ runner.temp }}/$PROJECT_NAME/Cargo.toml
sed -i "s/{version = \"5.1\", default-features = false}/{path = \"..\/..\/concordium-cis2\", default-features = false}/g" ${{ runner.temp }}/$PROJECT_NAME/Cargo.toml
sed -i "s/concordium-smart-contract-testing = \"3.0\"/concordium-smart-contract-testing = {path = \"..\/..\/contract-testing\"}/g" ${{ runner.temp }}/$PROJECT_NAME/Cargo.toml
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
diff ${{ runner.temp }}/$PROJECT_NAME/tests/tests.rs examples/cis2-nft/tests/tests.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.
Expand Down Expand Up @@ -376,10 +392,12 @@ jobs:
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
sed -i "s/version = \"8.1\", default-features = false/path = \"..\/..\/concordium-std\", version = \"8.1\", default-features = false/g" ${{ runner.temp }}/$PROJECT_NAME/Cargo.toml
sed -i "s/version = \"5.1\", default-features = false/path = \"..\/..\/concordium-cis2\", version = \"5.1\", default-features = false/g" ${{ runner.temp }}/$PROJECT_NAME/Cargo.toml
sed -i "s/concordium-smart-contract-testing = \"3.1\"/concordium-smart-contract-testing = {path = \"..\/..\/contract-testing\"}/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
diff ${{ runner.temp }}/$PROJECT_NAME/tests/tests.rs examples/credential-registry/tests/tests.rs
diff ${{ runner.temp }}/$PROJECT_NAME/README.md examples/credential-registry/README.md
clippy-cis2:
Expand Down Expand Up @@ -623,9 +641,6 @@ jobs:
- crypto-primitives

crates:
- examples/nametoken/Cargo.toml
- examples/signature-verifier/Cargo.toml
- examples/cis3-nft-sponsored-txs/Cargo.toml
- examples/credential-registry/Cargo.toml

steps:
Expand Down Expand Up @@ -787,30 +802,30 @@ jobs:
- x86_64-unknown-linux-gnu

crates:
- examples/voting/Cargo.toml
- examples/eSealing/Cargo.toml
- examples/auction/Cargo.toml
- examples/cis2-multi/Cargo.toml
- examples/cis2-multi-royalties/Cargo.toml
- examples/cis2-nft/Cargo.toml
- examples/cis3-nft-sponsored-txs/Cargo.toml
- examples/cis2-wccd/Cargo.toml
- examples/credential-registry/Cargo.toml
- examples/fib/Cargo.toml
- examples/icecream/Cargo.toml
- examples/memo/Cargo.toml
- examples/nametoken/Cargo.toml
- examples/piggy-bank/part1/Cargo.toml
- examples/piggy-bank/part2/Cargo.toml
- examples/proxy/Cargo.toml
- examples/recorder/Cargo.toml
- examples/signature-verifier/Cargo.toml
- examples/transfer-policy-check/Cargo.toml
- examples/two-step-transfer/Cargo.toml
- examples/smart-contract-upgrade/contract-version1/Cargo.toml
- examples/smart-contract-upgrade/contract-version2/Cargo.toml
- examples/offchain-transfers/Cargo.toml
- examples/account-signature-checks/Cargo.toml
- examples/voting
- examples/eSealing
- examples/auction
- examples/cis2-multi
- examples/cis2-multi-royalties
- examples/cis2-nft
- examples/cis3-nft-sponsored-txs
- examples/cis2-wccd
- examples/credential-registry
- examples/fib
- examples/icecream
- examples/memo
- examples/nametoken
- examples/piggy-bank/part1
- examples/piggy-bank/part2
- examples/proxy
- examples/recorder
- examples/signature-verifier
- examples/transfer-policy-check
- examples/two-step-transfer
- examples/smart-contract-upgrade/contract-version1
- examples/smart-contract-upgrade/contract-version2
- examples/offchain-transfers
- examples/account-signature-checks

steps:
- name: Checkout sources
Expand All @@ -826,9 +841,20 @@ jobs:
target: ${{ matrix.target }}
override: true

- name: Run cargo test
uses: actions-rs/cargo@v1
with:
command: test
# only run the library tests, no doc tests
args: --manifest-path ${{ matrix.crates }} --target=${{ matrix.target }} --lib
- name: Install Wasm target
run: rustup target install wasm32-unknown-unknown

- name: Download and install Cargo Concordium
run: |
CARGO_CCD=cargo-concordium_${{ env.CARGO_CONCORDIUM_VERSION }}
wget https://distribution.concordium.software/tools/linux/$CARGO_CCD
chmod +x $CARGO_CCD
sudo mv $CARGO_CCD /usr/bin/cargo-concordium
# The 'smart-contract-upgrade' example has a v1 and v2 contract and the tests in v1 needs the wasm module from v2 for upgrading.
- name: Build contract-upgrade version 2 module if needed
if: ${{ matrix.crates == 'examples/smart-contract-upgrade/contract-version1' }}
run: cargo concordium build --out "examples/smart-contract-upgrade/contract-version2/concordium-out/module.wasm.v1" -- --manifest-path "examples/smart-contract-upgrade/contract-version2/Cargo.toml"

- name: Run cargo concordium test
run: cargo concordium test --out "${{ matrix.crates }}/concordium-out/module.wasm.v1" -- --manifest-path "${{ matrix.crates }}/Cargo.toml"
4 changes: 4 additions & 0 deletions concordium-cis2/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased changes

## concordium-cis2 5.1.0 (2023-10-18)

- Derive `PartialEq` and `Eq` for `Cis2Event`, `BalanceOfQueryResponse`, and `OperatorOfQueryResponse`.

## concordium-cis2 5.0.0 (2023-08-21)

- Derive `PartialEq` and `Eq` for the `TransferEvent`, `MintEvent`, `BurnEvent`, `UpdateOperatorEvent`, `TokenMetadataEvent`, `OperatorUpdate`, and `UpdateOperator` types.
Expand Down
2 changes: 1 addition & 1 deletion concordium-cis2/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "concordium-cis2"
version = "5.0.0"
version = "5.1.0"
authors = ["Concordium <[email protected]>"]
edition = "2021"
license = "MPL-2.0"
Expand Down
6 changes: 3 additions & 3 deletions concordium-cis2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ pub struct TokenMetadataEvent<T: IsTokenId> {
}

/// Tagged CIS2 event to be serialized for the event log.
#[derive(Debug, Serialize)]
#[derive(Debug, Serialize, PartialEq, Eq)]
#[concordium(repr(u8))]
pub enum Cis2Event<T: IsTokenId, A: IsTokenAmount> {
/// A transfer between two addresses of some amount of tokens.
Expand Down Expand Up @@ -1161,7 +1161,7 @@ pub struct BalanceOfQueryParams<T: IsTokenId> {
/// The response which is sent back when calling the contract function
/// `balanceOf`.
/// It consists of the list of results corresponding to the list of queries.
#[derive(Debug, Serialize, SchemaType)]
#[derive(Debug, Serialize, SchemaType, PartialEq, Eq)]
#[concordium(transparent)]
pub struct BalanceOfQueryResponse<A: IsTokenAmount>(#[concordium(size_length = 2)] pub Vec<A>);

Expand Down Expand Up @@ -1197,7 +1197,7 @@ pub struct OperatorOfQueryParams {
/// `operatorOf`.
/// It consists of the list of result in the same order and length as the
/// queries in the parameter.
#[derive(Debug, Serialize, SchemaType)]
#[derive(Debug, Serialize, SchemaType, PartialEq, Eq)]
#[concordium(transparent)]
pub struct OperatorOfQueryResponse(#[concordium(size_length = 2)] pub Vec<bool>);

Expand Down
2 changes: 1 addition & 1 deletion concordium-rust-sdk
7 changes: 7 additions & 0 deletions concordium-std/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@

## Unreleased changes

## concordium-std 8.1.0 (2023-10-18)

- Set minimum Rust version to 1.66.
- Fix bug in `StateMap::get_mut`, which allowed multiple mutable references to the state to coexist.
- The signature has changed using `&self` to using `&mut self`.
- Deprecate the `test_infrastructure` module in favour of [concordium-smart-contract-testing](https://docs.rs/concordium-smart-contract-testing).
- Several traits are also deprecated as they are only needed when using the `test_infrastructure` for testing.
- Among the traits are `HasHost`, `HasStateApi`, `HasInitContext`, `HasReceiveContext`.
- They are replaced by concrete types, e.g. `Host`, `StateApi`, etc. in the documentation and nearly all example contracts.
- Add a section in the library documentation about how to migrate your contracts and tests.

## concordium-std 8.0.0 (2023-08-21)

Expand Down
4 changes: 2 additions & 2 deletions concordium-std/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "concordium-std"
version = "8.0.0"
version = "8.1.0"
authors = ["Concordium <[email protected]>"]
edition = "2021"
rust-version = "1.66"
Expand All @@ -23,7 +23,7 @@ getrandom = { version = "0.2", features = ["custom"], optional = true }

[dependencies.concordium-contracts-common]
path = "../concordium-rust-sdk/concordium-base/smart-contracts/contracts-common/concordium-contracts-common"
version = "8.0"
version = "8.1"
default-features = false
features = ["smart-contract"]

Expand Down
Loading

0 comments on commit 461d390

Please sign in to comment.