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 10 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
29 changes: 29 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,26 @@ test:
script:
- cargo test --verbose --all-features --no-fail-fast --workspace

# Just needed as long as we have the `ink-experimental-engine` feature.
# This stage is the same as the above `test`, with the exception that
# 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 have this test.
test-default-features:
stage: workspace
<<: *docker-env
needs:
- job: check-std
artifacts: false
variables:
# Since we run the tests with `--all-features` this implies the feature
# `ink-fuzz-tests` as well -- i.e. the fuzz tests are run.
# There's no way to disable a single feature while enabling all features
# at the same time, hence we use this workaround.
QUICKCHECK_TESTS: 0
script:
- cargo test --verbose --no-fail-fast --workspace

docs:
stage: workspace
<<: *docker-env
Expand Down Expand Up @@ -226,6 +246,15 @@ examples-test:
cargo test --verbose --manifest-path ${example}/Cargo.toml;
done

examples-test-experimental-engine:
stage: examples
<<: *docker-env
needs:
- job: clippy-std
artifacts: false
script:
cargo test --features ink-experimental-engine --verbose --manifest-path erc20/Cargo.toml;
cmichi marked this conversation as resolved.
Show resolved Hide resolved

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

license = "Apache-2.0"
readme = "README.md"
repository = "/~https://github.com/paritytech/ink"
documentation = "https://docs.rs/ink_env/"
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]
ink_env_types = { version = "3.0.0-rc3", path = "../env_types/", default-features = false }
ink_primitives = { version = "3.0.0-rc3", path = "../primitives/", default-features = false }

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"] }
num-traits = { version = "0.2", default-features = false, features = ["i128"] }
paste = "1.0"

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

rand = { version = "0.8", default-features = false, features = ["alloc"], optional = true }
scale-info = { version = "0.6", default-features = false, features = ["derive"], optional = true }

[features]
default = ["std"]
std = [
"ink_env_types/std",
"ink_primitives/std",
"scale/std",
"scale-info",
"scale-info/std",
"rand",
"rand/std",
"rand/std_rng",
"num-traits/std",
]
1 change: 1 addition & 0 deletions crates/engine/LICENSE
1 change: 1 addition & 0 deletions crates/engine/README.md
45 changes: 45 additions & 0 deletions crates/engine/src/accounts.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// 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 crate::test_api::Error;

use super::{
exec_context::OffChainError,
types::OffAccountId,
};

use derive_more::From;

/// Errors encountered upon interacting with the accounts database.
#[derive(Debug, From, PartialEq, Eq)]
pub enum AccountError {
// TODO Decoding(scale::Error),
DecodingFailed,
#[from(ignore)]
UnexpectedUserAccount,
#[from(ignore)]
NoAccountForId(OffAccountId),
}

impl From<AccountError> for Error {
fn from(account_error: AccountError) -> Self {
Error::OffChain(OffChainError::Account(account_error))
}
}

impl From<scale::Error> for AccountError {
fn from(_err: scale::Error) -> Self {
AccountError::DecodingFailed
}
}
62 changes: 62 additions & 0 deletions crates/engine/src/exec_context.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// 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::{
accounts::AccountError,
types::OffAccountId,
Environment,
};

use derive_more::From;

#[derive(Debug, From, PartialEq, Eq)]
pub enum OffChainError {
Account(AccountError),
#[from(ignore)]
UninitializedBlocks,
#[from(ignore)]
UninitializedExecutionContext,
#[from(ignore)]
UnregisteredChainExtension,
}

type Result<T> = core::result::Result<T, OffChainError>;

/// The context of a contract execution.
pub struct ExecContext {
/// The caller of the contract execution.
///
/// Might be user or another contract.
pub caller: OffAccountId,
cmichi marked this conversation as resolved.
Show resolved Hide resolved
/// The callee of the contract execution.
pub callee: OffAccountId,
}

impl ExecContext {
/// Returns the callee.
pub fn callee<T>(&self) -> Result<T::AccountId>
where
T: Environment,
{
// TODO type hell
let callee: Vec<u8> = self.callee.clone();
let res: std::result::Result<T::AccountId, scale::Error> =
scale::Decode::decode(&mut &callee[..]);
let res: std::result::Result<T::AccountId, AccountError> =
res.map_err(AccountError::from);
let res: std::result::Result<T::AccountId, OffChainError> =
res.map_err(Into::into);
res
}
}
Loading