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

Implement MVP for new off-chain testing engine #712

Merged
merged 37 commits into from
May 10, 2021
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
a693a0b
Add `engine` crate
cmichi Feb 25, 2021
e3ea5e4
Add `env_types` crate
cmichi Feb 25, 2021
eff3ada
Adapt `env`, `lang` and `storage`
cmichi Feb 25, 2021
da08ba7
Adapt examples
cmichi Feb 25, 2021
def45c2
Adapt CI
cmichi Mar 2, 2021
3956a2c
Symlink license and readme
cmichi Mar 2, 2021
a0012e9
Throw `TypedEncoded` out of `engine`
cmichi Mar 3, 2021
606c69b
Improve Erc20
cmichi Mar 3, 2021
6850b4b
Merge branch 'master' into cmichi-implement-new-offchain-engine-mvp
cmichi Mar 3, 2021
9c5f2ba
Bump versions to rc3
cmichi Mar 3, 2021
cc8143d
Fix clippy error: Manual implementation of `Option::map` (#717)
Mar 5, 2021
edab873
Implement comments
cmichi Mar 5, 2021
340185d
Merge branch 'master' into cmichi-implement-new-offchain-engine-mvp
cmichi Mar 16, 2021
cb54a77
Fix yml
cmichi Mar 16, 2021
0e0c044
Improve structure
cmichi Mar 16, 2021
be2b598
Add tests
cmichi Mar 18, 2021
02be20c
Merge branch 'master' into cmichi-implement-new-offchain-engine-mvp
cmichi Mar 19, 2021
46adef3
Fix function signature
cmichi Mar 22, 2021
1caada4
Get rid of `engine`s singleton
cmichi Apr 1, 2021
8a2831a
Revert instantiate stuff
cmichi Apr 13, 2021
c8117a9
Implement review comments
cmichi Apr 12, 2021
da71eea
Make `Storage` non-generic
cmichi Apr 13, 2021
b8ba878
Merge branch 'master' into cmichi-implement-new-offchain-engine-mvp
cmichi Apr 13, 2021
b81e4c2
Improve API for emmitted events
cmichi Apr 13, 2021
bff4609
Migrate to `panic_any`
cmichi Apr 15, 2021
655b425
Merge branch 'master' into cmichi-implement-new-offchain-engine-mvp
cmichi Apr 15, 2021
63da646
Clean up import
cmichi Apr 15, 2021
813301e
Import `panic_any`
cmichi Apr 15, 2021
c651d53
Merge branch 'master' into cmichi-implement-new-offchain-engine-mvp
cmichi Apr 28, 2021
8391f8c
Implement comments
cmichi Apr 28, 2021
863628d
Fix param
cmichi Apr 28, 2021
b5c3688
Use type
cmichi Apr 29, 2021
eafe7ac
Store balances in chain storage
cmichi Apr 29, 2021
8f64f38
Fix tests
cmichi Apr 29, 2021
68734c8
Use individual storage per contract
cmichi Apr 29, 2021
35dd9e6
Implement comments
cmichi May 4, 2021
8fec9ae
Merge branch 'master' into cmichi-implement-new-offchain-engine-mvp
cmichi May 10, 2021
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
26 changes: 26 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ test:
- cargo test --verbose --all-features --no-fail-fast --workspace
- cargo test --verbose --all-features --no-fail-fast --workspace --doc

# Just needed as long as we have the `ink-experimental-engine` feature.
# We do not invoke `--all-features` here -- this would imply the feature
# `ink-experimental-engine`. So in order to still run the tests without the
# experimental engine feature we need this command.
- cargo test --verbose --features std --no-fail-fast --workspace

docs:
stage: workspace
<<: *docker-env
Expand Down Expand Up @@ -179,6 +185,13 @@ codecov:
# RUSTFLAGS are the cause target cache can't be used here
- cargo build --verbose --all-features --workspace
- cargo test --verbose --all-features --no-fail-fast --workspace

# Just needed as long as we have the `ink-experimental-engine` feature.
# We must additionally run the coverage without `--all-features` here -- this
# would imply the feature `ink-experimental-engine`. So in order to still run
# the tests without the experimental engine feature we need this command.
- cargo test --verbose --features std --no-fail-fast --workspace

# coverage with branches
- grcov . --source-dir . --output-type lcov --llvm --branch --ignore-not-existing
--ignore "/*" --ignore "tests/*" --output-path lcov-w-branch.info
Expand Down Expand Up @@ -240,6 +253,19 @@ examples-test:
cargo test --verbose --manifest-path examples/delegator/${contract}/Cargo.toml;
done

examples-test-experimental-engine:
stage: examples
<<: *docker-env
needs:
- job: clippy-std
artifacts: false
script:
# We test only the examples for which the tests have already been migrated to
# use the experimental engine.
- cargo test --no-default-features --features std, ink-experimental-engine --verbose --manifest-path examples/erc20/Cargo.toml
- cargo test --no-default-features --features std, ink-experimental-engine --verbose --manifest-path examples/contract-terminate/Cargo.toml
- cargo test --no-default-features --features std, ink-experimental-engine --verbose --manifest-path examples/contract-transfer/Cargo.toml

examples-fmt:
stage: examples
<<: *docker-env
Expand Down
29 changes: 29 additions & 0 deletions crates/engine/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[package]
name = "ink_engine"
version = "3.0.0-rc3"
authors = ["Parity Technologies <[email protected]>", "Michael Müller <[email protected]>"]
edition = "2018"

license = "Apache-2.0"
readme = "README.md"
repository = "https://github.com/paritytech/ink"
documentation = "https://docs.rs/ink_engine/"
homepage = "https://www.parity.io/"
description = "[ink!] Experimental off-chain environment for testing."
keywords = ["wasm", "parity", "webassembly", "blockchain", "edsl"]
categories = ["no-std", "embedded"]
include = ["Cargo.toml", "src/**/*.rs", "README.md", "LICENSE"]

[dependencies]
scale = { package = "parity-scale-codec", version = "2.0", default-features = false, features = ["derive", "full"] }
derive_more = { version = "0.99", default-features = false, features = ["from", "display"] }

sha2 = { version = "0.9" }
sha3 = { version = "0.9" }
blake2 = { version = "0.9" }

[features]
default = ["std"]
std = [
"scale/std",
]
1 change: 1 addition & 0 deletions crates/engine/LICENSE
1 change: 1 addition & 0 deletions crates/engine/README.md
88 changes: 88 additions & 0 deletions crates/engine/src/exec_context.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// Copyright 2018-2021 Parity Technologies (UK) Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use super::types::{
AccountId,
Balance,
};

/// The context of a contract execution.
#[cfg_attr(test, derive(Debug, PartialEq, Eq))]
pub struct ExecContext {
/// The caller of the contract execution. Might be user or another contract.
///
/// We don't know the specifics of the AccountId ‒ like how many bytes or what
/// type of default `AccountId` makes sense ‒ they are left to be initialized
/// by the crate which uses the `engine`. Methods which require a caller might
/// panic when it has not been set.
pub caller: Option<AccountId>,
/// The callee of the contract execution. Might be user or another contract.
///
/// We don't know the specifics of the AccountId ‒ like how many bytes or what
/// type of default `AccountId` makes sense ‒ they are left to be initialized
/// by the crate which uses the `engine`. Methods which require a callee might
/// panic when it has not been set.
pub callee: Option<AccountId>,
/// The value transferred to the contract as part of the call.
pub value_transferred: Balance,
}

#[allow(clippy::new_without_default)]
impl ExecContext {
/// Creates a new execution context.
pub fn new() -> Self {
Self {
caller: None,
callee: None,
value_transferred: 0,
}
}

/// Returns the callee.
pub fn callee(&self) -> Vec<u8> {
self.callee
.as_ref()
.expect("no callee has been set")
.as_bytes()
.into()
}
cmichi marked this conversation as resolved.
Show resolved Hide resolved

/// Resets the execution context
pub fn reset(&mut self) {
self.caller = None;
self.callee = None;
self.value_transferred = Default::default();
}
}

#[cfg(test)]
mod tests {
use super::{
AccountId,
ExecContext,
};

#[test]
fn basic_operations() {
let mut exec_cont = ExecContext::new();

exec_cont.callee = Some(AccountId::from_bytes(&[13]));
exec_cont.caller = Some(AccountId::from_bytes(&[14]));
exec_cont.value_transferred = 15;
assert_eq!(exec_cont.callee(), vec![13]);

exec_cont.reset();
assert_eq!(exec_cont, ExecContext::new());
}
}
Loading