Skip to content

Commit

Permalink
Replace drink sandbox by internal ink_sandbox (#2158)
Browse files Browse the repository at this point in the history
* Replace drink sandbox by internal ink_sandbox

* fix spellcheck

* Make things less verbose

* fix doc comment

* Update crates/e2e/sandbox/Cargo.toml

Co-authored-by: Michael Müller <michi@parity.io>

* Fix todo

* fix cargo.toml

* Update crates/e2e/sandbox/src/macros.rs

Co-authored-by: Michael Müller <michi@parity.io>

* Update crates/e2e/sandbox/src/macros.rs

Co-authored-by: Michael Müller <michi@parity.io>

* Update crates/e2e/sandbox/src/macros.rs

Co-authored-by: Michael Müller <michi@parity.io>

* Update crates/e2e/sandbox/src/macros.rs

Co-authored-by: Michael Müller <michi@parity.io>

* Update crates/e2e/sandbox/src/macros.rs

Co-authored-by: Michael Müller <michi@parity.io>

* Update crates/e2e/sandbox/src/macros.rs

Co-authored-by: Michael Müller <michi@parity.io>

* Update crates/e2e/sandbox/src/macros.rs

Co-authored-by: Michael Müller <michi@parity.io>

* Apply suggestions from code review

Co-authored-by: Michael Müller <michi@parity.io>

* restore untouched cargo.toml

* fix

* more untouched to restore

* Remove mininal prefix. use DefaultSandbox instead of MinimalSandbox

* Refactor some shared type alias

* Fix macros

* Fixes

* fix dep

* Fix use import

* Move sandbox version to package instead of workspace

---------

Co-authored-by: Michael Müller <michi@parity.io>
  • Loading branch information
pgherveou and cmichi committed Mar 19, 2024
1 parent d16ad5f commit fd4ab57
Show file tree
Hide file tree
Showing 22 changed files with 1,304 additions and 126 deletions.
2 changes: 2 additions & 0 deletions .config/cargo_spellcheck.dic
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,5 @@ KiB
GB
DRink
^
externalities
sandbox_client
79 changes: 21 additions & 58 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ members = [
"crates/allocator",
"crates/e2e",
"crates/e2e/macro",
"crates/e2e/sandbox",
"crates/engine",
"crates/env",
"crates/ink",
Expand Down Expand Up @@ -40,7 +41,6 @@ cfg-if = { version = "1.0" }
contract-build = { version = "4.0.1" }
darling = { version = "0.20.8" }
derive_more = { version = "0.99.17", default-features = false }
drink = { version = "=0.14.0", default-features = false, features = ["std"] }
either = { version = "1.5", default-features = false }
funty = { version = "2.0.0" }
heck = { version = "0.4.0" }
Expand Down Expand Up @@ -81,12 +81,20 @@ wasm-instrument = { version = "0.4.0" }
which = { version = "6.0.0" }
xxhash-rust = { version = "0.8" }
const_env = { version = "0.1"}
wat = { version = "1.0.71" }

# Substrate dependencies
frame-metadata = { version = "16.0.0" }
frame-system = { version = "30.0.0", default-features = false }
frame-support = { version = "30.0.0", default-features = false }
pallet-contracts = { version = "29.0.0", default-features = false }
pallet-balances = { version = "30.0.0", default-features = false }
pallet-timestamp = { version = "29.0.0", default-features = false }
pallet-contracts-uapi = { package = "pallet-contracts-uapi-next", version = "=6.0.3", default-features = false }
pallet-contracts-mock-network = { version = "5.0.0", default-features = false }
sp-externalities = { version = "0.27.0", default-features = false }
sp-io = { version = "32.0.0", default-features = false }
sp-runtime-interface = { version = "26.0.0" }
sp-core = { version = "30.0.0", default-features = false }
sp-keyring = { version = "33.0.0", default-features = false }
sp-runtime = { version = "33.0.0", default-features = false }
Expand Down
1 change: 1 addition & 0 deletions RELEASES_CHECKLIST.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ in the future.
is not necessary.
- We don't want `cargo-release` to create any releases or push any code, we'll do
that manually once we've actually published to `crates.io`.
- Note that `ink_sandbox` has its own version number and can be released separately of the other crates.
3. Check the output of the dry run:
- Does not show any automatic bumping of crate versions.
- Runs without error.
Expand Down
16 changes: 9 additions & 7 deletions crates/e2e/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ ink_primitives = { workspace = true, default-features = true }

cargo_metadata = { workspace = true }
contract-build = { workspace = true }
drink = { workspace = true, optional = true }
ink_sandbox = { path = "./sandbox", optional = true }
pallet-contracts-mock-network = { workspace = true, optional = true }
funty = { workspace = true }
impl-serde = { workspace = true }
Expand Down Expand Up @@ -64,13 +64,15 @@ std = [
"sp-core/std",
"sp-runtime/std",
"sp-weights/std",
"drink?/std",
"ink_e2e_macro/std",
"ink_sandbox/std",
"frame-support/std",
"pallet-contracts-mock-network?/std"
]
drink = [
"dep:drink",
"ink_e2e_macro/drink",
"pallet-contracts-mock-network",
"subxt-metadata",

sandbox = [
"dep:ink_sandbox",
"subxt-metadata",
"pallet-contracts-mock-network",
"ink_e2e_macro/sandbox",
]
4 changes: 2 additions & 2 deletions crates/e2e/macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ quote = { workspace = true }

[dev-dependencies]
ink = { path = "../../ink" }
ink_e2e = { path = "../", features = ["drink"] }
ink_e2e = { path = "../", features = ["sandbox"] }
temp-env = "0.3.6"

[features]
std = []
drink = []
sandbox = []
6 changes: 3 additions & 3 deletions crates/e2e/macro/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl InkE2ETest {
Backend::Node(node_config) => {
build_full_client(&environment, exec_build_contracts, node_config)
}
#[cfg(any(test, feature = "drink"))]
#[cfg(any(test, feature = "sandbox"))]
Backend::RuntimeOnly(runtime) => {
build_runtime_client(exec_build_contracts, runtime.into())
}
Expand Down Expand Up @@ -146,10 +146,10 @@ fn build_full_client(
}
}

#[cfg(any(test, feature = "drink"))]
#[cfg(any(test, feature = "sandbox"))]
fn build_runtime_client(contracts: TokenStream2, runtime: syn::Path) -> TokenStream2 {
quote! {
let contracts = #contracts;
let mut client = ::ink_e2e::DrinkClient::<_, _, #runtime>::new(contracts);
let mut client = ::ink_e2e::SandboxClient::<_, _, #runtime>::new(contracts);
}
}
17 changes: 8 additions & 9 deletions crates/e2e/macro/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ pub enum Backend {

/// The lightweight approach skipping node layer.
///
/// This runs a runtime emulator within `TestExternalities` (using drink! library) in
/// This runs a runtime emulator within `TestExternalities`
/// the same process as the test.
#[cfg(any(test, feature = "drink"))]
#[cfg(any(test, feature = "sandbox"))]
RuntimeOnly(RuntimeOnly),
}

Expand Down Expand Up @@ -61,9 +61,8 @@ impl Node {
}
}

/// The runtime emulator that should be used within `TestExternalities` (using drink!
/// library).
#[cfg(any(test, feature = "drink"))]
/// The runtime emulator that should be used within `TestExternalities`
#[cfg(any(test, feature = "sandbox"))]
#[derive(Clone, Eq, PartialEq, Debug, darling::FromMeta)]
pub enum RuntimeOnly {
#[darling(word)]
Expand All @@ -72,11 +71,11 @@ pub enum RuntimeOnly {
Sandbox(syn::Path),
}

#[cfg(any(test, feature = "drink"))]
#[cfg(any(test, feature = "sandbox"))]
impl From<RuntimeOnly> for syn::Path {
fn from(value: RuntimeOnly) -> Self {
match value {
RuntimeOnly::Default => syn::parse_quote! { ::ink_e2e::MinimalSandbox },
RuntimeOnly::Default => syn::parse_quote! { ::ink_e2e::DefaultSandbox },
RuntimeOnly::Sandbox(path) => path,
}
}
Expand Down Expand Up @@ -151,15 +150,15 @@ mod tests {
#[test]
fn config_works_runtime_only_with_custom_backend() {
let input = quote! {
backend(runtime_only(sandbox = ::ink_e2e::MinimalSandbox)),
backend(runtime_only(sandbox = ::ink_e2e::DefaultSandbox)),
};
let config =
E2EConfig::from_list(&NestedMeta::parse_meta_list(input).unwrap()).unwrap();

assert_eq!(
config.backend(),
Backend::RuntimeOnly(RuntimeOnly::Sandbox(
syn::parse_quote! { ::ink_e2e::MinimalSandbox }
syn::parse_quote! { ::ink_e2e::DefaultSandbox }
))
);
}
Expand Down
41 changes: 41 additions & 0 deletions crates/e2e/sandbox/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
[package]
name = "ink_sandbox"
version = "5.0.0"
authors = ["Cardinal Cryptography", "Parity Technologies <admin@parity.io>"]
edition.workspace = true
license.workspace = true
description = "Sandbox runtime environment for ink! e2e tests"

[dependencies]
frame-metadata = { workspace = true }
frame-support = { workspace = true }
frame-system = { workspace = true }
pallet-balances = { workspace = true }
pallet-contracts = { workspace = true }
pallet-timestamp = { workspace = true }
scale = { workspace = true }
sp-core = { workspace = true }
sp-externalities = { workspace = true }
sp-io = { workspace = true }

paste = { workspace = true }
scale-info = { workspace = true }
wat = { workspace = true }

[features]
default = [
# This is required for the runtime-interface to work properly in the std env.
"std",
]
std = [
"frame-support/std",
"frame-system/std",
"pallet-balances/std",
"pallet-contracts/std",
"pallet-timestamp/std",
"scale/std",
"scale-info/std",
"sp-core/std",
"sp-externalities/std",
"sp-io/std"
]
13 changes: 13 additions & 0 deletions crates/e2e/sandbox/src/api.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
pub mod balance_api;
pub mod contracts_api;
pub mod system_api;
pub mod timestamp_api;

pub mod prelude {
pub use super::{
balance_api::BalanceAPI,
contracts_api::ContractAPI,
system_api::SystemAPI,
timestamp_api::TimestampAPI,
};
}

0 comments on commit fd4ab57

Please sign in to comment.