Skip to content

Commit

Permalink
Merge pull request #336 from Concordium/kb/merge-contract-testing-lib
Browse files Browse the repository at this point in the history
Merge contract testing library
  • Loading branch information
Bargsteen authored Sep 18, 2023
2 parents ecef53a + fea3635 commit 7dc481a
Show file tree
Hide file tree
Showing 33 changed files with 8,659 additions and 32 deletions.
106 changes: 106 additions & 0 deletions .github/workflows/linter-testing-lib.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
name: "Testing library: Format, lint, build, and test"

# This job runs:
# - rustfmt
# - clippy linting
# - tests
# for the smart contract testing library.

on:
push:
branches: main

pull_request:
branches: main
types:
- opened
- reopened
- synchronize
- ready_for_review
paths:
- 'contract-testing/**/*.rs'
- 'contract-testing/**/*.toml'
- 'rustfmt.toml'
- 'concordium-rust-sdk'

workflow_dispatch: # allows manual trigger

env:
RUST_FMT: nightly-2023-04-01-x86_64-unknown-linux-gnu
RUST_CLIPPY: 1.66

jobs:
"lint_fmt":
name: ${{ matrix.build-dir }} lint:fmt
# Don't run on draft pull requests
if: ${{ !github.event.pull_request.draft }}
runs-on: ubuntu-latest
strategy:
matrix:
build-dir:
- 'concordium-smart-contract-testing'
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ env.RUST_FMT }}
override: true
components: rustfmt
- name: Format
working-directory: ${{ matrix.build-dir }}
run: |
cargo fmt -- --color=always --check
"lint_clippy":
name: ${{ matrix.build-dir }} lint:clippy
# Don't run on draft pull requests
if: ${{ !github.event.pull_request.draft }}
runs-on: ubuntu-latest
strategy:
matrix:
build-dir:
- 'concordium-smart-contract-testing'
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: recursive
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ env.RUST_CLIPPY }}
override: true
components: clippy
- name: Clippy
working-directory: ${{ matrix.build-dir }}
run: |
git config --global url."https://github.com/".insteadOf "[email protected]:"
cargo clippy --color=always --tests --benches -- -Dclippy::all
"cargo_test":
name: ${{ matrix.build-dir }} cargo:test
runs-on: ubuntu-latest
needs:
- cargo-concordium_cargo_build-bench
strategy:
matrix:
build-dir:
- 'concordium-smart-contract-testing'
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: recursive
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ env.RUST_CLIPPY }}
override: true
- name: Test
working-directory: ${{ matrix.build-dir }}
run: cargo test -- --skip io_tests # Skip the I/O tests in the testing library.
36 changes: 18 additions & 18 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
- name: Checkout sources
uses: actions/checkout@v2
with:
submodules: true
submodules: recursive

- name: Install nightly toolchain with rustfmt available
uses: actions-rs/toolchain@v1
Expand Down Expand Up @@ -86,7 +86,7 @@ jobs:
- name: Checkout sources
uses: actions/checkout@v3
with:
submodules: true
submodules: recursive

- name: Run cargo-generate
# we use v0.17.5 here because the minimal supported version is 0.17.0 and the closest
Expand Down Expand Up @@ -130,7 +130,7 @@ jobs:
- name: Checkout sources
uses: actions/checkout@v3
with:
submodules: true
submodules: recursive

- name: Run cargo-generate
# we use v0.17.5 here because the minimal supported version is 0.17.0 and the closest
Expand Down Expand Up @@ -179,7 +179,7 @@ jobs:
- name: Checkout sources
uses: actions/checkout@v3
with:
submodules: true
submodules: recursive

- name: Run cargo-generate
# we use v0.17.5 here because the minimal supported version is 0.17.0 and the closest
Expand Down Expand Up @@ -231,7 +231,7 @@ jobs:
- name: Checkout sources
uses: actions/checkout@v3
with:
submodules: true
submodules: recursive

- name: Run cargo-generate
# we use v0.17.5 here because the minimal supported version is 0.17.0 and the closest
Expand Down Expand Up @@ -277,7 +277,7 @@ jobs:
- name: Checkout sources
uses: actions/checkout@v3
with:
submodules: true
submodules: recursive

- name: Run cargo-generate
# we use v0.17.5 here because the minimal supported version is 0.17.0 and the closest
Expand Down Expand Up @@ -323,7 +323,7 @@ jobs:
- name: Checkout sources
uses: actions/checkout@v3
with:
submodules: true
submodules: recursive

- name: Run cargo-generate
# at least version 0.17.0 is required for the rhai pre-script to work correctly;
Expand Down Expand Up @@ -375,7 +375,7 @@ jobs:
- name: Checkout sources
uses: actions/checkout@v2
with:
submodules: true
submodules: recursive

- name: Install toolchain with clippy available
uses: actions-rs/toolchain@v1
Expand Down Expand Up @@ -414,7 +414,7 @@ jobs:
- name: Checkout sources
uses: actions/checkout@v2
with:
submodules: true
submodules: recursive

- name: Install toolchain with clippy available
uses: actions-rs/toolchain@v1
Expand Down Expand Up @@ -451,7 +451,7 @@ jobs:
- name: Checkout sources
uses: actions/checkout@v2
with:
submodules: true
submodules: recursive

- name: Install toolchain with clippy available
uses: actions-rs/toolchain@v1
Expand Down Expand Up @@ -490,7 +490,7 @@ jobs:
- name: Checkout sources
uses: actions/checkout@v2
with:
submodules: true
submodules: recursive

- name: Install toolchain with clippy available
uses: actions-rs/toolchain@v1
Expand Down Expand Up @@ -524,7 +524,7 @@ jobs:
- name: Checkout sources
uses: actions/checkout@v2
with:
submodules: true
submodules: recursive

- name: Install nightly toolchain with check available
uses: actions-rs/toolchain@v1
Expand Down Expand Up @@ -566,7 +566,7 @@ jobs:
- name: Checkout sources
uses: actions/checkout@v2
with:
submodules: true
submodules: recursive

- name: Install nightly toolchain with check available
uses: actions-rs/toolchain@v1
Expand Down Expand Up @@ -605,7 +605,7 @@ jobs:
- name: Checkout sources
uses: actions/checkout@v2
with:
submodules: true
submodules: recursive

- name: Install toolchain
uses: actions-rs/toolchain@v1
Expand Down Expand Up @@ -660,7 +660,7 @@ jobs:
- name: Checkout sources
uses: actions/checkout@v2
with:
submodules: true
submodules: recursive

- name: Install toolchain with clippy available
uses: actions-rs/toolchain@v1
Expand Down Expand Up @@ -697,7 +697,7 @@ jobs:
- name: Checkout sources
uses: actions/checkout@v2
with:
submodules: true
submodules: recursive

- name: Install toolchain
uses: actions-rs/toolchain@v1
Expand Down Expand Up @@ -733,7 +733,7 @@ jobs:
- name: Checkout sources
uses: actions/checkout@v2
with:
submodules: true
submodules: recursive

- name: Install toolchain
uses: actions-rs/toolchain@v1
Expand Down Expand Up @@ -790,7 +790,7 @@ jobs:
- name: Checkout sources
uses: actions/checkout@v2
with:
submodules: true
submodules: recursive

- name: Install toolchain
uses: actions-rs/toolchain@v1
Expand Down
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "concordium-contracts-common"]
path = concordium-contracts-common
url = ../concordium-contracts-common.git
[submodule "concordium-rust-sdk"]
path = concordium-rust-sdk
url = ../concordium-rust-sdk.git
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.0-4baaaa.svg)](https://github.com/Concordium/.github/blob/main/.github/CODE_OF_CONDUCT.md)

This repository consists of the core standard library for writing smart
contracts for the Concordium blockchain in the Rust programming languages, as
well as some sample smart contracts. The core library is
[concordium-std](./concordium-std).
This repository consists of libraries for writing and testing smart contracts for the Concordium blockchain in the Rust programming language.
It also contains some sample smart contracts.
The core library is
[concordium-std](./concordium-std), and the testing library is [concordium-smart-contract-testing](./contract-testing).

The core library provides procedural macros to reduce the amount of boilerplate the user needs to write,
while the `concordium-std` library exposes a high-level API that smart contract
Expand Down Expand Up @@ -35,9 +35,9 @@ the logic of the contract is reasonable, or safe.
## Submodules

The repository has
[concordium-contracts-common](https://github.com/Concordium/concordium-contracts-common)
[concordium-rust-sdk](https://github.com/Concordium/concordium-rust-sdk)
as a submodule, and testing and builds are set-up to use the submodule version.
When changes are made in `concordium-contracts-common` they should be propagated
When changes are made in `concordium-rust-sdk` they should be propagated
to this repository.

## Contributing
Expand All @@ -50,7 +50,7 @@ Changes to any of the packages must be such that
- ```cargo clippy --all``` produces no warnings
- ```rustfmt``` makes no changes.

Everything in this repository should build with rust version 1.65 however the `fmt` tool must be from a nightly release since some of the configuration options are not stable. One way to run the `fmt` tool is
Everything in this repository should build with rust version 1.66 however the `fmt` tool must be from a nightly release since some of the configuration options are not stable. One way to run the `fmt` tool is
```
cargo +nightly-2023-04-01 fmt
```
Expand Down
1 change: 0 additions & 1 deletion concordium-contracts-common
Submodule concordium-contracts-common deleted from 9d1f25
1 change: 1 addition & 0 deletions concordium-rust-sdk
Submodule concordium-rust-sdk added at 0a2f89
2 changes: 1 addition & 1 deletion concordium-std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ quickcheck = {version = "1", optional = true }
getrandom = { version = "0.2", features = ["custom"], optional = true }

[dependencies.concordium-contracts-common]
path = "../concordium-contracts-common/concordium-contracts-common"
path = "../concordium-rust-sdk/concordium-base/smart-contracts/contracts-common/concordium-contracts-common"
version = "8.0"
default-features = false
features = ["smart-contract"]
Expand Down
47 changes: 47 additions & 0 deletions contract-testing/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Changelog

## Unreleased changes

- Add functionality for setting the exchange rates and block time of the chain based on queries from an external node.
- Configured via a builder pattern, see `Chain::builder`.
- Add methods to `Chain`:
- `external_query_block` to get the default block used for external queries
- `block_time` to get the block time
- `tick_block_time` to increase the block time by a `Duration`
- Add the following types by re-exporting them from internal crates:
- `BlockHash`
- `Timestamp` which `SlotTime` is an alias of.
- `Duration`
- `Endpoint`
- Add methods to the `Chain` for adding external accounts and contracts and for invoking contracts on an external node.
- See the `Chain` method `contract_invoke_external` for more details.
- Bump minimum supported Rust version to `1.66`.

## 3.0.0

- Support protocol 6 semantics, in particular validation assumes protocol 6
semantics now, allowing sign extension instructions and new operations for
querying account's public keys, and checking signatures with account's keys.
- Add `AccountSignatures` structure.
- Add an `AccountAccessStructure` to the `Account` structure. This is a breaking
change. Extend the constructors of `Account` to allow constructing accounts
with this access structure.

## 2.0.0

- Include `ContractTraceElement`s for failed contract executions, including internal failures.
- Introduce the enum `DebugTraceElement`, which has information about trace elements, including failed ones and the cause of error, and the energy usage.
- On the `ContractInvokeSuccess` type:
- Change the type of the `trace_elements` field to be `Vec<DebugTraceElement>` instead of `Vec<ContractTraceElement>`. (breaking change)
- Add a helper method, `effective_trace_elements()`, to retrieve the "effective" trace elements, i.e., elements that were *not* rolled back.
- These are the elements that were previously returned in the `trace_elements` field.
- There is also a version of the method which clones: `effective_trace_elements_cloned()`.
- To migrate existing code, replace `some_update.trace_elements` with `some_update.effective_trace_elements_cloned()`.
- Add a helper method, `rollbacks_occurred()`, to determine whether any internal failures or rollbacks occurred.
- On the `ContractInvokeError` type:
- Include the field `trace_elements` of type `Vec<DebugTraceElements>` with the trace elements that were hitherto discarded. (breaking change)
- To migrate, include the new field or use `..` when pattern matching on the type.

## 1.0.0

- The initial release of the library.
Loading

0 comments on commit 7dc481a

Please sign in to comment.