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

Migrate tests for example contracts #347

Merged
merged 44 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
7a081ea
Add type aliases that removes the `Extern` prefix
Bargsteen Sep 19, 2023
d26aaba
Migrate tests and remove generics in init/receive methods
Bargsteen Oct 6, 2023
d0f7cb8
Also include events produced in interrupts
Bargsteen Oct 6, 2023
e87b1d5
Derive PartialEq/Eq
Bargsteen Oct 6, 2023
505f6bf
Update dependency with policy serialization fix
Bargsteen Oct 6, 2023
fac9486
Merge branch 'main' into kb/migrate-tests
Bargsteen Oct 6, 2023
60e14e2
Fix tests in upgrade example contracts
Bargsteen Oct 9, 2023
66e8a32
Use `cargo concordium test` in CI
Bargsteen Oct 9, 2023
20829d5
Also install the wasm target
Bargsteen Oct 9, 2023
59a7cd8
Migrate tests in `default` and `cis2-nft` templates
Bargsteen Oct 9, 2023
f477fdb
Use local dependency before comparing
Bargsteen Oct 9, 2023
ad9c6c8
Conditionally compile v2 upgrade module for v1 testing
Bargsteen Oct 9, 2023
68814b4
Add missing comment in template
Bargsteen Oct 10, 2023
03fba11
Remove some of the crypto-primitive checks in the CI
Bargsteen Oct 10, 2023
0ae9901
Deprecate several traits in favour of the concrete alternatives
Bargsteen Oct 11, 2023
5255446
Deprecate `test_infrastructure` module and update changelog
Bargsteen Oct 12, 2023
a03ecd0
Apply suggestions from code review
Bargsteen Oct 12, 2023
8908edf
Add backlinks
Bargsteen Oct 13, 2023
8d48480
Explain how to run the tests
Bargsteen Oct 13, 2023
1fbff6f
Update changelog
Bargsteen Oct 13, 2023
00d944c
Clarify documentation
Bargsteen Oct 13, 2023
9958e0b
Explain allow deprecated
Bargsteen Oct 13, 2023
39e7575
Download Cargo Concordium instead of building it in CI
Bargsteen Oct 16, 2023
008ee06
Add helper methods for parsing
Bargsteen Oct 16, 2023
39fea88
Use hex formatting of for key and signature
Bargsteen Oct 16, 2023
d902b66
Migrate applicable tests
Bargsteen Oct 17, 2023
218fb31
Update template
Bargsteen Oct 17, 2023
62b38d6
Merge branch 'main' into kb/migrate-tests
Bargsteen Oct 17, 2023
2121c33
Fix formatting
Bargsteen Oct 17, 2023
2d8cc97
Include integration tests
Bargsteen Oct 17, 2023
993d3ee
Run diff on tests
Bargsteen Oct 17, 2023
21037e4
Fix discrepancies and clippy warnings
Bargsteen Oct 17, 2023
949a782
Address review comments
Bargsteen Oct 17, 2023
285bdd2
Fix more diffs
Bargsteen Oct 17, 2023
71ba719
Move with sudo
Bargsteen Oct 17, 2023
f7fd8ce
Readme diffs..
Bargsteen Oct 17, 2023
cfdda63
Merge branch 'kb/migrate-tests' into kb/migrate-docs
Bargsteen Oct 17, 2023
226c8ab
Deprecate `test_infrastructure` and supporting traits (#349)
Bargsteen Oct 17, 2023
e916b1a
Fix references in docs
Bargsteen Oct 18, 2023
3d74d03
Merge branch 'kb/migrate-docs' into kb/migrate-tests
Bargsteen Oct 18, 2023
f9e835b
Bump versions and changelog for release.
abizjak Oct 18, 2023
0419476
Merge branch 'main' into kb/migrate-tests
abizjak Oct 18, 2023
cf298a9
Clippy.
abizjak Oct 18, 2023
ee531fd
Fix templates.
abizjak Oct 18, 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
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"
Bargsteen marked this conversation as resolved.
Show resolved Hide resolved
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)]
Bargsteen marked this conversation as resolved.
Show resolved Hide resolved
#[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
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
Loading