diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md index 09b04784294..f1dd032d34b 100644 --- a/ARCHITECTURE.md +++ b/ARCHITECTURE.md @@ -60,11 +60,11 @@ ink! contracts are compiled to RISC-V bytecode for This is how ink! smart contracts are executed on a blockchain: they are uploaded to a blockchain that runs PolkaVM, PolkaVM then interprets them. -As contracts are executed in a sandbox execution environment on the -blockchain itself we compile them to a `no_std` environment. +As contracts are executed in the runtime environment on the +blockchain we compile them to a `no_std` environment. More specifically they are executed by the [`pallet-revive`](https://github.com/paritytech/polkadot-sdk/tree/master/substrate/frame/revive), a module of the Polkadot SDK blockchain framework. This module takes ink! -smart contracts and runs them in a PolkaVM sandbox environment. +smart contracts and runs them in a PolkaVM execution environment. It also provides an API to smart contracts for anything a smart contract needs: storing + retrieving data, calling other contracts, sending value, fetching the block number, …. @@ -250,9 +250,9 @@ most smart-contract-specific events: `Called`, `ContractCodeUpdated, CodeStored` The `Instantiated` event was brought back in a later PR. (5) `pallet-revive` included `revm` as a non-optional dependency. As ink! has to -depend on `pallet-revive` for some features (e.g. sandboxed E2E testing), this +depend on `pallet-revive` for some features (e.g. runtime E2E testing), this results in over 75 more child dependencies having to be build now. This increased -build times for sandboxed E2E tests significantly. +build times for runtime E2E tests significantly. [We proposed](https://github.com/paritytech/polkadot-sdk/pull/9689) putting anything `revm` behind a feature flag, but Parity is not open to it. diff --git a/CHANGELOG.md b/CHANGELOG.md index 70f38c8e610..9dca070c0e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,10 +6,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 [Unreleased] -## Added +### Added - Implements the API for the `pallet-revive` host functions `chain_id`, `balance_of`, `base_fee`, `origin`, `code_size`, `block_hash`, `block_author` - [#2719](https://github.com/use-ink/ink/pull/2719) - Implement `From` for "ink-as-dependency" contract refs - [#2728](https://github.com/use-ink/ink/pull/2728) +### Changed +- Rename `ink_sandbox` crate to `ink_runtime`, `Sandbox` trait to `RuntimeEnv`, and `SandboxClient` to `RuntimeClient` for improved clarity. Also simplifies syntax for e2e tests, both runtime and node e2e tests. + ## Version 6.0.0-beta.1 ### Added diff --git a/Cargo.lock b/Cargo.lock index 008c56d6547..edff413697d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3725,7 +3725,7 @@ dependencies = [ "ink", "ink_e2e", "ink_ir", - "ink_sandbox", + "ink_runtime", "proc-macro2", "quote", "syn 2.0.110", @@ -3938,7 +3938,7 @@ dependencies = [ ] [[package]] -name = "ink_sandbox" +name = "ink_runtime" version = "6.0.0-beta.1" dependencies = [ "frame-metadata", diff --git a/Cargo.toml b/Cargo.toml index 019b3700e97..45eb927c5d6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,7 @@ members = [ "crates/revive-types", "crates/prelude", "crates/primitives", - "crates/sandbox", + "crates/runtime", "crates/storage", "crates/storage/traits" ] @@ -81,7 +81,7 @@ tracing-subscriber = { version = "0.3.20" } trybuild = { version = "1.0.110" } which = { version = "8.0.0" } xxhash-rust = { version = "0.8" } -const_env = { version = "0.1" } +const_env = { version = "0.1.4" } const-hex = { version = "1.17.0", default-features = false } # Substrate dependencies diff --git a/RELEASES_CHECKLIST.md b/RELEASES_CHECKLIST.md index b1e5d22bd48..0c1fee6dcb0 100644 --- a/RELEASES_CHECKLIST.md +++ b/RELEASES_CHECKLIST.md @@ -60,18 +60,18 @@ in the future. - Release `cargo-contract` crates. - Request update of `drink` client, which depends on the `cargo-contract` crates. - Release `ink_e2e`. -1. The `ink_sandbox` crate depends on a git commit of `polkadot-sdk`, hence it +1. The `ink_runtime` crate depends on a git commit of `polkadot-sdk`, hence it currently cannot be published to crates.io. 1. Do a dry run: ```bash fd Cargo.toml crates/ | \ grep -v e2e | \ - grep -v sandbox | \ + grep -v runtime/ | \ xargs -n1 cargo no-dev-deps publish --allow-dirty --dry-run --manifest-path ``` - This command ignores the `e2e` and `sandbox` folder: The `e2e` crates depend on the `cargo-contract/contract-build` + This command ignores the `e2e` and `runtime` folders: The `e2e` crates depend on the `cargo-contract/contract-build` crate, so if you want to publish those, you need to publish `cargo-contract/contract-build` first. - The `sandbox` is ignored, as it depends on some crates via their `git` ref. + The `runtime` is ignored, as it depends on some crates via their `git` ref. It uses [`no-dev-deps`](https://crates.io/crates/cargo-no-dev-deps) for publishing, so that the `dev-dependencies` of ink! are ignored for publishing. They are not needed and due to a cycle it's also not possible to publish with them. diff --git a/crates/e2e/macro/Cargo.toml b/crates/e2e/macro/Cargo.toml index 611ec718b7d..bffbf2dcfca 100644 --- a/crates/e2e/macro/Cargo.toml +++ b/crates/e2e/macro/Cargo.toml @@ -31,7 +31,7 @@ tracing = { workspace = true } [dev-dependencies] ink = { path = "../../ink" } ink_e2e = { path = "../" } -ink_sandbox = { path = "../../sandbox" } +ink_runtime = { path = "../../runtime" } temp-env = "0.3.6" [features] diff --git a/crates/e2e/macro/src/config.rs b/crates/e2e/macro/src/config.rs index 9a0a3714f7a..91ee38b5dd5 100644 --- a/crates/e2e/macro/src/config.rs +++ b/crates/e2e/macro/src/config.rs @@ -12,6 +12,17 @@ // See the License for the specific language governing permissions and // limitations under the License. +use darling::{ + FromMeta, + ast::NestedMeta, +}; +use proc_macro2::TokenStream as TokenStream2; +use syn::{ + Meta, + punctuated::Punctuated, + spanned::Spanned, +}; + /// The type of the architecture that should be used to run test. #[derive(Clone, Eq, PartialEq, Debug, darling::FromMeta)] #[darling(rename_all = "snake_case")] @@ -65,16 +76,16 @@ impl Node { /// The runtime emulator that should be used within `TestExternalities` #[derive(Clone, Eq, PartialEq, Debug, darling::FromMeta)] pub struct RuntimeOnly { - /// The sandbox runtime type (e.g., `ink_sandbox::DefaultSandbox`) - pub sandbox: syn::Path, + /// The runtime type (e.g., `ink_runtime::DefaultRuntime`) + pub runtime: syn::Path, /// The client type implementing the backend traits (e.g., - /// `ink_sandbox::SandboxClient`) + /// `ink_runtime::RuntimeClient`) pub client: syn::Path, } impl RuntimeOnly { pub fn runtime_path(&self) -> syn::Path { - self.sandbox.clone() + self.runtime.clone() } pub fn client_path(&self) -> syn::Path { self.client.clone() @@ -129,25 +140,123 @@ impl E2EConfig { pub fn replace_test_attr(&self) -> Option { self.replace_test_attr.clone() } + + /// Parses the attribute arguments passed to `ink_e2e::test`. + pub fn from_attr_tokens(attr: TokenStream2) -> Result { + let nested_meta = NestedMeta::parse_meta_list(attr)?; + Self::from_nested_meta(nested_meta) + } + + /// Builds the configuration from already parsed meta items. + pub fn from_nested_meta(nested_meta: Vec) -> Result { + let normalized = normalize_runtime_meta(nested_meta)?; + Self::from_list(&normalized).map_err(syn::Error::from) + } +} + +fn normalize_runtime_meta( + nested_meta: Vec, +) -> Result, syn::Error> { + let mut args = Vec::with_capacity(nested_meta.len()); + let mut runtime = None; + + for meta in nested_meta { + if let Some(found) = RuntimeBackendArg::from_nested_meta(&meta)? { + if runtime.replace(found).is_some() { + return Err(syn::Error::new( + meta.span(), + "only a single `runtime` attribute is allowed", + )); + } + continue; + } + args.push(meta); + } + + if let Some(runtime) = runtime { + args.push(runtime.into_backend_meta()); + } + + Ok(args) +} + +struct RuntimeBackendArg { + runtime: Option, +} + +impl RuntimeBackendArg { + fn from_nested_meta(meta: &NestedMeta) -> Result, syn::Error> { + let meta = match meta { + NestedMeta::Meta(meta) if meta.path().is_ident("runtime") => meta, + _ => return Ok(None), + }; + + match meta { + Meta::Path(_) => Ok(Some(Self { runtime: None })), + Meta::List(list) => { + let nested: Punctuated = + list.parse_args_with(Punctuated::parse_terminated)?; + if nested.len() != 1 { + return Err(syn::Error::new( + list.span(), + "`runtime` expects zero or one runtime type", + )); + } + match nested.first().unwrap() { + NestedMeta::Meta(Meta::Path(path)) => { + Ok(Some(Self { + runtime: Some(path.clone()), + })) + } + other => { + Err(syn::Error::new( + other.span(), + "`runtime` expects a runtime type path", + )) + } + } + } + Meta::NameValue(name_value) => { + Err(syn::Error::new( + name_value.span(), + "`runtime` does not support name-value pairs", + )) + } + } + } + + fn runtime(&self) -> syn::Path { + self.runtime + .clone() + .unwrap_or_else(|| syn::parse_quote! { ::ink_runtime::DefaultRuntime }) + } + + fn into_backend_meta(self) -> NestedMeta { + let runtime = self.runtime(); + syn::parse_quote! { + backend(runtime_only(runtime = #runtime, client = ::ink_runtime::RuntimeClient)) + } + } } #[cfg(test)] mod tests { use super::*; - use darling::{ - FromMeta, - ast::NestedMeta, - }; + use darling::ast::NestedMeta; use quote::quote; + fn parse_config(input: TokenStream2) -> E2EConfig { + let nested = NestedMeta::parse_meta_list(input).unwrap(); + E2EConfig::from_nested_meta(nested).unwrap() + } + #[test] fn config_works_backend_runtime_only() { let input = quote! { environment = crate::CustomEnvironment, - backend(runtime_only(sandbox = ::ink_sandbox::DefaultSandbox, client = ::ink_sandbox::SandboxClient)), + backend(runtime_only(runtime = ::ink_runtime::DefaultRuntime, client = ::ink_runtime::RuntimeClient)), }; - let config = - E2EConfig::from_list(&NestedMeta::parse_meta_list(input).unwrap()).unwrap(); + let config = parse_config(input); assert_eq!( config.environment(), @@ -157,26 +266,25 @@ mod tests { assert_eq!( config.backend(), Backend::RuntimeOnly(RuntimeOnly { - sandbox: syn::parse_quote! { ::ink_sandbox::DefaultSandbox }, - client: syn::parse_quote! { ::ink_sandbox::SandboxClient }, + runtime: syn::parse_quote! { ::ink_runtime::DefaultRuntime }, + client: syn::parse_quote! { ::ink_runtime::RuntimeClient }, }) ); } #[test] - #[should_panic(expected = "ErrorUnknownField")] + #[should_panic(expected = "Unknown field")] fn config_backend_runtime_only_default_not_allowed() { let input = quote! { backend(runtime_only(default)), }; - let config = - E2EConfig::from_list(&NestedMeta::parse_meta_list(input).unwrap()).unwrap(); + let config = parse_config(input); assert_eq!( config.backend(), Backend::RuntimeOnly(RuntimeOnly { - sandbox: syn::parse_quote! { ::ink_sandbox::DefaultSandbox }, - client: syn::parse_quote! { ::ink_sandbox::SandboxClient }, + runtime: syn::parse_quote! { ::ink_runtime::DefaultRuntime }, + client: syn::parse_quote! { ::ink_runtime::RuntimeClient }, }) ); } @@ -184,16 +292,43 @@ mod tests { #[test] fn config_works_runtime_only_with_custom_backend() { let input = quote! { - backend(runtime_only(sandbox = ::ink_sandbox::DefaultSandbox, client = ::ink_sandbox::SandboxClient)), + backend(runtime_only(runtime = ::ink_runtime::DefaultRuntime, client = ::ink_runtime::RuntimeClient)), }; - let config = - E2EConfig::from_list(&NestedMeta::parse_meta_list(input).unwrap()).unwrap(); + let config = parse_config(input); + + assert_eq!( + config.backend(), + Backend::RuntimeOnly(RuntimeOnly { + runtime: syn::parse_quote! { ::ink_runtime::DefaultRuntime }, + client: syn::parse_quote! { ::ink_runtime::RuntimeClient }, + }) + ); + } + + #[test] + fn runtime_keyword_defaults() { + let input = quote! { runtime }; + let config = parse_config(input); + + assert_eq!( + config.backend(), + Backend::RuntimeOnly(RuntimeOnly { + runtime: syn::parse_quote! { ::ink_runtime::DefaultRuntime }, + client: syn::parse_quote! { ::ink_runtime::RuntimeClient }, + }) + ); + } + + #[test] + fn runtime_keyword_custom_runtime() { + let input = quote! { runtime(crate::CustomRuntime) }; + let config = parse_config(input); assert_eq!( config.backend(), Backend::RuntimeOnly(RuntimeOnly { - sandbox: syn::parse_quote! { ::ink_sandbox::DefaultSandbox }, - client: syn::parse_quote! { ::ink_sandbox::SandboxClient }, + runtime: syn::parse_quote! { crate::CustomRuntime }, + client: syn::parse_quote! { ::ink_runtime::RuntimeClient }, }) ); } @@ -203,8 +338,7 @@ mod tests { let input = quote! { backend(node), }; - let config = - E2EConfig::from_list(&NestedMeta::parse_meta_list(input).unwrap()).unwrap(); + let config = parse_config(input); assert_eq!(config.backend(), Backend::Node(Node::Auto)); @@ -231,13 +365,12 @@ mod tests { } #[test] - #[should_panic(expected = "ErrorUnknownField")] + #[should_panic(expected = "Unknown field")] fn config_backend_node_auto_not_allowed() { let input = quote! { backend(node(auto)), }; - let config = - E2EConfig::from_list(&NestedMeta::parse_meta_list(input).unwrap()).unwrap(); + let config = parse_config(input); assert_eq!(config.backend(), Backend::Node(Node::Auto)); } @@ -247,8 +380,7 @@ mod tests { let input = quote! { backend(node(url = "ws://0.0.0.0:9999")), }; - let config = - E2EConfig::from_list(&NestedMeta::parse_meta_list(input).unwrap()).unwrap(); + let config = parse_config(input); match config.backend() { Backend::Node(node_config) => { @@ -277,8 +409,7 @@ mod tests { let input = quote! { replace_test_attr = "#[quickcheck]" }; - let config = - E2EConfig::from_list(&NestedMeta::parse_meta_list(input).unwrap()).unwrap(); + let config = parse_config(input); assert_eq!(config.replace_test_attr(), Some("#[quickcheck]".to_owned())); } diff --git a/crates/e2e/macro/src/ir.rs b/crates/e2e/macro/src/ir.rs index 7cbc623e08b..0b92ec9a2c0 100644 --- a/crates/e2e/macro/src/ir.rs +++ b/crates/e2e/macro/src/ir.rs @@ -13,10 +13,6 @@ // limitations under the License. use crate::config::E2EConfig; -use darling::{ - FromMeta, - ast::NestedMeta, -}; use proc_macro2::TokenStream as TokenStream2; /// The End-to-End test with all required information. @@ -38,7 +34,7 @@ impl InkE2ETest { /// Returns `Ok` if the test matches all requirements for an /// ink! E2E test definition. pub fn new(attrs: TokenStream2, input: TokenStream2) -> Result { - let e2e_config = E2EConfig::from_list(&NestedMeta::parse_meta_list(attrs)?)?; + let e2e_config = E2EConfig::from_attr_tokens(attrs)?; let item_fn = syn::parse2::(input)?; let e2e_fn = E2EFn::from(item_fn); Ok(Self { diff --git a/crates/e2e/macro/src/lib.rs b/crates/e2e/macro/src/lib.rs index 1d79b1992e7..7f65bc2a64a 100644 --- a/crates/e2e/macro/src/lib.rs +++ b/crates/e2e/macro/src/lib.rs @@ -60,12 +60,15 @@ use syn::Result; /// ``` /// type E2EResult = std::result::Result>; /// -/// #[ink_sandbox::test(backend(runtime_only(sandbox = ink_sandbox::DefaultSandbox, client = ink_sandbox::SandboxClient)))] -/// async fn runtime_call_works() -> E2EResult<()> { +/// #[ink_e2e::test(runtime)] +/// async fn runtime_call_works(mut client: Client) -> E2EResult<()> { /// // ... /// } /// ``` /// +/// This defaults to `ink_runtime::DefaultRuntime` together with the built-in +/// `ink_runtime::RuntimeClient`. +/// /// In this configuration the test will not run against a node that is running in the /// background, but against an in-process slimmed down `pallet-revive` execution /// environment. @@ -74,6 +77,15 @@ use syn::Result; /// in our documentation for more details. /// For a full example [see here](https://github.com/use-ink/ink-examples/tree/v5.x.x/e2e-runtime-only-backend). /// +/// You can also provide a custom runtime: +/// +/// ``` +/// #[ink_e2e::test(runtime(crate::CustomRuntime))] +/// async fn runtime_call_works(mut client: Client) -> E2EResult<()> { +/// // ... +/// } +/// ``` +/// /// # Example /// /// ``` diff --git a/crates/primitives/src/types.rs b/crates/primitives/src/types.rs index 8ba31f45f21..1f9fa419e8d 100644 --- a/crates/primitives/src/types.rs +++ b/crates/primitives/src/types.rs @@ -401,7 +401,7 @@ pub enum DefaultEnvironment {} impl Environment for DefaultEnvironment { // This number was chosen as it's also what `pallet-revive` // chooses by default. It's also the number present in the - // `ink_sandbox` and the `ink-node`. + // `ink_runtime` and the `ink-node`. const NATIVE_TO_ETH_RATIO: u32 = 100_000_000; // These const's correspond to the settings of Asset Hub and diff --git a/crates/sandbox/Cargo.toml b/crates/runtime/Cargo.toml similarity index 95% rename from crates/sandbox/Cargo.toml rename to crates/runtime/Cargo.toml index 7b442fec60c..f72fcc644d7 100644 --- a/crates/sandbox/Cargo.toml +++ b/crates/runtime/Cargo.toml @@ -1,12 +1,12 @@ [package] -name = "ink_sandbox" +name = "ink_runtime" version = "6.0.0-beta.1" authors = ["Use Ink ", "Cardinal Cryptography"] edition.workspace = true license.workspace = true -description = "Sandbox runtime environment for ink! e2e tests" +description = "Runtime environment for ink! e2e tests" repository.workspace = true -documentation = "https://docs.rs/ink_sandbox" +documentation = "https://docs.rs/ink_runtime" homepage.workspace = true [dependencies] diff --git a/crates/sandbox/src/api.rs b/crates/runtime/src/api.rs similarity index 100% rename from crates/sandbox/src/api.rs rename to crates/runtime/src/api.rs diff --git a/crates/sandbox/src/api/assets_api.rs b/crates/runtime/src/api/assets_api.rs similarity index 79% rename from crates/sandbox/src/api/assets_api.rs rename to crates/runtime/src/api/assets_api.rs index d198d89833a..3bb103e96eb 100644 --- a/crates/sandbox/src/api/assets_api.rs +++ b/crates/runtime/src/api/assets_api.rs @@ -1,7 +1,7 @@ use crate::{ AccountIdFor, IntoAccountId, - Sandbox, + RuntimeEnv, }; use frame_support::{ pallet_prelude::DispatchError, @@ -23,12 +23,12 @@ use frame_support::{ type AssetIdOf = >::AssetId; type AssetBalanceOf = >::Balance; -/// Assets API for the sandbox. +/// Assets API for the runtime. /// /// Provides methods to create, mint, and manage assets in `pallet-assets`. pub trait AssetsAPI where - T: Sandbox, + T: RuntimeEnv, T::Runtime: pallet_assets::Config, I: 'static, { @@ -168,7 +168,7 @@ where impl AssetsAPI for T where - T: Sandbox, + T: RuntimeEnv, T::Runtime: pallet_assets::Config, I: 'static, { @@ -323,56 +323,56 @@ where #[cfg(test)] mod tests { use super::*; - use crate::DefaultSandbox; + use crate::DefaultRuntime; #[test] fn create_works() { - let mut sandbox = DefaultSandbox::default(); - let admin = DefaultSandbox::default_actor(); + let mut runtime = DefaultRuntime::default(); + let admin = DefaultRuntime::default_actor(); let asset_id = 1u32; let min_balance = 1u128; - let result = sandbox.create(&asset_id, &admin, min_balance); + let result = runtime.create(&asset_id, &admin, min_balance); assert!(result.is_ok()); - assert!(sandbox.asset_exists(&asset_id)); + assert!(runtime.asset_exists(&asset_id)); } #[test] fn set_metadata_works() { - let mut sandbox = DefaultSandbox::default(); - let admin = DefaultSandbox::default_actor(); + let mut runtime = DefaultRuntime::default(); + let admin = DefaultRuntime::default_actor(); let asset_id = 1u32; - sandbox.create(&asset_id, &admin, 1u128).unwrap(); + runtime.create(&asset_id, &admin, 1u128).unwrap(); let name = b"Test Token".to_vec(); let symbol = b"TEST".to_vec(); let decimals = 18u8; - let result = sandbox.set_metadata(&asset_id, &admin, name, symbol, decimals); + let result = runtime.set_metadata(&asset_id, &admin, name, symbol, decimals); assert!(result.is_ok()); } #[test] fn metadata_works() { - let mut sandbox = DefaultSandbox::default(); - let admin = DefaultSandbox::default_actor(); + let mut runtime = DefaultRuntime::default(); + let admin = DefaultRuntime::default_actor(); let asset_id = 1u32; - sandbox.create(&asset_id, &admin, 1u128).unwrap(); + runtime.create(&asset_id, &admin, 1u128).unwrap(); let name = b"Test Token".to_vec(); let symbol = b"TEST".to_vec(); let decimals = 18u8; - sandbox + runtime .set_metadata(&asset_id, &admin, name.clone(), symbol.clone(), decimals) .unwrap(); let (retrieved_name, retrieved_symbol, retrieved_decimals) = - sandbox.metadata(&asset_id); + runtime.metadata(&asset_id); assert_eq!(retrieved_name, name); assert_eq!(retrieved_symbol, symbol); @@ -381,64 +381,64 @@ mod tests { #[test] fn approve_works() { - let mut sandbox = DefaultSandbox::default(); - let admin = DefaultSandbox::default_actor(); + let mut runtime = DefaultRuntime::default(); + let admin = DefaultRuntime::default_actor(); let spender = ink_e2e::bob().into_account_id(); let asset_id = 1u32; - sandbox.create(&asset_id, &admin, 1u128).unwrap(); - sandbox.mint_into(&asset_id, &admin, 1000u128).unwrap(); + runtime.create(&asset_id, &admin, 1u128).unwrap(); + runtime.mint_into(&asset_id, &admin, 1000u128).unwrap(); - let allowance_before = sandbox.allowance(&asset_id, &admin, &spender); + let allowance_before = runtime.allowance(&asset_id, &admin, &spender); assert_eq!(allowance_before, 0); - let result = sandbox.approve(&asset_id, &admin, &spender, 500u128); + let result = runtime.approve(&asset_id, &admin, &spender, 500u128); assert!(result.is_ok()); - let allowance_after = sandbox.allowance(&asset_id, &admin, &spender); + let allowance_after = runtime.allowance(&asset_id, &admin, &spender); assert_eq!(allowance_after, 500); } #[test] fn mint_into_works() { - let mut sandbox = DefaultSandbox::default(); - let admin = DefaultSandbox::default_actor(); + let mut runtime = DefaultRuntime::default(); + let admin = DefaultRuntime::default_actor(); let asset_id = 1u32; - sandbox.create(&asset_id, &admin, 1u128).unwrap(); + runtime.create(&asset_id, &admin, 1u128).unwrap(); - let balance_before = sandbox.balance_of(&asset_id, &admin); + let balance_before = runtime.balance_of(&asset_id, &admin); assert_eq!(balance_before, 0); - sandbox.mint_into(&asset_id, &admin, 100u128).unwrap(); + runtime.mint_into(&asset_id, &admin, 100u128).unwrap(); - let balance_after = sandbox.balance_of(&asset_id, &admin); + let balance_after = runtime.balance_of(&asset_id, &admin); assert_eq!(balance_after, 100); } #[test] fn transfer_works() { - let mut sandbox = DefaultSandbox::default(); - let admin = DefaultSandbox::default_actor(); + let mut runtime = DefaultRuntime::default(); + let admin = DefaultRuntime::default_actor(); let recipient = ink_e2e::bob().into_account_id(); let asset_id = 1u32; - sandbox.create(&asset_id, &admin, 1u128).unwrap(); - sandbox.mint_into(&asset_id, &admin, 1000u128).unwrap(); + runtime.create(&asset_id, &admin, 1u128).unwrap(); + runtime.mint_into(&asset_id, &admin, 1000u128).unwrap(); - let admin_balance_before = sandbox.balance_of(&asset_id, &admin); - let recipient_balance_before = sandbox.balance_of(&asset_id, &recipient); + let admin_balance_before = runtime.balance_of(&asset_id, &admin); + let recipient_balance_before = runtime.balance_of(&asset_id, &recipient); assert_eq!(admin_balance_before, 1000); assert_eq!(recipient_balance_before, 0); - let result = sandbox.transfer(&asset_id, &admin, &recipient, 300u128); + let result = runtime.transfer(&asset_id, &admin, &recipient, 300u128); assert!(result.is_ok()); - let admin_balance_after = sandbox.balance_of(&asset_id, &admin); - let recipient_balance_after = sandbox.balance_of(&asset_id, &recipient); + let admin_balance_after = runtime.balance_of(&asset_id, &admin); + let recipient_balance_after = runtime.balance_of(&asset_id, &recipient); assert_eq!(admin_balance_after, 700); assert_eq!(recipient_balance_after, 300); @@ -446,68 +446,68 @@ mod tests { #[test] fn balance_of_works() { - let mut sandbox = DefaultSandbox::default(); - let admin = DefaultSandbox::default_actor(); + let mut runtime = DefaultRuntime::default(); + let admin = DefaultRuntime::default_actor(); let asset_id = 1u32; - sandbox.create(&asset_id, &admin, 1u128).unwrap(); + runtime.create(&asset_id, &admin, 1u128).unwrap(); - let balance = sandbox.balance_of(&asset_id, &admin); + let balance = runtime.balance_of(&asset_id, &admin); assert_eq!(balance, 0); - sandbox.mint_into(&asset_id, &admin, 500u128).unwrap(); + runtime.mint_into(&asset_id, &admin, 500u128).unwrap(); - let balance = sandbox.balance_of(&asset_id, &admin); + let balance = runtime.balance_of(&asset_id, &admin); assert_eq!(balance, 500); } #[test] fn total_supply_works() { - let mut sandbox = DefaultSandbox::default(); - let admin = DefaultSandbox::default_actor(); + let mut runtime = DefaultRuntime::default(); + let admin = DefaultRuntime::default_actor(); let asset_id = 1u32; - sandbox.create(&asset_id, &admin, 1u128).unwrap(); + runtime.create(&asset_id, &admin, 1u128).unwrap(); - let supply_before = sandbox.total_supply(&asset_id); + let supply_before = runtime.total_supply(&asset_id); assert_eq!(supply_before, 0); - sandbox.mint_into(&asset_id, &admin, 1000u128).unwrap(); + runtime.mint_into(&asset_id, &admin, 1000u128).unwrap(); - let supply_after = sandbox.total_supply(&asset_id); + let supply_after = runtime.total_supply(&asset_id); assert_eq!(supply_after, 1000); } #[test] fn allowance_works() { - let mut sandbox = DefaultSandbox::default(); - let admin = DefaultSandbox::default_actor(); + let mut runtime = DefaultRuntime::default(); + let admin = DefaultRuntime::default_actor(); let spender = ink_e2e::bob().into_account_id(); let asset_id = 1u32; - sandbox.create(&asset_id, &admin, 1u128).unwrap(); + runtime.create(&asset_id, &admin, 1u128).unwrap(); - let allowance = sandbox.allowance(&asset_id, &admin, &spender); + let allowance = runtime.allowance(&asset_id, &admin, &spender); assert_eq!(allowance, 0); - sandbox + runtime .approve(&asset_id, &admin, &spender, 250u128) .unwrap(); - let allowance = sandbox.allowance(&asset_id, &admin, &spender); + let allowance = runtime.allowance(&asset_id, &admin, &spender); assert_eq!(allowance, 250); } #[test] fn asset_exists_works() { - let mut sandbox = DefaultSandbox::default(); - let admin = DefaultSandbox::default_actor(); + let mut runtime = DefaultRuntime::default(); + let admin = DefaultRuntime::default_actor(); let asset_id = 1u32; - assert!(!sandbox.asset_exists(&asset_id)); + assert!(!runtime.asset_exists(&asset_id)); - sandbox.create(&asset_id, &admin, 1u128).unwrap(); + runtime.create(&asset_id, &admin, 1u128).unwrap(); - assert!(sandbox.asset_exists(&asset_id)); + assert!(runtime.asset_exists(&asset_id)); } } diff --git a/crates/sandbox/src/api/balance_api.rs b/crates/runtime/src/api/balance_api.rs similarity index 86% rename from crates/sandbox/src/api/balance_api.rs rename to crates/runtime/src/api/balance_api.rs index 8bbc0f0a30d..d74872c590f 100644 --- a/crates/sandbox/src/api/balance_api.rs +++ b/crates/runtime/src/api/balance_api.rs @@ -1,7 +1,7 @@ use crate::{ AccountIdFor, OriginFor, - Sandbox, + RuntimeEnv, }; use frame_support::{ sp_runtime::DispatchError, @@ -11,10 +11,10 @@ use pallet_revive::sp_runtime::traits::StaticLookup; type BalanceOf = ::Balance; -/// Balance API for the sandbox. -pub trait BalanceAPI +/// Balance API for the runtime. +pub trait BalanceAPI where - T: Sandbox, + T: RuntimeEnv, T::Runtime: pallet_balances::Config, { /// Mint tokens to an account. @@ -49,7 +49,7 @@ where impl BalanceAPI for T where - T: Sandbox, + T: RuntimeEnv, T::Runtime: pallet_balances::Config, { fn mint_into( @@ -96,18 +96,18 @@ where #[cfg(test)] mod test { use super::*; - use crate::DefaultSandbox; + use crate::DefaultRuntime; #[test] fn mint_works() { - let mut sandbox = DefaultSandbox::default(); - let balance = sandbox.free_balance(&DefaultSandbox::default_actor()); + let mut runtime = DefaultRuntime::default(); + let balance = runtime.free_balance(&DefaultRuntime::default_actor()); - sandbox - .mint_into(&DefaultSandbox::default_actor(), 100) + runtime + .mint_into(&DefaultRuntime::default_actor(), 100) .unwrap(); assert_eq!( - sandbox.free_balance(&DefaultSandbox::default_actor()), + runtime.free_balance(&DefaultRuntime::default_actor()), balance + 100 ); } diff --git a/crates/sandbox/src/api/revive_api.rs b/crates/runtime/src/api/revive_api.rs similarity index 87% rename from crates/sandbox/src/api/revive_api.rs rename to crates/runtime/src/api/revive_api.rs index 37b08500964..73af49d6b2e 100644 --- a/crates/sandbox/src/api/revive_api.rs +++ b/crates/runtime/src/api/revive_api.rs @@ -3,7 +3,7 @@ use crate::{ ContractExecResultFor, ContractResultInstantiate, H256, - Sandbox, + RuntimeEnv, balance_to_evm_value, }; use frame_support::{ @@ -156,13 +156,13 @@ pub trait ContractAPI { impl ContractAPI for T where - T: Sandbox, + T: RuntimeEnv, T::Runtime: pallet_balances::Config + pallet_revive::Config, BalanceOf: Into + TryFrom + Bounded, MomentOf: Into, - <::Runtime as frame_system::Config>::Nonce: Into, + <::Runtime as frame_system::Config>::Nonce: Into, // todo - <::Runtime as frame_system::Config>::Hash: + <::Runtime as frame_system::Config>::Hash: frame_support::traits::IsType, { type T = T::Runtime; @@ -311,7 +311,7 @@ pub fn decode_debug_buffer(buffer: &[u8]) -> Vec { mod tests { use super::*; use crate::{ - DefaultSandbox, + DefaultRuntime, RuntimeEventOf, api::prelude::*, }; @@ -336,23 +336,23 @@ mod tests { /// /// This function funds the account with the existential deposit /// (i.e. minimum balance). - fn warm_up(sandbox: &mut T) + fn warm_up(runtime: &mut T) where - ::Runtime: pallet_revive::Config + pallet_balances::Config, - T: BalanceAPI + Sandbox, + ::Runtime: pallet_revive::Config + pallet_balances::Config, + T: BalanceAPI + RuntimeEnv, { - let acc = pallet_revive::Pallet::<::Runtime>::account_id(); - let ed = pallet_balances::Pallet::<::Runtime>::minimum_balance(); - sandbox.mint_into(&acc, ed).unwrap_or_else(|_| { + let acc = pallet_revive::Pallet::<::Runtime>::account_id(); + let ed = pallet_balances::Pallet::<::Runtime>::minimum_balance(); + runtime.mint_into(&acc, ed).unwrap_or_else(|_| { panic!("Failed to mint existential balance into `pallet-revive` account") }); } #[test] fn can_upload_code() { - let mut sandbox = DefaultSandbox::default(); + let mut runtime = DefaultRuntime::default(); let contract_binary = compile_module("dummy"); - warm_up::(&mut sandbox); + warm_up::(&mut runtime); use sha3::{ Digest, @@ -362,8 +362,8 @@ mod tests { let hash = H256::from_slice(hash.as_slice()); let origin = - DefaultSandbox::convert_account_to_origin(DefaultSandbox::default_actor()); - let result = sandbox.upload_contract(contract_binary, origin, 100000000000000); + DefaultRuntime::convert_account_to_origin(DefaultRuntime::default_actor()); + let result = runtime.upload_contract(contract_binary, origin, 100000000000000); assert!(result.is_ok()); assert_eq!(hash, result.unwrap().code_hash); @@ -371,37 +371,37 @@ mod tests { #[test] fn can_deploy_contract() { - let mut sandbox = DefaultSandbox::default(); + let mut runtime = DefaultRuntime::default(); let contract_binary = compile_module("dummy"); - let events_before = sandbox.events(); + let events_before = runtime.events(); assert!(events_before.is_empty()); - warm_up::(&mut sandbox); + warm_up::(&mut runtime); - let default_actor = DefaultSandbox::default_actor(); - sandbox.map_account(&default_actor).expect("cannot map"); - let origin = DefaultSandbox::convert_account_to_origin(default_actor); - let result = sandbox.deploy_contract( + let default_actor = DefaultRuntime::default_actor(); + runtime.map_account(&default_actor).expect("cannot map"); + let origin = DefaultRuntime::convert_account_to_origin(default_actor); + let result = runtime.deploy_contract( contract_binary.clone(), 0, vec![], None, origin.clone(), - DefaultSandbox::default_gas_limit(), + DefaultRuntime::default_gas_limit(), 100000000000000, ); assert!(result.result.is_ok()); assert!(!result.result.unwrap().result.did_revert()); // deploying again must fail due to `DuplicateContract` - let result = sandbox.deploy_contract( + let result = runtime.deploy_contract( contract_binary, 0, vec![], None, origin, - DefaultSandbox::default_gas_limit(), + DefaultRuntime::default_gas_limit(), 100000000000000, ); assert!(result.result.is_err()); @@ -411,45 +411,45 @@ mod tests { #[test] fn can_call_contract() { - let mut sandbox = DefaultSandbox::default(); - let _actor = DefaultSandbox::default_actor(); + let mut runtime = DefaultRuntime::default(); + let _actor = DefaultRuntime::default_actor(); let contract_binary = compile_module("dummy"); - warm_up::(&mut sandbox); + warm_up::(&mut runtime); - let default_actor = DefaultSandbox::default_actor(); - sandbox.map_account(&default_actor).expect("unable to map"); - let origin = DefaultSandbox::convert_account_to_origin(default_actor); - let result = sandbox.deploy_contract( + let default_actor = DefaultRuntime::default_actor(); + runtime.map_account(&default_actor).expect("unable to map"); + let origin = DefaultRuntime::convert_account_to_origin(default_actor); + let result = runtime.deploy_contract( contract_binary, 0, vec![], None, origin.clone(), - DefaultSandbox::default_gas_limit(), + DefaultRuntime::default_gas_limit(), STORAGE_DEPOSIT_LIMIT, ); assert!(!result.result.clone().unwrap().result.did_revert()); let contract_address = result.result.expect("Contract should be deployed").addr; - sandbox.reset_events(); + runtime.reset_events(); - let result = sandbox.call_contract( + let result = runtime.call_contract( contract_address, 0, vec![], origin.clone(), - DefaultSandbox::default_gas_limit(), + DefaultRuntime::default_gas_limit(), STORAGE_DEPOSIT_LIMIT, ); assert!(result.result.is_ok()); assert!(!result.result.unwrap().did_revert()); - let events = sandbox.events(); + let events = runtime.events(); assert_eq!(events.len(), 1); assert_eq!( events[0].event, - RuntimeEventOf::::Revive( + RuntimeEventOf::::Revive( pallet_revive::Event::ContractEmitted { contract: contract_address, topics: vec![H256::from([42u8; 32])], diff --git a/crates/sandbox/src/api/system_api.rs b/crates/runtime/src/api/system_api.rs similarity index 68% rename from crates/sandbox/src/api/system_api.rs rename to crates/runtime/src/api/system_api.rs index 80a7cdf53a4..23ce373c7ee 100644 --- a/crates/sandbox/src/api/system_api.rs +++ b/crates/runtime/src/api/system_api.rs @@ -1,7 +1,7 @@ use crate::{ EventRecordOf, RuntimeCall, - Sandbox, + RuntimeEnv, }; use frame_support::sp_runtime::{ DispatchResultWithInfo, @@ -12,7 +12,7 @@ use frame_support::sp_runtime::{ }; use frame_system::pallet_prelude::BlockNumberFor; -/// System API for the sandbox. +/// System API for the runtime. pub trait SystemAPI { /// The runtime system config. type T: frame_system::Config; @@ -51,7 +51,7 @@ pub trait SystemAPI { impl SystemAPI for T where - T: Sandbox, + T: RuntimeEnv, T::Runtime: frame_system::Config, { type T = T::Runtime; @@ -100,11 +100,11 @@ where #[cfg(test)] mod tests { use crate::{ - DefaultSandbox, + DefaultRuntime, RuntimeCall, + RuntimeEnv, RuntimeEventOf, RuntimeOf, - Sandbox, api::prelude::*, }; use frame_support::sp_runtime::{ @@ -114,109 +114,109 @@ mod tests { }; fn make_transfer( - sandbox: &mut DefaultSandbox, + runtime: &mut DefaultRuntime, dest: AccountId32, value: u128, ) -> DispatchResultWithInfo< - ::Runtime> as Dispatchable>::PostInfo, + ::Runtime> as Dispatchable>::PostInfo, > { assert_ne!( - DefaultSandbox::default_actor(), + DefaultRuntime::default_actor(), dest, "make_transfer should send to account different than default_actor" ); - sandbox.runtime_call( - RuntimeCall::>::Balances(pallet_balances::Call::< - RuntimeOf, + runtime.runtime_call( + RuntimeCall::>::Balances(pallet_balances::Call::< + RuntimeOf, >::transfer_allow_death { dest: dest.into(), value, }), - Some(DefaultSandbox::default_actor()), + Some(DefaultRuntime::default_actor()), ) } #[test] fn dry_run_works() { - let mut sandbox = DefaultSandbox::default(); - let actor = DefaultSandbox::default_actor(); - let initial_balance = sandbox.free_balance(&actor); + let mut runtime = DefaultRuntime::default(); + let actor = DefaultRuntime::default_actor(); + let initial_balance = runtime.free_balance(&actor); - sandbox.dry_run(|sandbox| { - crate::api::balance_api::BalanceAPI::mint_into(sandbox, &actor, 100).unwrap(); - assert_eq!(sandbox.free_balance(&actor), initial_balance + 100); + runtime.dry_run(|runtime| { + crate::api::balance_api::BalanceAPI::mint_into(runtime, &actor, 100).unwrap(); + assert_eq!(runtime.free_balance(&actor), initial_balance + 100); }); - assert_eq!(sandbox.free_balance(&actor), initial_balance); + assert_eq!(runtime.free_balance(&actor), initial_balance); } #[test] fn runtime_call_works() { - let mut sandbox = DefaultSandbox::default(); + let mut runtime = DefaultRuntime::default(); const RECIPIENT: AccountId32 = AccountId32::new([2u8; 32]); - let initial_balance = sandbox.free_balance(&RECIPIENT); + let initial_balance = runtime.free_balance(&RECIPIENT); - let result = make_transfer(&mut sandbox, RECIPIENT, 100); + let result = make_transfer(&mut runtime, RECIPIENT, 100); assert!(result.is_ok()); let expected_balance = initial_balance + 100; - assert_eq!(sandbox.free_balance(&RECIPIENT), expected_balance); + assert_eq!(runtime.free_balance(&RECIPIENT), expected_balance); } #[test] fn current_events() { - let mut sandbox = DefaultSandbox::default(); + let mut runtime = DefaultRuntime::default(); const RECIPIENT: AccountId32 = AccountId32::new([2u8; 32]); - let events_before = sandbox.events(); + let events_before = runtime.events(); assert!(events_before.is_empty()); - make_transfer(&mut sandbox, RECIPIENT, 1).expect("Failed to make transfer"); + make_transfer(&mut runtime, RECIPIENT, 1).expect("Failed to make transfer"); - let events_after = sandbox.events(); + let events_after = runtime.events(); assert!(!events_after.is_empty()); assert!(matches!( events_after.last().unwrap().event, - RuntimeEventOf::::Balances(_) + RuntimeEventOf::::Balances(_) )); } #[test] fn resetting_events() { - let mut sandbox = DefaultSandbox::default(); + let mut runtime = DefaultRuntime::default(); const RECIPIENT: AccountId32 = AccountId32::new([3u8; 32]); - make_transfer(&mut sandbox, RECIPIENT.clone(), 1) + make_transfer(&mut runtime, RECIPIENT.clone(), 1) .expect("Failed to make transfer"); - assert!(!sandbox.events().is_empty()); - sandbox.reset_events(); - assert!(sandbox.events().is_empty()); + assert!(!runtime.events().is_empty()); + runtime.reset_events(); + assert!(runtime.events().is_empty()); - make_transfer(&mut sandbox, RECIPIENT, 1).expect("Failed to make transfer"); - assert!(!sandbox.events().is_empty()); + make_transfer(&mut runtime, RECIPIENT, 1).expect("Failed to make transfer"); + assert!(!runtime.events().is_empty()); } #[test] fn snapshot_works() { - let mut sandbox = DefaultSandbox::default(); + let mut runtime = DefaultRuntime::default(); // Check state before - let block_before = sandbox.block_number(); - let snapshot_before = sandbox.take_snapshot(); + let block_before = runtime.block_number(); + let snapshot_before = runtime.take_snapshot(); // Advance some blocks to have some state change - let _ = sandbox.build_blocks(5); - let block_after = sandbox.block_number(); + let _ = runtime.build_blocks(5); + let block_after = runtime.block_number(); // Check block number and state after assert_eq!(block_before + 5, block_after); // Restore state - sandbox.restore_snapshot(snapshot_before); + runtime.restore_snapshot(snapshot_before); // Check state after restore - assert_eq!(block_before, sandbox.block_number()); + assert_eq!(block_before, runtime.block_number()); } } diff --git a/crates/sandbox/src/api/timestamp_api.rs b/crates/runtime/src/api/timestamp_api.rs similarity index 78% rename from crates/sandbox/src/api/timestamp_api.rs rename to crates/runtime/src/api/timestamp_api.rs index e2c4f7e730a..ebbc8bb3f48 100644 --- a/crates/sandbox/src/api/timestamp_api.rs +++ b/crates/runtime/src/api/timestamp_api.rs @@ -1,4 +1,4 @@ -use crate::Sandbox; +use crate::RuntimeEnv; /// Generic Time type. type MomentOf = ::Moment; @@ -21,7 +21,7 @@ pub trait TimestampAPI { impl TimestampAPI for T where - T: Sandbox, + T: RuntimeEnv, T::Runtime: pallet_timestamp::Config, { type T = T::Runtime; @@ -40,19 +40,19 @@ where #[cfg(test)] mod tests { use crate::{ - DefaultSandbox, + DefaultRuntime, api::prelude::*, }; #[test] fn getting_and_setting_timestamp_works() { - let mut sandbox = DefaultSandbox::default(); + let mut runtime = DefaultRuntime::default(); for timestamp in 0..10 { - assert_ne!(sandbox.get_timestamp(), timestamp); - sandbox.set_timestamp(timestamp); - assert_eq!(sandbox.get_timestamp(), timestamp); + assert_ne!(runtime.get_timestamp(), timestamp); + runtime.set_timestamp(timestamp); + assert_eq!(runtime.get_timestamp(), timestamp); - sandbox.build_block(); + runtime.build_block(); } } } diff --git a/crates/sandbox/src/client.rs b/crates/runtime/src/client.rs similarity index 79% rename from crates/sandbox/src/client.rs rename to crates/runtime/src/client.rs index 3fd8c71f71a..c63d0a7f23d 100644 --- a/crates/sandbox/src/client.rs +++ b/crates/runtime/src/client.rs @@ -16,9 +16,9 @@ use crate::{ AccountIdFor, EventRecordOf, RuntimeCall, - Sandbox, + RuntimeEnv, api::prelude::*, - error::SandboxErr, + error::RuntimeErr, frame_system, frame_system::pallet_prelude::OriginFor, pallet_balances, @@ -106,8 +106,8 @@ type BalanceOf = ::Balance; type ContractsBalanceOf = <::Currency as Inspect>>::Balance; -pub struct Client { - sandbox: S, +pub struct Client { + runtime: R, contracts: ContractsRegistry, _phantom: PhantomData, } @@ -115,34 +115,34 @@ pub struct Client { // While it is not necessary true that `Client` is `Send`, it will not be used in a way // that would violate this bound. In particular, all `Client` instances will be operating // synchronously. -unsafe impl Send for Client {} -impl Client +unsafe impl Send for Client {} +impl Client where - S: Default, - S::Runtime: pallet_balances::Config + pallet_revive::Config, - AccountIdFor: From<[u8; 32]>, - BalanceOf: From, + R: Default, + R::Runtime: pallet_balances::Config + pallet_revive::Config, + AccountIdFor: From<[u8; 32]>, + BalanceOf: From, { pub fn new>(contracts: impl IntoIterator) -> Self { - let mut sandbox = S::default(); - Self::fund_accounts(&mut sandbox); + let mut runtime = R::default(); + Self::fund_accounts(&mut runtime); Self { - sandbox, + runtime, contracts: ContractsRegistry::new(contracts), _phantom: Default::default(), } } - /// Get a mutable reference to the underlying sandbox. + /// Get a mutable reference to the underlying runtime. /// - /// This allows direct access to all sandbox methods and traits, making it easy to + /// This allows direct access to all runtime methods and traits, making it easy to /// interact with runtime pallets like `pallet-assets`: - pub fn sandbox(&mut self) -> &mut S { - &mut self.sandbox + pub fn runtime(&mut self) -> &mut R { + &mut self.runtime } - fn fund_accounts(sandbox: &mut S) { + fn fund_accounts(runtime: &mut R) { const TOKENS: u128 = 1_000_000_000_000_000; let accounts = [ @@ -158,29 +158,30 @@ where .map(|kp| kp.public_key().0) .map(From::from); for account in accounts.iter() { - sandbox + runtime .mint_into(account, TOKENS.into()) .unwrap_or_else(|_| panic!("Failed to mint {TOKENS} tokens")); } - let acc = pallet_revive::Pallet::::account_id(); - let ed = pallet_balances::Pallet::::minimum_balance(); - sandbox.mint_into(&acc, ed).unwrap_or_else(|_| { + let acc = pallet_revive::Pallet::::account_id(); + let ed = pallet_balances::Pallet::::minimum_balance(); + runtime.mint_into(&acc, ed).unwrap_or_else(|_| { panic!("Failed to mint existential deposit into `pallet-revive` account") }); } } #[async_trait] -impl + Send, S: Sandbox> ChainBackend for Client +impl + Send, R: RuntimeEnv> ChainBackend + for Client where - S::Runtime: pallet_balances::Config, - AccountIdFor: From<[u8; 32]>, + R::Runtime: pallet_balances::Config, + AccountIdFor: From<[u8; 32]>, { type AccountId = AccountId; - type Balance = BalanceOf; - type Error = SandboxErr; - type EventLog = Vec>; + type Balance = BalanceOf; + type Error = RuntimeErr; + type EventLog = Vec>; async fn create_and_fund_account( &mut self, @@ -189,7 +190,7 @@ where ) -> Keypair { let (pair, seed) = Pair::generate(); - self.sandbox + self.runtime .mint_into(&pair.public().0.into(), amount) .expect("Failed to mint tokens"); @@ -200,8 +201,8 @@ where &mut self, account: Self::AccountId, ) -> Result { - let account = AccountIdFor::::from(*account.as_ref()); - Ok(self.sandbox.free_balance(&account)) + let account = AccountIdFor::::from(*account.as_ref()); + Ok(self.runtime.free_balance(&account)) } async fn runtime_call<'a>( @@ -213,39 +214,39 @@ where ) -> Result { // Since in general, `ChainBackend::runtime_call` must be dynamic, we have to // perform some translation here in order to invoke strongly-typed - // [`ink_sandbox::Sandbox`] API. + // [`ink_runtime::RuntimeEnv`] API. - // Get metadata of the Sandbox runtime, so that we can encode the call object. + // Get metadata of the Runtime environment, so that we can encode the call object. // Panic on error - metadata of the static im-memory runtime should always be // available. - let raw_metadata: Vec = S::get_metadata().into(); + let raw_metadata: Vec = R::get_metadata().into(); let metadata = subxt_metadata::Metadata::decode(&mut raw_metadata.as_slice()) .expect("Failed to decode metadata"); // Encode the call object. let call = subxt::dynamic::tx(pallet_name, call_name, call_data); let encoded_call = call.encode_call_data(&metadata.into()).map_err(|err| { - SandboxErr::new(format!("runtime_call: Error encoding call: {err:?}")) + RuntimeErr::new(format!("runtime_call: Error encoding call: {err:?}")) })?; // Decode the call object. // Panic on error - we just encoded a validated call object, so it should be // decodable. let decoded_call = - RuntimeCall::::decode(&mut encoded_call.as_slice()) + RuntimeCall::::decode(&mut encoded_call.as_slice()) .expect("Failed to decode runtime call"); // Execute the call and record events emitted during this operation. - let start = self.sandbox.events().len(); - self.sandbox + let start = self.runtime.events().len(); + self.runtime .runtime_call( decoded_call, - S::convert_account_to_origin(keypair_to_account(origin)), + R::convert_account_to_origin(keypair_to_account(origin)), ) .map_err(|err| { - SandboxErr::new(format!("runtime_call: execution error {:?}", err.error)) + RuntimeErr::new(format!("runtime_call: execution error {:?}", err.error)) })?; - let all = self.sandbox.events(); + let all = self.runtime.events(); let events = all[start..].to_vec(); Ok(events) } @@ -258,15 +259,15 @@ where ) -> Result<(), Self::Error> { let caller = keypair_to_account(origin); let origin = RawOrigin::Signed(caller); - let origin = OriginFor::::from(origin); + let origin = OriginFor::::from(origin); let dest = dest.as_ref(); let dest = Decode::decode(&mut dest.as_slice()).unwrap(); - self.sandbox + self.runtime .transfer_allow_death(&origin, &dest, value) .map_err(|err| { - SandboxErr::new(format!("transfer_allow_death failed: {err:?}")) + RuntimeErr::new(format!("transfer_allow_death failed: {err:?}")) }) } } @@ -274,19 +275,19 @@ where #[async_trait] impl< AccountId: Clone + Send + Sync + From<[u8; 32]> + AsRef<[u8; 32]>, - S: Sandbox, - E: Environment> + R: RuntimeEnv, + E: Environment> + 'static, -> BuilderClient for Client +> BuilderClient for Client where - S::Runtime: pallet_balances::Config + pallet_revive::Config, - AccountIdFor: From<[u8; 32]> + AsRef<[u8; 32]>, - ContractsBalanceOf: Send + Sync, - ContractsBalanceOf: Into + TryFrom + Bounded, - MomentOf: Into, - <::Runtime as frame_system::Config>::Nonce: Into, + R::Runtime: pallet_balances::Config + pallet_revive::Config, + AccountIdFor: From<[u8; 32]> + AsRef<[u8; 32]>, + ContractsBalanceOf: Send + Sync, + ContractsBalanceOf: Into + TryFrom + Bounded, + MomentOf: Into, + ::Nonce: Into, // todo - <::Runtime as frame_system::Config>::Hash: + ::Hash: frame_support::traits::IsType, { fn load_code(&self, contract_name: &str) -> Vec { @@ -310,13 +311,13 @@ where async fn bare_instantiate< Contract: Clone, Args: Send + Sync + EncodeArgsWith + Clone, - R, + Ret, Abi: Send + Sync + Clone, >( &mut self, code: Vec, caller: &Keypair, - constructor: &mut CreateBuilderPartial, + constructor: &mut CreateBuilderPartial, value: E::Balance, gas_limit: Weight, storage_deposit_limit: E::Balance, @@ -336,25 +337,25 @@ where storage_deposit_limit: E::Balance, ) -> Result, Self::Error> { let _ = - as BuilderClient>::map_account(self, caller).await; + as BuilderClient>::map_account(self, caller).await; // get the trace - let _ = self.sandbox.build_block(); + let _ = self.runtime.build_block(); let tracer_type = TracerType::CallTracer(Some(CallTracerConfig::default())); - let mut tracer = self.sandbox.evm_tracer(tracer_type); + let mut tracer = self.runtime.evm_tracer(tracer_type); let mut code_hash: Option = None; // Record events emitted during instantiation - let start = self.sandbox.events().len(); + let start = self.runtime.events().len(); let result = pallet_revive::tracing::trace(tracer.as_tracing(), || { code_hash = Some(H256(ink_e2e::code_hash(&code[..]))); - self.sandbox.deploy_contract( + self.runtime.deploy_contract( code, value, data, salt(), - caller_to_origin::(caller), + caller_to_origin::(caller), // TODO: mismatch in dependencies pallet_revive::Weight::from_parts( gas_limit.ref_time(), @@ -367,7 +368,7 @@ where let addr_raw = match &result.result { Err(err) => { log_error(&format!("instantiation failed: {err:?}")); - return Err(SandboxErr::new(format!("bare_instantiate: {err:?}"))); + return Err(RuntimeErr::new(format!("bare_instantiate: {err:?}"))); } Ok(res) => res.addr, }; @@ -378,13 +379,13 @@ where }; let account_id = - ::AddressMapper::to_fallback_account_id( + ::AddressMapper::to_fallback_account_id( &addr_raw, ) .as_ref() .to_owned(); - let all = self.sandbox.events(); + let all = self.runtime.events(); let events = all[start..].to_vec(); Ok(BareInstantiationResult { @@ -403,13 +404,13 @@ where async fn bare_instantiate_dry_run< Contract: Clone, Args: Send + Sync + EncodeArgsWith + Clone, - R, + Ret, Abi: Send + Sync + Clone, >( &mut self, contract_name: &str, caller: &Keypair, - constructor: &mut CreateBuilderPartial, + constructor: &mut CreateBuilderPartial, value: E::Balance, storage_deposit_limit: Option, ) -> Result, Self::Error> { @@ -439,16 +440,16 @@ where ) -> Result, Self::Error> { // There's a side effect here! let _ = - as BuilderClient>::map_account(self, caller).await; + as BuilderClient>::map_account(self, caller).await; - let dry_run_result = self.sandbox.dry_run(|sandbox| { - sandbox.deploy_contract( + let dry_run_result = self.runtime.dry_run(|runtime| { + runtime.deploy_contract( code, value, data, salt(), - caller_to_origin::(caller), - S::default_gas_limit(), + caller_to_origin::(caller), + R::default_gas_limit(), storage_deposit_limit.unwrap_or(E::Balance::max_value()), ) }); @@ -470,7 +471,7 @@ where storage_deposit: to_revive_storage_deposit(dry_run_result.storage_deposit), result: dry_run_result .result - .map_err(|_e| sp_runtime::DispatchError::Other("SandboxError")) // TODO: mismatch in dependencies + .map_err(|_e| sp_runtime::DispatchError::Other("RuntimeError")) // TODO: mismatch in dependencies .map(|res| { InstantiateReturnValue { result: ExecReturnValue { @@ -493,20 +494,20 @@ where ) -> Result, Self::Error> { let code = self.contracts.load_code(contract_name); // Record events emitted during upload - let start = self.sandbox.events().len(); - let result = match self.sandbox.upload_contract( + let start = self.runtime.events().len(); + let result = match self.runtime.upload_contract( code, - caller_to_origin::(caller), + caller_to_origin::(caller), storage_deposit_limit.unwrap_or_else(|| E::Balance::max_value()), ) { Ok(result) => result, Err(err) => { log_error(&format!("upload failed: {err:?}")); - return Err(SandboxErr::new(format!("bare_upload: {err:?}"))); + return Err(RuntimeErr::new(format!("bare_upload: {err:?}"))); } }; - let all = self.sandbox.events(); + let all = self.runtime.events(); let events = all[start..].to_vec(); Ok(UploadResult { code_hash: result.code_hash, @@ -523,7 +524,7 @@ where _caller: &Keypair, _code_hash: H256, ) -> Result { - unimplemented!("sandbox does not yet support remove_code") + unimplemented!("runtime does not yet support remove_code") } /// Important: For an uncomplicated UX of the E2E testing environment we @@ -547,11 +548,11 @@ where { // There's a side effect here! let _ = - as BuilderClient>::map_account(self, caller).await; + as BuilderClient>::map_account(self, caller).await; let addr = *message.clone().params().callee(); let exec_input = message.clone().params().exec_input().encode(); - as BuilderClient>::raw_call::<'_, '_, '_>( + as BuilderClient>::raw_call::<'_, '_, '_>( self, addr, exec_input, @@ -573,17 +574,17 @@ where signer: &Keypair, ) -> Result<(Self::EventLog, Option), Self::Error> { // Record events emitted during the contract call - let start = self.sandbox.events().len(); + let start = self.runtime.events().len(); // todo let tracer_type = TracerType::CallTracer(Some(CallTracerConfig::default())); - let mut tracer = self.sandbox.evm_tracer(tracer_type); + let mut tracer = self.runtime.evm_tracer(tracer_type); let _result = pallet_revive::tracing::trace(tracer.as_tracing(), || { - self.sandbox + self.runtime .call_contract( dest, value, input_data, - caller_to_origin::(signer), + caller_to_origin::(signer), // TODO: mismatch in dependencies pallet_revive::Weight::from_parts( gas_limit.ref_time(), @@ -592,14 +593,14 @@ where storage_deposit_limit, ) .result - .map_err(|err| SandboxErr::new(format!("bare_call: {err:?}"))) + .map_err(|err| RuntimeErr::new(format!("bare_call: {err:?}"))) })?; let trace = match tracer.collect_trace() { Some(Trace::Call(call_trace)) => Some(to_revive_trace(call_trace)), _ => None, }; - let all = self.sandbox.events(); + let all = self.runtime.events(); let events = all[start..].to_vec(); Ok((events, trace)) } @@ -645,15 +646,15 @@ where ) -> Result, Self::Error> { // There's a side effect here! let _ = - as BuilderClient>::map_account(self, caller).await; + as BuilderClient>::map_account(self, caller).await; - let result = self.sandbox.dry_run(|sandbox| { - sandbox.call_contract( + let result = self.runtime.dry_run(|runtime| { + runtime.call_contract( dest, value, input_data, - caller_to_origin::(caller), - S::default_gas_limit(), + caller_to_origin::(caller), + R::default_gas_limit(), storage_deposit_limit.unwrap_or(E::Balance::max_value()), ) }); @@ -681,7 +682,7 @@ where storage_deposit: to_revive_storage_deposit(result.storage_deposit), result: result .result - .map_err(|_e| sp_runtime::DispatchError::Other("SandboxError")) // TODO: mismatch in dependencies + .map_err(|_e| sp_runtime::DispatchError::Other("RuntimeError")) // TODO: mismatch in dependencies .map(|res| { ExecReturnValue { // TODO: mismatch in dependencies @@ -699,13 +700,13 @@ where &mut self, caller: &Keypair, ) -> Result, Self::Error> { - let caller_account: AccountIdFor = keypair_to_account(caller); - let origin = S::convert_account_to_origin(caller_account); + let caller_account: AccountIdFor = keypair_to_account(caller); + let origin = R::convert_account_to_origin(caller_account); - self.sandbox - .execute_with(|| pallet_revive::Pallet::::map_account(origin)) + self.runtime + .execute_with(|| pallet_revive::Pallet::::map_account(origin)) .map_err(|err| { - SandboxErr::new(format!("map_account: execution error {err:?}")) + RuntimeErr::new(format!("map_account: execution error {err:?}")) }) .map(|_| None) } @@ -713,30 +714,30 @@ where async fn to_account_id(&mut self, addr: &H160) -> Result { use pallet_revive::AddressMapper; let account_id = - ::AddressMapper::to_account_id(addr); + ::AddressMapper::to_account_id(addr); Ok(E::AccountId::from(*account_id.as_ref())) } } -impl Client +impl Client where - S::Runtime: pallet_revive::Config, - ::RuntimeEvent: - TryInto>, + R::Runtime: pallet_revive::Config, + ::RuntimeEvent: + TryInto>, { pub fn contract_events(&mut self) -> Vec> where - S::Runtime: pallet_revive::Config, - ::RuntimeEvent: - TryInto>, + R::Runtime: pallet_revive::Config, + ::RuntimeEvent: + TryInto>, { - self.sandbox + self.runtime .events() .iter() .filter_map(|event_record| { if let Ok(pallet_event) = &event_record.event.clone().try_into() { match pallet_event { - pallet_revive::Event::::ContractEmitted { + pallet_revive::Event::::ContractEmitted { data, .. } => Some(data.clone()), @@ -752,9 +753,9 @@ where /// Returns the last contract event that was emitted, if any. pub fn last_contract_event(&mut self) -> Option> where - S::Runtime: pallet_revive::Config, - ::RuntimeEvent: - TryInto>, + R::Runtime: pallet_revive::Config, + ::RuntimeEvent: + TryInto>, { self.contract_events().last().cloned() } @@ -763,17 +764,17 @@ where /// Helper function for the `assert_last_contract_event!` macro. /// /// # Parameters: -/// - `client` - The client for interacting with the sandbox. +/// - `client` - The client for interacting with the runtime. /// - `event` - The expected event. #[track_caller] -pub fn assert_last_contract_event_inner( - client: &mut Client, +pub fn assert_last_contract_event_inner( + client: &mut Client, event: E, ) where - S: Sandbox, - S::Runtime: pallet_revive::Config, - ::RuntimeEvent: - TryInto>, + R: RuntimeEnv, + R::Runtime: pallet_revive::Config, + ::RuntimeEvent: + TryInto>, E: Decode + scale::Encode + core::fmt::Debug + std::cmp::PartialEq, { let expected_event = event; @@ -800,7 +801,7 @@ pub fn assert_last_contract_event_inner( impl< AccountId: Clone + Send + Sync + From<[u8; 32]> + AsRef<[u8; 32]>, - Config: Sandbox, + Config: RuntimeEnv, E: Environment> + 'static, > E2EBackend for Client @@ -819,50 +820,50 @@ where #[async_trait] impl< AccountId: Clone + Send + Sync + From<[u8; 32]> + AsRef<[u8; 32]>, - S: Sandbox, - E: Environment> + R: RuntimeEnv, + E: Environment> + 'static, -> ContractsBackend for Client +> ContractsBackend for Client where - S::Runtime: pallet_balances::Config + pallet_revive::Config, - AccountIdFor: From<[u8; 32]> + AsRef<[u8; 32]>, + R::Runtime: pallet_balances::Config + pallet_revive::Config, + AccountIdFor: From<[u8; 32]> + AsRef<[u8; 32]>, { - type Error = SandboxErr; - type EventLog = Vec>; + type Error = RuntimeErr; + type EventLog = Vec>; } -/// Exposes preset sandbox configurations to be used in tests. +/// Exposes preset runtime configurations to be used in tests. pub mod preset { /* // todo pub mod mock_network { - use ink_sandbox::{ + use ink_runtime::{ frame_system, AccountIdFor, BlockBuilder, Extension, RuntimeMetadataPrefixed, - Sandbox, + RuntimeEnv, Snapshot, }; pub use pallet_revive_mock_network::*; use sp_runtime::traits::Dispatchable; - /// A [`ink_sandbox::Sandbox`] that can be used to test contracts + /// A [`ink_runtime::RuntimeEnv`] that can be used to test contracts /// with a mock network of relay chain and parachains. /// /// ```no_compile - /// #[ink_e2e::test(backend(runtime_only(sandbox = MockNetworkSandbox, client = ink_sandbox::SandboxClient)))] + /// #[ink_e2e::test(runtime(MockNetworkRuntime))] /// async fn my_test(mut client: Client) -> E2EResult<()> { /// // ... /// } /// ``` #[derive(Default)] - pub struct MockNetworkSandbox { + pub struct MockNetworkRuntime { dry_run: bool, } - impl Sandbox for MockNetworkSandbox { + impl RuntimeEnv for MockNetworkRuntime { type Runtime = parachain::Runtime; fn execute_with(&mut self, execute: impl FnOnce() -> T) -> T { @@ -938,11 +939,11 @@ pub mod preset { }) } - fn restore_snapshot(&mut self, snapshot: ink_sandbox::Snapshot) { + fn restore_snapshot(&mut self, snapshot: ink_runtime::Snapshot) { EXT_PARAA.with(|v| { let mut v = v.borrow_mut(); - *v = ink_sandbox::TestExternalities::from_raw_snapshot( + *v = ink_runtime::TestExternalities::from_raw_snapshot( snapshot.storage, snapshot.storage_root, Default::default(), @@ -955,13 +956,13 @@ pub mod preset { } /// Transforms a `Keypair` into an origin. -pub fn caller_to_origin(caller: &Keypair) -> OriginFor +pub fn caller_to_origin(caller: &Keypair) -> OriginFor where - S: Sandbox, - S::Runtime: pallet_balances::Config + pallet_revive::Config, - AccountIdFor: From<[u8; 32]> + AsRef<[u8; 32]>, + R: RuntimeEnv, + R::Runtime: pallet_balances::Config + pallet_revive::Config, + AccountIdFor: From<[u8; 32]> + AsRef<[u8; 32]>, { let caller = keypair_to_account(caller); let origin = RawOrigin::Signed(caller); - OriginFor::::from(origin) + OriginFor::::from(origin) } diff --git a/crates/sandbox/src/error.rs b/crates/runtime/src/error.rs similarity index 71% rename from crates/sandbox/src/error.rs rename to crates/runtime/src/error.rs index 314ba570c2f..b5ab76405dc 100644 --- a/crates/sandbox/src/error.rs +++ b/crates/runtime/src/error.rs @@ -14,52 +14,52 @@ use std::fmt; -/// Dummy error type for sandbox_client +/// Dummy error type for runtime_client #[derive(Debug, thiserror::Error)] -pub struct SandboxErr { +pub struct RuntimeErr { msg: String, } -impl SandboxErr { - /// Create a new `SandboxErr` with the given message. +impl RuntimeErr { + /// Create a new `RuntimeErr` with the given message. #[allow(dead_code)] pub fn new(msg: String) -> Self { Self { msg } } } -impl From for SandboxErr { +impl From for RuntimeErr { fn from(msg: String) -> Self { Self { msg } } } -impl fmt::Display for SandboxErr { +impl fmt::Display for RuntimeErr { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "SandboxErr: {}", self.msg) + write!(f, "RuntimeErr: {}", self.msg) } } -/// Unified error type for sandbox E2E testing. +/// Unified error type for runtime E2E testing. /// /// This error type allows seamless error propagation with the `?` operator -/// across sandbox APIs (which return `DispatchError`) and contract calls -/// (which return `SandboxErr`). +/// across runtime APIs (which return `DispatchError`) and contract calls +/// (which return `RuntimeErr`). #[derive(Debug, thiserror::Error)] pub enum E2EError { /// Error from FRAME dispatch (e.g., pallet extrinsic failures). /// - /// Returned by sandbox APIs like `create()`, `mint_into()`, `map_account()`, etc. + /// Returned by runtime APIs like `create()`, `mint_into()`, `map_account()`, etc. /// when the underlying FRAME pallet operation fails. #[error("Dispatch error: {0:?}")] Dispatch(frame_support::sp_runtime::DispatchError), - /// Error from sandbox operations. + /// Error from runtime operations. /// /// Returned by contract instantiation and call operations when they fail - /// at the sandbox client level. - #[error("Sandbox error: {0}")] - Sandbox(#[from] SandboxErr), + /// at the runtime client level. + #[error("Runtime error: {0}")] + Runtime(#[from] RuntimeErr), } impl From for E2EError { diff --git a/crates/sandbox/src/lib.rs b/crates/runtime/src/lib.rs similarity index 92% rename from crates/sandbox/src/lib.rs rename to crates/runtime/src/lib.rs index 56a7ca4a569..9abc3ae43d0 100644 --- a/crates/sandbox/src/lib.rs +++ b/crates/runtime/src/lib.rs @@ -29,7 +29,7 @@ use ink_revive_types::{ pub use macros::{ AssetIdForTrustBackedAssets, BlockBuilder, - DefaultSandbox, + DefaultRuntime, TrustBackedAssetsInstance, }; use pallet_revive::{ @@ -38,7 +38,7 @@ use pallet_revive::{ InstantiateReturnValue, }; use sp_core::Get; -/// Export pallets that are used in [`crate::create_sandbox`] +/// Export pallets that are used in [`crate::create_runtime`] pub use { frame_support::sp_runtime::testing::H256, frame_support::{ @@ -67,7 +67,7 @@ pub use { }; pub use client::{ - Client as SandboxClient, + Client as RuntimeClient, preset, }; pub use error::E2EError; @@ -117,15 +117,15 @@ pub type ContractExecResultFor = /// Alias for the `map_account` result. pub type MapAccountResultFor = Result<(), DispatchError>; -/// Alias for the runtime of a sandbox. -pub type RuntimeOf = ::Runtime; +/// Alias for the runtime of a runtime environment. +pub type RuntimeOf = ::Runtime; -/// Alias for the runtime event of a sandbox. +/// Alias for the runtime event of a runtime environment. pub type RuntimeEventOf = as frame_system::Config>::RuntimeEvent; -/// Sandbox defines the API of a sandboxed runtime. -pub trait Sandbox { - /// The runtime associated with the sandbox. +/// RuntimeEnv defines the API of a runtime environment. +pub trait RuntimeEnv { + /// The runtime associated with the runtime environment. type Runtime: frame_system::Config; /// Execute the given externalities. @@ -151,7 +151,7 @@ pub trait Sandbox { Default::default() } - /// Default actor for the sandbox. + /// Default actor for the runtime environment. fn default_actor() -> AccountIdFor; fn default_gas_limit() -> Weight { @@ -194,7 +194,7 @@ where native_to_eth_ratio.saturating_mul(evm_value) } -/// Convert a `pallet_revive::CallTrace` (sandbox) into an `ink_revive_types::CallTrace` +/// Convert a `pallet_revive::CallTrace` (runtime) into an `ink_revive_types::CallTrace` /// (API). pub fn to_revive_trace(t: pallet_revive::evm::CallTrace) -> CallTrace { CallTrace { @@ -258,7 +258,7 @@ pub fn to_revive_storage_deposit( /// Trait for types that can be converted into a runtime AccountId. /// -/// This allows sandbox APIs to accept various account types without requiring manual +/// This allows runtime APIs to accept various account types without requiring manual /// conversion. pub trait IntoAccountId { fn into_account_id(self) -> AccountId; diff --git a/crates/sandbox/src/macros.rs b/crates/runtime/src/macros.rs similarity index 95% rename from crates/sandbox/src/macros.rs rename to crates/runtime/src/macros.rs index 4e82559eeeb..df0714a2602 100644 --- a/crates/sandbox/src/macros.rs +++ b/crates/runtime/src/macros.rs @@ -128,11 +128,11 @@ macro_rules! assert_noop { /// Asserts that the latest contract event matches an expected event. /// -/// This macro verifies that the last emitted contract event from the sandbox +/// This macro verifies that the last emitted contract event from the runtime /// matches the provided expected event. /// /// # Parameters -/// - `client` - Mutable reference to the sandbox client +/// - `client` - Mutable reference to the runtime client /// - `event` - The expected event #[macro_export] macro_rules! assert_last_event { @@ -211,29 +211,29 @@ impl< /// Macro creating a minimal runtime with the given name. /// -/// The new macro will automatically implement `crate::Sandbox`. +/// The new macro will automatically implement `crate::RuntimeEnv`. #[macro_export] -macro_rules! create_sandbox { +macro_rules! create_runtime { ($name:ident) => { $crate::paste::paste! { - $crate::create_sandbox!($name, [<$name Runtime>], (), {}); + $crate::create_runtime!($name, [<$name Runtime>], (), {}); } }; ($name:ident, $debug: ty) => { $crate::paste::paste! { - $crate::create_sandbox!($name, [<$name Runtime>], $debug, {}); + $crate::create_runtime!($name, [<$name Runtime>], $debug, {}); } }; ($name:ident, $debug: ty, { $( $pallet_name:tt : $pallet:ident ),* $(,)? }) => { $crate::paste::paste! { - $crate::create_sandbox!($name, [<$name Runtime>], $debug, { + $crate::create_runtime!($name, [<$name Runtime>], $debug, { $( $pallet_name : $pallet, )* }); } }; - ($sandbox:ident, $runtime:ident, $debug: ty, { $( $pallet_name:tt : $pallet:ident ),* $(,)? }) => { + ($runtime_env:ident, $runtime:ident, $debug: ty, { $( $pallet_name:tt : $pallet:ident ),* $(,)? }) => { // Put all the boilerplate into an auxiliary module mod construct_runtime { @@ -399,11 +399,11 @@ mod construct_runtime { pub const INITIAL_BALANCE: u128 = 1_000_000_000_000_000; pub const DEFAULT_ACCOUNT: AccountId32 = AccountId32::new([1u8; 32]); - pub struct $sandbox { + pub struct $runtime_env { ext: $crate::TestExternalities, } - impl ::std::default::Default for $sandbox { + impl ::std::default::Default for $runtime_env { fn default() -> Self { let ext = $crate::macros::BlockBuilder::<$runtime>::new_ext(vec![( DEFAULT_ACCOUNT, @@ -413,8 +413,8 @@ mod construct_runtime { } } - // Implement `crate::Sandbox` trait - impl $crate::Sandbox for $sandbox { + // Implement `crate::RuntimeEnv` trait + impl $crate::RuntimeEnv for $runtime_env { type Runtime = $runtime; fn execute_with(&mut self, execute: impl FnOnce() -> T) -> T { @@ -492,11 +492,11 @@ mod construct_runtime { // Export runtime type itself, pallets and useful types from the auxiliary module pub use construct_runtime::{ - $sandbox, $runtime, Assets, AssetIdForTrustBackedAssets, Balances, Revive, PalletInfo, + $runtime_env, $runtime, Assets, AssetIdForTrustBackedAssets, Balances, Revive, PalletInfo, RuntimeCall, RuntimeEvent, RuntimeHoldReason, RuntimeOrigin, System, Timestamp, TrustBackedAssetsInstance, }; }; } -create_sandbox!(DefaultSandbox); +create_runtime!(DefaultRuntime); diff --git a/crates/sandbox/test-resources/dummy.polkavm b/crates/runtime/test-resources/dummy.polkavm similarity index 100% rename from crates/sandbox/test-resources/dummy.polkavm rename to crates/runtime/test-resources/dummy.polkavm diff --git a/integration-tests/all-abi/events/lib.rs b/integration-tests/all-abi/events/lib.rs index 4c361d6fc95..f5f8d5f2a26 100644 --- a/integration-tests/all-abi/events/lib.rs +++ b/integration-tests/all-abi/events/lib.rs @@ -447,9 +447,7 @@ pub mod events { type E2EResult = std::result::Result>; #[ink_e2e::test] - async fn emits_foreign_event( - mut client: Client, - ) -> E2EResult<()> { + async fn emits_foreign_event(mut client: Client) -> E2EResult<()> { // given let init_value = false; let mut constructor = EventsRef::new(init_value); @@ -510,9 +508,7 @@ pub mod events { } #[ink_e2e::test()] - async fn emits_inline_anonymous_event( - mut client: Client, - ) -> E2EResult<()> { + async fn emits_inline_anonymous_event(mut client: Client) -> E2EResult<()> { // given let init_value = false; let mut constructor = EventsRef::new(init_value); @@ -597,9 +593,7 @@ pub mod events { } #[ink_e2e::test] - async fn emits_event_with_option_topic_some( - mut client: Client, - ) -> E2EResult<()> { + async fn emits_event_with_option_topic_some(mut client: Client) -> E2EResult<()> { // given let init_value = false; let mut constructor = EventsRef::new(init_value); @@ -672,9 +666,7 @@ pub mod events { } #[ink_e2e::test] - async fn emits_event_with_option_topic_none( - mut client: Client, - ) -> E2EResult<()> { + async fn emits_event_with_option_topic_none(mut client: Client) -> E2EResult<()> { // given let init_value = false; let mut constructor = EventsRef::new(init_value); diff --git a/integration-tests/internal/builtin-precompiles/lib.rs b/integration-tests/internal/builtin-precompiles/lib.rs index 976fc250bb6..296568561ca 100755 --- a/integration-tests/internal/builtin-precompiles/lib.rs +++ b/integration-tests/internal/builtin-precompiles/lib.rs @@ -42,9 +42,7 @@ mod builtin_precompiles { type E2EResult = std::result::Result>; #[ink_e2e::test] - async fn bn128_add_works( - mut client: Client, - ) -> E2EResult<()> { + async fn bn128_add_works(mut client: Client) -> E2EResult<()> { // given let mut constructor = BuiltinPrecompilesRef::new(); let contract = client @@ -76,9 +74,7 @@ mod builtin_precompiles { } #[ink_e2e::test] - async fn bn128_mul_works( - mut client: Client, - ) -> E2EResult<()> { + async fn bn128_mul_works(mut client: Client) -> E2EResult<()> { // given let mut constructor = BuiltinPrecompilesRef::new(); let contract = client @@ -110,9 +106,7 @@ mod builtin_precompiles { } #[ink_e2e::test] - async fn bn128_pairing_works( - mut client: Client, - ) -> E2EResult<()> { + async fn bn128_pairing_works(mut client: Client) -> E2EResult<()> { // given let mut constructor = BuiltinPrecompilesRef::new(); let contract = client @@ -143,9 +137,7 @@ mod builtin_precompiles { } #[ink_e2e::test] - async fn bn128_pairing_zero_points_works( - mut client: Client, - ) -> E2EResult<()> { + async fn bn128_pairing_zero_points_works(mut client: Client) -> E2EResult<()> { // given let mut constructor = BuiltinPrecompilesRef::new(); let contract = client diff --git a/integration-tests/internal/call-builder-return-value/lib.rs b/integration-tests/internal/call-builder-return-value/lib.rs index a81bc033aa6..9e760fd97e8 100755 --- a/integration-tests/internal/call-builder-return-value/lib.rs +++ b/integration-tests/internal/call-builder-return-value/lib.rs @@ -121,9 +121,7 @@ mod call_builder { type E2EResult = std::result::Result>; #[ink_e2e::test] - async fn e2e_delegate_call_return_value_returns_correct_value< - Client: E2EBackend, - >( + async fn e2e_delegate_call_return_value_returns_correct_value( mut client: Client, ) -> E2EResult<()> { let origin = client @@ -165,9 +163,7 @@ mod call_builder { } #[ink_e2e::test] - async fn e2e_delegate_call_return_value_errors_if_return_data_too_long< - Client: E2EBackend, - >( + async fn e2e_delegate_call_return_value_errors_if_return_data_too_long( mut client: Client, ) -> E2EResult<()> { let origin = client @@ -209,9 +205,7 @@ mod call_builder { } #[ink_e2e::test] - async fn e2e_forward_call_return_value_returns_correct_value< - Client: E2EBackend, - >( + async fn e2e_forward_call_return_value_returns_correct_value( mut client: Client, ) -> E2EResult<()> { let origin = client @@ -252,9 +246,7 @@ mod call_builder { } #[ink_e2e::test] - async fn e2e_forward_call_return_value_errors_if_return_data_too_long< - Client: E2EBackend, - >( + async fn e2e_forward_call_return_value_errors_if_return_data_too_long( mut client: Client, ) -> E2EResult<()> { let origin = client diff --git a/integration-tests/internal/data-hostfns/lib.rs b/integration-tests/internal/data-hostfns/lib.rs index a28b7921b00..830e4ea0759 100644 --- a/integration-tests/internal/data-hostfns/lib.rs +++ b/integration-tests/internal/data-hostfns/lib.rs @@ -33,9 +33,7 @@ mod data_hostfns { type E2EResult = std::result::Result>; #[ink_e2e::test] - async fn e2e_call_data_size_works( - mut client: Client, - ) -> E2EResult<()> { + async fn e2e_call_data_size_works(mut client: Client) -> E2EResult<()> { // given let contract = client .instantiate( @@ -63,9 +61,7 @@ mod data_hostfns { } #[ink_e2e::test] - async fn e2e_return_data_size_works( - mut client: Client, - ) -> E2EResult<()> { + async fn e2e_return_data_size_works(mut client: Client) -> E2EResult<()> { // given let contract = client .instantiate( diff --git a/integration-tests/internal/e2e-runtime-only-backend/Cargo.toml b/integration-tests/internal/e2e-runtime-only-backend/Cargo.toml index 5c9133d8426..4e436dd7379 100644 --- a/integration-tests/internal/e2e-runtime-only-backend/Cargo.toml +++ b/integration-tests/internal/e2e-runtime-only-backend/Cargo.toml @@ -10,7 +10,7 @@ ink = { path = "../../../crates/ink", default-features = false } [dev-dependencies] ink_e2e = { path = "../../../crates/e2e" } -ink_sandbox = { path = "../../../crates/sandbox" } +ink_runtime = { path = "../../../crates/runtime" } [lib] path = "lib.rs" diff --git a/integration-tests/internal/e2e-runtime-only-backend/lib.rs b/integration-tests/internal/e2e-runtime-only-backend/lib.rs index 681c0883549..5e89f22eb6e 100644 --- a/integration-tests/internal/e2e-runtime-only-backend/lib.rs +++ b/integration-tests/internal/e2e-runtime-only-backend/lib.rs @@ -56,11 +56,8 @@ pub mod flipper { /// - flip the flipper /// - get the flipper's value /// - assert that the value is `true` - #[ink_sandbox::test(backend(runtime_only( - sandbox = ink_sandbox::DefaultSandbox, - client = ink_sandbox::SandboxClient - )))] - async fn it_works(mut client: Client) -> E2EResult<()> { + #[ink_e2e::test(runtime)] + async fn it_works(mut client: Client) -> E2EResult<()> { // given const INITIAL_VALUE: bool = false; let mut constructor = FlipperRef::new(INITIAL_VALUE); @@ -98,10 +95,7 @@ pub mod flipper { /// - transfer some funds to the contract using runtime call /// - get the contract's balance again /// - assert that the contract's balance increased by the transferred amount - #[ink_sandbox::test(backend(runtime_only( - sandbox = ink_sandbox::DefaultSandbox, - client = ink_sandbox::SandboxClient - )))] + #[ink_e2e::test(runtime)] async fn runtime_call_works() -> E2EResult<()> { // given let mut constructor = FlipperRef::new(false); @@ -155,11 +149,8 @@ pub mod flipper { } /// Just instantiate a contract using non-default runtime. - #[ink_sandbox::test(backend(runtime_only( - sandbox = ink_sandbox::DefaultSandbox, - client = ink_sandbox::SandboxClient - )))] - async fn custom_runtime(mut client: Client) -> E2EResult<()> { + #[ink_e2e::test(runtime)] + async fn custom_runtime(mut client: Client) -> E2EResult<()> { client .instantiate( "e2e-runtime-only-backend", diff --git a/integration-tests/internal/gas-hostfns/lib.rs b/integration-tests/internal/gas-hostfns/lib.rs index ea9ad1416f5..01f547e6a51 100644 --- a/integration-tests/internal/gas-hostfns/lib.rs +++ b/integration-tests/internal/gas-hostfns/lib.rs @@ -39,9 +39,7 @@ mod gas_hostfns { type E2EResult = std::result::Result>; #[ink_e2e::test] - async fn e2e_gas_limit_works( - mut client: Client, - ) -> E2EResult<()> { + async fn e2e_gas_limit_works(mut client: Client) -> E2EResult<()> { // given let contract = client .instantiate("gas_hostfns", &ink_e2e::alice(), &mut GasHostfnsRef::new()) @@ -65,9 +63,7 @@ mod gas_hostfns { } #[ink_e2e::test] - async fn e2e_gas_price_works( - mut client: Client, - ) -> E2EResult<()> { + async fn e2e_gas_price_works(mut client: Client) -> E2EResult<()> { // given let contract = client .instantiate("gas_hostfns", &ink_e2e::alice(), &mut GasHostfnsRef::new()) @@ -91,9 +87,7 @@ mod gas_hostfns { } #[ink_e2e::test] - async fn e2e_gas_left_works( - mut client: Client, - ) -> E2EResult<()> { + async fn e2e_gas_left_works(mut client: Client) -> E2EResult<()> { // given let contract = client .instantiate("gas_hostfns", &ink_e2e::alice(), &mut GasHostfnsRef::new()) diff --git a/integration-tests/internal/lang-err/call-builder-delegate/lib.rs b/integration-tests/internal/lang-err/call-builder-delegate/lib.rs index 064c4f5ea3f..fc86761c6c8 100755 --- a/integration-tests/internal/lang-err/call-builder-delegate/lib.rs +++ b/integration-tests/internal/lang-err/call-builder-delegate/lib.rs @@ -102,7 +102,7 @@ mod call_builder { type E2EResult = std::result::Result>; #[ink_e2e::test] - async fn e2e_invalid_message_selector_can_be_handled( + async fn e2e_invalid_message_selector_can_be_handled( mut client: Client, ) -> E2EResult<()> { let origin = client @@ -142,7 +142,7 @@ mod call_builder { } #[ink_e2e::test] - async fn e2e_invalid_message_selector_panics_on_invoke( + async fn e2e_invalid_message_selector_panics_on_invoke( mut client: Client, ) -> E2EResult<()> { let origin = client diff --git a/integration-tests/internal/lang-err/call-builder/lib.rs b/integration-tests/internal/lang-err/call-builder/lib.rs index 2a75f5a9536..093f2c78431 100755 --- a/integration-tests/internal/lang-err/call-builder/lib.rs +++ b/integration-tests/internal/lang-err/call-builder/lib.rs @@ -176,7 +176,7 @@ mod call_builder { type E2EResult = std::result::Result>; #[ink_e2e::test] - async fn e2e_invalid_message_selector_can_be_handled( + async fn e2e_invalid_message_selector_can_be_handled( mut client: Client, ) -> E2EResult<()> { let origin = client @@ -227,7 +227,7 @@ mod call_builder { } #[ink_e2e::test] - async fn e2e_invalid_message_selector_panics_on_invoke( + async fn e2e_invalid_message_selector_panics_on_invoke( mut client: Client, ) -> E2EResult<()> { let mut constructor = CallBuilderTestRef::new(); @@ -264,7 +264,7 @@ mod call_builder { } #[ink_e2e::test] - async fn e2e_create_builder_works_with_valid_selector( + async fn e2e_create_builder_works_with_valid_selector( mut client: Client, ) -> E2EResult<()> { let origin = client @@ -305,7 +305,7 @@ mod call_builder { } #[ink_e2e::test] - async fn e2e_create_builder_fails_with_invalid_selector( + async fn e2e_create_builder_fails_with_invalid_selector( mut client: Client, ) -> E2EResult<()> { let origin = client @@ -346,9 +346,7 @@ mod call_builder { } #[ink_e2e::test] - async fn e2e_create_builder_with_infallible_revert_constructor_encodes_ok< - Client: E2EBackend, - >( + async fn e2e_create_builder_with_infallible_revert_constructor_encodes_ok( mut client: Client, ) -> E2EResult<()> { let origin = client @@ -385,9 +383,7 @@ mod call_builder { } #[ink_e2e::test] - async fn e2e_create_builder_can_handle_fallible_constructor_success< - Client: E2EBackend, - >( + async fn e2e_create_builder_can_handle_fallible_constructor_success( mut client: Client, ) -> E2EResult<()> { let origin = client @@ -429,9 +425,7 @@ mod call_builder { } #[ink_e2e::test] - async fn e2e_create_builder_can_handle_fallible_constructor_error< - Client: E2EBackend, - >( + async fn e2e_create_builder_can_handle_fallible_constructor_error( mut client: Client, ) -> E2EResult<()> { let origin = client @@ -480,9 +474,7 @@ mod call_builder { } #[ink_e2e::test] - async fn e2e_create_builder_with_fallible_revert_constructor_encodes_ok< - Client: E2EBackend, - >( + async fn e2e_create_builder_with_fallible_revert_constructor_encodes_ok( mut client: Client, ) -> E2EResult<()> { let origin = client @@ -519,9 +511,7 @@ mod call_builder { } #[ink_e2e::test] - async fn e2e_create_builder_with_fallible_revert_constructor_encodes_err< - Client: E2EBackend, - >( + async fn e2e_create_builder_with_fallible_revert_constructor_encodes_err( mut client: Client, ) -> E2EResult<()> { let origin = client diff --git a/integration-tests/internal/lang-err/constructors-return-value/lib.rs b/integration-tests/internal/lang-err/constructors-return-value/lib.rs index a00005d6a9f..08fc6fcbc49 100644 --- a/integration-tests/internal/lang-err/constructors-return-value/lib.rs +++ b/integration-tests/internal/lang-err/constructors-return-value/lib.rs @@ -116,9 +116,7 @@ pub mod constructors_return_value { type E2EResult = std::result::Result>; #[ink_e2e::test] - async fn e2e_infallible_constructor( - mut client: Client, - ) -> E2EResult<()> { + async fn e2e_infallible_constructor(mut client: Client) -> E2EResult<()> { let mut constructor = ConstructorsReturnValueRef::new(true); let infallible_constructor_result = client .instantiate( @@ -154,9 +152,7 @@ pub mod constructors_return_value { } #[ink_e2e::test] - async fn e2e_fallible_constructor_succeed( - mut client: Client, - ) -> E2EResult<()> { + async fn e2e_fallible_constructor_succeed(mut client: Client) -> E2EResult<()> { let mut constructor = ConstructorsReturnValueRef::try_new(true); let result = client .instantiate( @@ -205,9 +201,7 @@ pub mod constructors_return_value { } #[ink_e2e::test] - async fn e2e_fallible_constructor_fails( - mut client: Client, - ) -> E2EResult<()> { + async fn e2e_fallible_constructor_fails(mut client: Client) -> E2EResult<()> { let mut constructor = ConstructorsReturnValueRef::try_new(false); let result = client diff --git a/integration-tests/internal/lang-err/contract-ref/lib.rs b/integration-tests/internal/lang-err/contract-ref/lib.rs index 3d77a5333cb..98d5a84ef97 100755 --- a/integration-tests/internal/lang-err/contract-ref/lib.rs +++ b/integration-tests/internal/lang-err/contract-ref/lib.rs @@ -82,9 +82,7 @@ mod contract_ref { type E2EResult = std::result::Result>; #[ink_e2e::test] - async fn e2e_ref_can_flip_correctly( - mut client: Client, - ) -> E2EResult<()> { + async fn e2e_ref_can_flip_correctly(mut client: Client) -> E2EResult<()> { let flipper_hash = client .upload("integration_flipper", &ink_e2e::alice()) .submit() @@ -126,7 +124,7 @@ mod contract_ref { } #[ink_e2e::test] - async fn e2e_fallible_ref_can_be_instantiated( + async fn e2e_fallible_ref_can_be_instantiated( mut client: Client, ) -> E2EResult<()> { let flipper_hash: ink::H256 = client @@ -156,7 +154,7 @@ mod contract_ref { } #[ink_e2e::test] - async fn e2e_fallible_ref_fails_to_be_instantiated( + async fn e2e_fallible_ref_fails_to_be_instantiated( mut client: Client, ) -> E2EResult<()> { let flipper_hash = client diff --git a/integration-tests/internal/lang-err/integration-flipper/lib.rs b/integration-tests/internal/lang-err/integration-flipper/lib.rs index 9b200cd912e..3c8bba46940 100644 --- a/integration-tests/internal/lang-err/integration-flipper/lib.rs +++ b/integration-tests/internal/lang-err/integration-flipper/lib.rs @@ -67,9 +67,7 @@ pub mod integration_flipper { type E2EResult = std::result::Result>; #[ink_e2e::test] - async fn e2e_can_flip_correctly( - mut client: Client, - ) -> E2EResult<()> { + async fn e2e_can_flip_correctly(mut client: Client) -> E2EResult<()> { let mut constructor = FlipperRef::new_default(); let flipper = client .instantiate("integration_flipper", &ink_e2e::alice(), &mut constructor) @@ -107,9 +105,7 @@ pub mod integration_flipper { } #[ink_e2e::test] - async fn e2e_message_error_reverts_state( - mut client: Client, - ) -> E2EResult<()> { + async fn e2e_message_error_reverts_state(mut client: Client) -> E2EResult<()> { let mut constructor = FlipperRef::new_default(); let flipper = client .instantiate("integration_flipper", &ink_e2e::bob(), &mut constructor) diff --git a/integration-tests/internal/mapping/lib.rs b/integration-tests/internal/mapping/lib.rs index cf59d8dc87d..fabef7c07d4 100755 --- a/integration-tests/internal/mapping/lib.rs +++ b/integration-tests/internal/mapping/lib.rs @@ -149,9 +149,7 @@ mod mapping { type E2EResult = std::result::Result>; #[ink_e2e::test] - async fn insert_and_get_works( - mut client: Client, - ) -> E2EResult<()> { + async fn insert_and_get_works(mut client: Client) -> E2EResult<()> { // given let mut constructor = MappingsRef::new(); let contract = client @@ -185,9 +183,7 @@ mod mapping { } #[ink_e2e::test] - async fn insert_and_contains_works( - mut client: Client, - ) -> E2EResult<()> { + async fn insert_and_contains_works(mut client: Client) -> E2EResult<()> { // given let mut constructor = MappingsRef::new(); let contract = client @@ -215,7 +211,7 @@ mod mapping { } #[ink_e2e::test] - async fn reinsert_works(mut client: Client) -> E2EResult<()> { + async fn reinsert_works(mut client: Client) -> E2EResult<()> { // given let mut constructor = MappingsRef::new(); let contract = client @@ -258,9 +254,7 @@ mod mapping { } #[ink_e2e::test] - async fn insert_and_remove_works( - mut client: Client, - ) -> E2EResult<()> { + async fn insert_and_remove_works(mut client: Client) -> E2EResult<()> { // given let mut constructor = MappingsRef::new(); let contract = client @@ -300,9 +294,7 @@ mod mapping { } #[ink_e2e::test] - async fn insert_and_take_works( - mut client: Client, - ) -> E2EResult<()> { + async fn insert_and_take_works(mut client: Client) -> E2EResult<()> { // given let mut constructor = MappingsRef::new(); let contract = client @@ -346,9 +338,7 @@ mod mapping { #[ignore] #[ink_e2e::test] - async fn fallible_storage_methods_work( - mut client: Client, - ) -> E2EResult<()> { + async fn fallible_storage_methods_work(mut client: Client) -> E2EResult<()> { // Makes testing the fallible storage methods more efficient const ERR: &str = "For this test the env variable `INK_STATIC_BUFFER_SIZE` needs to be set to `256`"; let buffer_size = std::env::var("INK_STATIC_BUFFER_SIZE") diff --git a/integration-tests/internal/misc-evm-getters-hostfns/lib.rs b/integration-tests/internal/misc-evm-getters-hostfns/lib.rs index 24109cbb7bb..1e6b82ab333 100644 --- a/integration-tests/internal/misc-evm-getters-hostfns/lib.rs +++ b/integration-tests/internal/misc-evm-getters-hostfns/lib.rs @@ -73,9 +73,7 @@ mod misc_evm_getters_hostfns { type E2EResult = std::result::Result>; #[ink_e2e::test] - async fn e2e_chain_id_works( - mut client: Client, - ) -> E2EResult<()> { + async fn e2e_chain_id_works(mut client: Client) -> E2EResult<()> { // given let contract = client .instantiate( @@ -103,9 +101,7 @@ mod misc_evm_getters_hostfns { } #[ink_e2e::test] - async fn e2e_balance_of_works( - mut client: Client, - ) -> E2EResult<()> { + async fn e2e_balance_of_works(mut client: Client) -> E2EResult<()> { // given let contract = client .instantiate( @@ -133,9 +129,7 @@ mod misc_evm_getters_hostfns { } #[ink_e2e::test] - async fn e2e_base_fee_works( - mut client: Client, - ) -> E2EResult<()> { + async fn e2e_base_fee_works(mut client: Client) -> E2EResult<()> { // given let contract = client .instantiate( @@ -163,9 +157,7 @@ mod misc_evm_getters_hostfns { } #[ink_e2e::test] - async fn e2e_origin_works( - mut client: Client, - ) -> E2EResult<()> { + async fn e2e_origin_works(mut client: Client) -> E2EResult<()> { // given let contract = client .instantiate( @@ -196,9 +188,7 @@ mod misc_evm_getters_hostfns { } #[ink_e2e::test] - async fn e2e_code_size_works( - mut client: Client, - ) -> E2EResult<()> { + async fn e2e_code_size_works(mut client: Client) -> E2EResult<()> { // given let contract = client .instantiate( @@ -226,9 +216,7 @@ mod misc_evm_getters_hostfns { } #[ink_e2e::test] - async fn e2e_block_hash_works( - mut client: Client, - ) -> E2EResult<()> { + async fn e2e_block_hash_works(mut client: Client) -> E2EResult<()> { // given let contract = client .instantiate( @@ -257,9 +245,7 @@ mod misc_evm_getters_hostfns { } #[ink_e2e::test] - async fn e2e_block_author_works( - mut client: Client, - ) -> E2EResult<()> { + async fn e2e_block_author_works(mut client: Client) -> E2EResult<()> { // given let contract = client .instantiate( diff --git a/integration-tests/internal/misc-hostfns/lib.rs b/integration-tests/internal/misc-hostfns/lib.rs index eb94943ed9c..247a10b5f21 100755 --- a/integration-tests/internal/misc-hostfns/lib.rs +++ b/integration-tests/internal/misc-hostfns/lib.rs @@ -60,9 +60,7 @@ mod misc_hostfns { type E2EResult = std::result::Result>; #[ink_e2e::test] - async fn e2e_addr_account_id_works( - mut client: Client, - ) -> E2EResult<()> { + async fn e2e_addr_account_id_works(mut client: Client) -> E2EResult<()> { // given let contract = client .instantiate( @@ -88,9 +86,7 @@ mod misc_hostfns { } #[ink_e2e::test] - async fn e2e_is_contract_works( - mut client: Client, - ) -> E2EResult<()> { + async fn e2e_is_contract_works(mut client: Client) -> E2EResult<()> { // given let contract = client .instantiate("misc_hostfns", &ink_e2e::bob(), &mut MiscHostfnsRef::new()) diff --git a/integration-tests/internal/overflow-safety/lib.rs b/integration-tests/internal/overflow-safety/lib.rs index 6dae7798da5..1feb4fe7c2b 100644 --- a/integration-tests/internal/overflow-safety/lib.rs +++ b/integration-tests/internal/overflow-safety/lib.rs @@ -73,9 +73,7 @@ pub mod overflow_safety { type E2EResult = std::result::Result>; #[ink_e2e::test] - async fn add_no_overflow_works( - mut client: Client, - ) -> E2EResult<()> { + async fn add_no_overflow_works(mut client: Client) -> E2EResult<()> { // given let mut constructor = OverflowSafetyRef::new(); let contract = client @@ -98,9 +96,7 @@ pub mod overflow_safety { } #[ink_e2e::test] - async fn add_with_overflow_reverts( - mut client: Client, - ) -> E2EResult<()> { + async fn add_with_overflow_reverts(mut client: Client) -> E2EResult<()> { // given let mut constructor = OverflowSafetyRef::new(); let contract = client @@ -119,9 +115,7 @@ pub mod overflow_safety { } #[ink_e2e::test] - async fn sub_no_overflow_works( - mut client: Client, - ) -> E2EResult<()> { + async fn sub_no_overflow_works(mut client: Client) -> E2EResult<()> { // given let mut constructor = OverflowSafetyRef::new(); let contract = client @@ -144,9 +138,7 @@ pub mod overflow_safety { } #[ink_e2e::test] - async fn sub_with_overflow_reverts( - mut client: Client, - ) -> E2EResult<()> { + async fn sub_with_overflow_reverts(mut client: Client) -> E2EResult<()> { // given let mut constructor = OverflowSafetyRef::new(); let contract = client diff --git a/integration-tests/internal/static-buffer/lib.rs b/integration-tests/internal/static-buffer/lib.rs index f299a5f5243..e8cdc51ef6d 100644 --- a/integration-tests/internal/static-buffer/lib.rs +++ b/integration-tests/internal/static-buffer/lib.rs @@ -67,9 +67,7 @@ pub mod static_buffer { } #[ink_e2e::test] - async fn e2e_run_out_of_buffer_memory( - mut client: Client, - ) -> E2EResult<()> { + async fn e2e_run_out_of_buffer_memory(mut client: Client) -> E2EResult<()> { // given assert_buffer_size(); let mut constructor = StaticBufferRef::new(true); @@ -97,7 +95,7 @@ pub mod static_buffer { } #[ink_e2e::test] - async fn buffer(mut client: Client) -> E2EResult<()> { + async fn buffer(mut client: Client) -> E2EResult<()> { // given assert_buffer_size(); let mut constructor = StaticBufferRef::new_default(); diff --git a/integration-tests/internal/system-precompile/lib.rs b/integration-tests/internal/system-precompile/lib.rs index 72e0d769bff..1fed4171401 100755 --- a/integration-tests/internal/system-precompile/lib.rs +++ b/integration-tests/internal/system-precompile/lib.rs @@ -34,9 +34,7 @@ mod system_precompile { type E2EResult = std::result::Result>; #[ink_e2e::test] - async fn minimum_balance_works( - mut client: Client, - ) -> E2EResult<()> { + async fn minimum_balance_works(mut client: Client) -> E2EResult<()> { // given let mut constructor = SystemPrecompileRef::new(); let contract = client diff --git a/integration-tests/public/assets-precompile/Cargo.toml b/integration-tests/public/assets-precompile/Cargo.toml index 012fa9be2ab..56a7d5a70eb 100644 --- a/integration-tests/public/assets-precompile/Cargo.toml +++ b/integration-tests/public/assets-precompile/Cargo.toml @@ -11,7 +11,7 @@ ink_precompiles = { path = "../../../crates/precompiles", default-features = fal [dev-dependencies] ink_e2e = { path = "../../../crates/e2e" } -ink_sandbox = { path = "../../../crates/sandbox" } +ink_runtime = { path = "../../../crates/runtime" } hex = "0.4" [lib] diff --git a/integration-tests/public/assets-precompile/lib.rs b/integration-tests/public/assets-precompile/lib.rs index bc37c157ef3..86d455b3822 100644 --- a/integration-tests/public/assets-precompile/lib.rs +++ b/integration-tests/public/assets-precompile/lib.rs @@ -189,10 +189,8 @@ mod e2e_tests { alice, bob, }; - use ink_sandbox::{ - DefaultSandbox, + use ink_runtime::{ E2EError, - SandboxClient, api::prelude::{ AssetsAPI, ContractAPI, @@ -204,11 +202,8 @@ mod e2e_tests { type E2EResult = std::result::Result; - #[ink_sandbox::test(backend(runtime_only( - sandbox = DefaultSandbox, - client = SandboxClient - )))] - async fn deployment_works(mut client: Client) -> E2EResult<()> { + #[ink_e2e::test(runtime)] + async fn deployment_works(mut client: Client) -> E2EResult<()> { let asset_id: u32 = 1; let mut constructor = AssetHubPrecompileRef::new(asset_id); @@ -229,16 +224,13 @@ mod e2e_tests { Ok(()) } - #[ink_sandbox::test(backend(runtime_only( - sandbox = DefaultSandbox, - client = SandboxClient - )))] - async fn total_supply_works(mut client: Client) -> E2EResult<()> { + #[ink_e2e::test(runtime)] + async fn total_supply_works(mut client: Client) -> E2EResult<()> { let asset_id: u32 = 1; let admin = alice(); - client.sandbox().create(&asset_id, &admin, 1u128)?; - client.sandbox().mint_into(&asset_id, &admin, 1000u128)?; + client.runtime().create(&asset_id, &admin, 1u128)?; + client.runtime().mint_into(&asset_id, &admin, 1000u128)?; let contract = client .instantiate( @@ -259,18 +251,15 @@ mod e2e_tests { Ok(()) } - #[ink_sandbox::test(backend(runtime_only( - sandbox = DefaultSandbox, - client = SandboxClient - )))] - async fn balance_of_works(mut client: Client) -> E2EResult<()> { + #[ink_e2e::test(runtime)] + async fn balance_of_works(mut client: Client) -> E2EResult<()> { let asset_id: u32 = 1; let alice = alice(); let bob = bob(); - client.sandbox().create(&asset_id, &alice, 1u128)?; - client.sandbox().mint_into(&asset_id, &alice, 1000u128)?; - client.sandbox().mint_into(&asset_id, &bob, 500u128)?; + client.runtime().create(&asset_id, &alice, 1u128)?; + client.runtime().mint_into(&asset_id, &alice, 1000u128)?; + client.runtime().mint_into(&asset_id, &bob, 500u128)?; let contract = client .instantiate( @@ -282,7 +271,7 @@ mod e2e_tests { .await?; // Map bob's account otherwise it fails. - client.sandbox().map_account(&bob)?; + client.runtime().map_account(&bob)?; let contract_call = contract.call_builder::(); let alice_balance = client @@ -299,16 +288,13 @@ mod e2e_tests { Ok(()) } - #[ink_sandbox::test(backend(runtime_only( - sandbox = DefaultSandbox, - client = SandboxClient - )))] - async fn transfer_works(mut client: Client) -> E2EResult<()> { + #[ink_e2e::test(runtime)] + async fn transfer_works(mut client: Client) -> E2EResult<()> { let asset_id: u32 = 1; let alice = alice(); let bob = bob(); - client.sandbox().create(&asset_id, &alice, 1u128)?; + client.runtime().create(&asset_id, &alice, 1u128)?; let contract = client .instantiate( @@ -320,9 +306,9 @@ mod e2e_tests { .await?; client - .sandbox() + .runtime() .mint_into(&asset_id, &contract.account_id, 100_000u128)?; - client.sandbox().map_account(&bob)?; + client.runtime().map_account(&bob)?; let mut contract_call = contract.call_builder::(); let bob_address = bob.address(); @@ -346,8 +332,8 @@ mod e2e_tests { ); let contract_balance = - client.sandbox().balance_of(&asset_id, &contract.account_id); - let bob_balance = client.sandbox().balance_of(&asset_id, &bob); + client.runtime().balance_of(&asset_id, &contract.account_id); + let bob_balance = client.runtime().balance_of(&asset_id, &bob); assert_eq!(contract_balance, 99_000u128); assert_eq!(bob_balance, 1_000u128); @@ -363,16 +349,13 @@ mod e2e_tests { Ok(()) } - #[ink_sandbox::test(backend(runtime_only( - sandbox = DefaultSandbox, - client = SandboxClient - )))] - async fn approve_works(mut client: Client) -> E2EResult<()> { + #[ink_e2e::test(runtime)] + async fn approve_works(mut client: Client) -> E2EResult<()> { let asset_id: u32 = 1; let alice = alice(); let bob = bob(); - client.sandbox().create(&asset_id, &alice, 1u128)?; + client.runtime().create(&asset_id, &alice, 1u128)?; let contract = client .instantiate("assets_precompile", &alice, &mut AssetHubPrecompileRef::new(asset_id)) @@ -382,12 +365,12 @@ mod e2e_tests { .await?; client - .sandbox() + .runtime() .mint_into(&asset_id, &contract.account_id, 100_000u128)?; - client.sandbox().map_account(&bob)?; + client.runtime().map_account(&bob)?; let bob_allowance_before = client - .sandbox() + .runtime() .allowance(&asset_id, &contract.account_id, &bob); assert_eq!(bob_allowance_before, 0u128); // Bob's allowance is 0 @@ -411,23 +394,20 @@ mod e2e_tests { let bob_allowance = client - .sandbox() + .runtime() .allowance(&asset_id, &contract.account_id, &bob); assert_eq!(bob_allowance, 200u128); Ok(()) } - #[ink_sandbox::test(backend(runtime_only( - sandbox = DefaultSandbox, - client = SandboxClient - )))] - async fn allowance_works(mut client: Client) -> E2EResult<()> { + #[ink_e2e::test(runtime)] + async fn allowance_works(mut client: Client) -> E2EResult<()> { let asset_id: u32 = 1; let alice = alice(); let bob = bob(); - client.sandbox().create(&asset_id, &alice, 1u128)?; + client.runtime().create(&asset_id, &alice, 1u128)?; let contract = client .instantiate( @@ -439,15 +419,15 @@ mod e2e_tests { .await?; let contract_call = contract.call_builder::(); - client.sandbox().mint_into(&asset_id, &alice, 100_000u128)?; - client.sandbox().map_account(&bob)?; + client.runtime().mint_into(&asset_id, &alice, 100_000u128)?; + client.runtime().map_account(&bob)?; let allowance_call = &contract_call.allowance(alice.address(), bob.address()); let result = client.call(&alice, allowance_call).dry_run().await?; assert_eq!(result.return_value(), U256::from(0)); // Approve bob to spend alice's tokens - client.sandbox().approve(&asset_id, &alice, &bob, 300u128)?; + client.runtime().approve(&asset_id, &alice, &bob, 300u128)?; let result = client.call(&alice, allowance_call).dry_run().await?; assert_eq!(result.return_value(), U256::from(300)); @@ -455,18 +435,13 @@ mod e2e_tests { Ok(()) } - #[ink_sandbox::test(backend(runtime_only( - sandbox = DefaultSandbox, - client = SandboxClient - )))] - async fn transfer_from_works( - mut client: Client, - ) -> E2EResult<()> { + #[ink_e2e::test(runtime)] + async fn transfer_from_works(mut client: Client) -> E2EResult<()> { let asset_id: u32 = 1; let alice = alice(); let bob = bob(); - client.sandbox().create(&asset_id, &alice, 1u128)?; + client.runtime().create(&asset_id, &alice, 1u128)?; let contract = client .instantiate( @@ -477,12 +452,12 @@ mod e2e_tests { .submit() .await?; - client.sandbox().mint_into(&asset_id, &alice, 100_000u128)?; + client.runtime().mint_into(&asset_id, &alice, 100_000u128)?; // Approve alice to spend contract's tokens client - .sandbox() + .runtime() .approve(&asset_id, &alice, &contract.account_id, 50_000u128)?; - client.sandbox().map_account(&bob)?; + client.runtime().map_account(&bob)?; let mut contract_call = contract.call_builder::(); let alice_address = alice.address(); @@ -505,11 +480,11 @@ mod e2e_tests { } ); - let alice_balance = client.sandbox().balance_of(&asset_id, &alice); - let bob_balance = client.sandbox().balance_of(&asset_id, &bob); + let alice_balance = client.runtime().balance_of(&asset_id, &alice); + let bob_balance = client.runtime().balance_of(&asset_id, &bob); let contract_allowance = client - .sandbox() + .runtime() .allowance(&asset_id, &alice, &contract.account_id); assert_eq!(alice_balance, 98_500u128); assert_eq!(bob_balance, 1_500u128); diff --git a/integration-tests/public/bytes/lib.rs b/integration-tests/public/bytes/lib.rs index aa0a4939222..ac434fe4824 100644 --- a/integration-tests/public/bytes/lib.rs +++ b/integration-tests/public/bytes/lib.rs @@ -128,9 +128,7 @@ pub mod bytes { type E2EResult = std::result::Result>; #[ink_e2e::test] - async fn fixed_bytes_works( - mut client: Client, - ) -> E2EResult<()> { + async fn fixed_bytes_works(mut client: Client) -> E2EResult<()> { // given let mut constructor = BytesRef::new(); let contract = client @@ -171,9 +169,7 @@ pub mod bytes { } #[ink_e2e::test] - async fn dyn_bytes_works( - mut client: Client, - ) -> E2EResult<()> { + async fn dyn_bytes_works(mut client: Client) -> E2EResult<()> { // given let mut constructor = BytesRef::new(); let contract = client diff --git a/integration-tests/public/contract-invocation/lib.rs b/integration-tests/public/contract-invocation/lib.rs index 9a7188affb4..636dc2c39df 100644 --- a/integration-tests/public/contract-invocation/lib.rs +++ b/integration-tests/public/contract-invocation/lib.rs @@ -427,9 +427,7 @@ mod instantiate_contract { } #[ink_e2e::test] - async fn test_invoke_delegate_e2e( - mut client: Client, - ) -> E2EResult<()> { + async fn test_invoke_delegate_e2e(mut client: Client) -> E2EResult<()> { let origin = client .create_and_fund_account(&ink_e2e::alice(), 10_000_000_000_000) .await; diff --git a/integration-tests/public/contract-storage/e2e_tests.rs b/integration-tests/public/contract-storage/e2e_tests.rs index 684d740d83c..58040a43cb1 100644 --- a/integration-tests/public/contract-storage/e2e_tests.rs +++ b/integration-tests/public/contract-storage/e2e_tests.rs @@ -4,7 +4,7 @@ use ink_e2e::ContractsBackend; type E2EResult = std::result::Result>; #[ink_e2e::test] -async fn get_contract_storage_consumes_entire_buffer( +async fn get_contract_storage_consumes_entire_buffer( mut client: Client, ) -> E2EResult<()> { // given @@ -33,9 +33,7 @@ async fn get_contract_storage_consumes_entire_buffer( } #[ink_e2e::test] -async fn get_contract_storage_fails_when_extra_data( - mut client: Client, -) -> E2EResult<()> { +async fn get_contract_storage_fails_when_extra_data(mut client: Client) -> E2EResult<()> { // given let mut constructor = ContractStorageRef::new(); let contract = client @@ -63,7 +61,7 @@ async fn get_contract_storage_fails_when_extra_data( } #[ink_e2e::test] -async fn take_contract_storage_consumes_entire_buffer( +async fn take_contract_storage_consumes_entire_buffer( mut client: Client, ) -> E2EResult<()> { // given @@ -92,7 +90,7 @@ async fn take_contract_storage_consumes_entire_buffer( } #[ink_e2e::test] -async fn take_contract_storage_fails_when_extra_data( +async fn take_contract_storage_fails_when_extra_data( mut client: Client, ) -> E2EResult<()> { // given diff --git a/integration-tests/public/contract-terminate/lib.rs b/integration-tests/public/contract-terminate/lib.rs index 41632a4892e..965813bd615 100644 --- a/integration-tests/public/contract-terminate/lib.rs +++ b/integration-tests/public/contract-terminate/lib.rs @@ -57,9 +57,7 @@ pub mod just_terminates { type E2EResult = std::result::Result>; #[ink_e2e::test] - async fn e2e_contract_terminates( - mut client: Client, - ) -> E2EResult<()> { + async fn e2e_contract_terminates(mut client: Client) -> E2EResult<()> { // given let mut constructor = JustTerminateRef::new(); let contract = client diff --git a/integration-tests/public/contract-transfer/Cargo.toml b/integration-tests/public/contract-transfer/Cargo.toml index 2f74796fbcf..deec04f2653 100644 --- a/integration-tests/public/contract-transfer/Cargo.toml +++ b/integration-tests/public/contract-transfer/Cargo.toml @@ -10,7 +10,7 @@ ink = { path = "../../../crates/ink", default-features = false } [dev-dependencies] ink_e2e = { path = "../../../crates/e2e"} -ink_sandbox = { path = "../../../crates/sandbox" } +ink_runtime = { path = "../../../crates/runtime" } [lib] path = "lib.rs" diff --git a/integration-tests/public/contract-transfer/lib.rs b/integration-tests/public/contract-transfer/lib.rs index dfeb8e865ae..bafdbbc25d7 100644 --- a/integration-tests/public/contract-transfer/lib.rs +++ b/integration-tests/public/contract-transfer/lib.rs @@ -190,7 +190,7 @@ pub mod give_me { type E2EResult = std::result::Result>; #[ink_e2e::test] - async fn e2e_sending_value_to_give_me_must_fail( + async fn e2e_sending_value_to_give_me_must_fail( mut client: Client, ) -> E2EResult<()> { // given @@ -225,11 +225,8 @@ pub mod give_me { Ok(()) } - #[ink_sandbox::test(backend(runtime_only( - sandbox = ink_sandbox::DefaultSandbox, - client = ink_sandbox::SandboxClient - )))] - async fn e2e_contract_must_transfer_value_to_sender( + #[ink_e2e::test(runtime)] + async fn e2e_contract_must_transfer_value_to_sender( mut client: Client, ) -> E2EResult<()> { // given diff --git a/integration-tests/public/contract-xcm/lib.rs b/integration-tests/public/contract-xcm/lib.rs index bf767dfedcd..0f3d8e5e4b9 100644 --- a/integration-tests/public/contract-xcm/lib.rs +++ b/integration-tests/public/contract-xcm/lib.rs @@ -166,9 +166,7 @@ mod contract_xcm { type E2EResult = Result>; #[ink_e2e::test] - async fn xcm_execute_works( - mut client: Client, - ) -> E2EResult<()> { + async fn xcm_execute_works(mut client: Client) -> E2EResult<()> { // given let mut constructor = ContractXcmRef::new(); let contract = client @@ -217,7 +215,7 @@ mod contract_xcm { } #[ink_e2e::test] - async fn xcm_execute_failure_detection_works( + async fn xcm_execute_failure_detection_works( mut client: Client, ) -> E2EResult<()> { // todo @cmichi: This sleep is necessary until we have our `ink-node` @@ -257,7 +255,7 @@ mod contract_xcm { } #[ink_e2e::test] - async fn xcm_send_works(mut client: Client) -> E2EResult<()> { + async fn xcm_send_works(mut client: Client) -> E2EResult<()> { // todo @cmichi: This sleep is necessary until we have our `ink-node` // support a parachain/relaychain setup. For the moment we use the // Rococo runtime for testing the examples locally. That runtime diff --git a/integration-tests/public/cross-contract-calls-advanced/e2e_tests.rs b/integration-tests/public/cross-contract-calls-advanced/e2e_tests.rs index ff578d7edbb..245687a9338 100644 --- a/integration-tests/public/cross-contract-calls-advanced/e2e_tests.rs +++ b/integration-tests/public/cross-contract-calls-advanced/e2e_tests.rs @@ -4,7 +4,7 @@ use ink_e2e::ContractsBackend; type E2EResult = std::result::Result>; #[ink_e2e::test] -async fn instantiate_with_insufficient_storage_deposit_limit( +async fn instantiate_with_insufficient_storage_deposit_limit( mut client: Client, ) -> E2EResult<()> { // given @@ -43,9 +43,7 @@ async fn instantiate_with_insufficient_storage_deposit_limit } #[ink_e2e::test] -async fn instantiate_with_sufficient_limits( - mut client: Client, -) -> E2EResult<()> { +async fn instantiate_with_sufficient_limits(mut client: Client) -> E2EResult<()> { // given let other_contract_code = client .upload("other-contract", &ink_e2e::alice()) @@ -80,7 +78,7 @@ async fn instantiate_with_sufficient_limits( } #[ink_e2e::test] -async fn instantiate_no_limits(mut client: Client) -> E2EResult<()> { +async fn instantiate_no_limits(mut client: Client) -> E2EResult<()> { // given let other_contract_code = client .upload("other-contract", &ink_e2e::alice()) @@ -105,7 +103,7 @@ async fn instantiate_no_limits(mut client: Client) -> E2ERes } #[ink_e2e::test] -async fn flip_and_get(mut client: Client) -> E2EResult<()> { +async fn flip_and_get(mut client: Client) -> E2EResult<()> { // given let other_contract_code = client .upload("other-contract", &ink_e2e::alice()) diff --git a/integration-tests/public/cross-contract-calls/e2e_tests.rs b/integration-tests/public/cross-contract-calls/e2e_tests.rs index 33f54de7d41..b658bb8fd4b 100644 --- a/integration-tests/public/cross-contract-calls/e2e_tests.rs +++ b/integration-tests/public/cross-contract-calls/e2e_tests.rs @@ -5,7 +5,7 @@ use other_contract::OtherContractRef; type E2EResult = std::result::Result>; #[ink_e2e::test] -async fn instantiate_no_limits(mut client: Client) -> E2EResult<()> { +async fn instantiate_no_limits(mut client: Client) -> E2EResult<()> { // given let mut other_constructor = OtherContractRef::new(true); let other_contract = client @@ -28,7 +28,7 @@ async fn instantiate_no_limits(mut client: Client) -> E2ERes } #[ink_e2e::test] -async fn flip_and_get(mut client: Client) -> E2EResult<()> { +async fn flip_and_get(mut client: Client) -> E2EResult<()> { // given let mut other_constructor = OtherContractRef::new(true); let other_contract = client diff --git a/integration-tests/public/custom-allocator/lib.rs b/integration-tests/public/custom-allocator/lib.rs index 81970fa694f..f77aec9ffe0 100755 --- a/integration-tests/public/custom-allocator/lib.rs +++ b/integration-tests/public/custom-allocator/lib.rs @@ -169,7 +169,7 @@ mod custom_allocator { /// We test that we can upload and instantiate the contract using its default /// constructor. #[ink_e2e::test] - async fn default_works(mut client: Client) -> E2EResult<()> { + async fn default_works(mut client: Client) -> E2EResult<()> { // Given let mut constructor = CustomAllocatorRef::default(); @@ -191,7 +191,7 @@ mod custom_allocator { /// We test that we can read and write a value from the on-chain contract. #[ink_e2e::test] - async fn it_works(mut client: Client) -> E2EResult<()> { + async fn it_works(mut client: Client) -> E2EResult<()> { // Given let mut constructor = CustomAllocatorRef::new(false); let contract = client diff --git a/integration-tests/public/custom-environment/lib.rs b/integration-tests/public/custom-environment/lib.rs index 495ffe5ed68..52ad4034e0c 100644 --- a/integration-tests/public/custom-environment/lib.rs +++ b/integration-tests/public/custom-environment/lib.rs @@ -87,9 +87,7 @@ mod runtime_call { #[cfg(feature = "permissive-node")] #[ink_e2e::test(environment = crate::EnvironmentWithManyTopics)] - async fn calling_custom_environment_works( - mut client: Client, - ) -> E2EResult<()> { + async fn calling_custom_environment_works(mut client: Client) -> E2EResult<()> { // given let mut constructor = TopicsRef::new(); let contract = client @@ -116,9 +114,7 @@ mod runtime_call { #[cfg(not(feature = "permissive-node"))] #[ink_e2e::test(environment = crate::EnvironmentWithManyTopics)] - async fn calling_custom_environment_fails_if_incompatible_with_node< - Client: E2EBackend, - >( + async fn calling_custom_environment_fails_if_incompatible_with_node( mut client: Client, ) -> E2EResult<()> { // given diff --git a/integration-tests/public/debugging-strategies/lib.rs b/integration-tests/public/debugging-strategies/lib.rs index 6fc1ebd8334..5805d655c1c 100755 --- a/integration-tests/public/debugging-strategies/lib.rs +++ b/integration-tests/public/debugging-strategies/lib.rs @@ -121,9 +121,7 @@ mod debugging_strategies { /// we can have code in the contract that is utilized purely /// for testing, but not for release builds. #[ink_e2e::test(features = ["debug"])] - async fn e2e_debugging_event_emitted( - mut client: Client, - ) -> E2EResult<()> { + async fn e2e_debugging_event_emitted(mut client: Client) -> E2EResult<()> { // given let mut constructor = DebuggingStrategiesRef::new(); let contract = client @@ -156,9 +154,7 @@ mod debugging_strategies { /// This test illustrates how to decode a `Revive::ContractReverted`. #[ink_e2e::test(features = ["debug"])] - async fn e2e_decode_intentional_revert( - mut client: Client, - ) -> E2EResult<()> { + async fn e2e_decode_intentional_revert(mut client: Client) -> E2EResult<()> { // given let mut constructor = DebuggingStrategiesRef::new(); let contract = client @@ -185,9 +181,7 @@ mod debugging_strategies { /// This test illustrates how to decode a `Revive::ContractReverted`. #[ink_e2e::test] - async fn e2e_decode_revert( - mut client: Client, - ) -> E2EResult<()> { + async fn e2e_decode_revert(mut client: Client) -> E2EResult<()> { // given let mut constructor = DebuggingStrategiesRef::new(); let contract = client @@ -234,7 +228,7 @@ mod debugging_strategies { /// This test illustrates how to use the `pallet-revive` tracing functionality. #[ink_e2e::test] - async fn e2e_tracing(mut client: Client) -> E2EResult<()> { + async fn e2e_tracing(mut client: Client) -> E2EResult<()> { // given let mut constructor = DebuggingStrategiesRef::new(); let contract = client @@ -312,6 +306,6 @@ mod debugging_strategies { Ok(()) } - // todo add the same above, but for the sandbox + // todo add the same above, but for the runtime backend } } diff --git a/integration-tests/public/e2e-call-runtime/lib.rs b/integration-tests/public/e2e-call-runtime/lib.rs index c8d5a7e3704..fa69b8b0103 100644 --- a/integration-tests/public/e2e-call-runtime/lib.rs +++ b/integration-tests/public/e2e-call-runtime/lib.rs @@ -32,9 +32,7 @@ pub mod e2e_call_runtime { type E2EResult = std::result::Result>; #[ink_e2e::test] - async fn call_runtime_works( - mut client: Client, - ) -> E2EResult<()> { + async fn call_runtime_works(mut client: Client) -> E2EResult<()> { // given let mut constructor = ContractRef::new(); let contract = client diff --git a/integration-tests/public/erc20/lib.rs b/integration-tests/public/erc20/lib.rs index 25d738a15b0..fd41432384e 100644 --- a/integration-tests/public/erc20/lib.rs +++ b/integration-tests/public/erc20/lib.rs @@ -536,7 +536,7 @@ mod erc20 { type E2EResult = std::result::Result>; #[ink_e2e::test] - async fn e2e_transfer(mut client: Client) -> E2EResult<()> { + async fn e2e_transfer(mut client: Client) -> E2EResult<()> { // given let total_supply = U256::from(1_000_000_000); let mut constructor = Erc20Ref::new(total_supply); @@ -583,7 +583,7 @@ mod erc20 { } #[ink_e2e::test] - async fn e2e_allowances(mut client: Client) -> E2EResult<()> { + async fn e2e_allowances(mut client: Client) -> E2EResult<()> { // given let total_supply = U256::from(1_000_000_000); let mut constructor = Erc20Ref::new(total_supply); diff --git a/integration-tests/public/events/lib.rs b/integration-tests/public/events/lib.rs index 95d63361568..48420cf3e57 100644 --- a/integration-tests/public/events/lib.rs +++ b/integration-tests/public/events/lib.rs @@ -280,9 +280,7 @@ pub mod events { type E2EResult = std::result::Result>; #[ink_e2e::test] - async fn emits_foreign_event( - mut client: Client, - ) -> E2EResult<()> { + async fn emits_foreign_event(mut client: Client) -> E2EResult<()> { // given let init_value = false; let mut constructor = EventsRef::new(init_value); @@ -323,9 +321,7 @@ pub mod events { } #[ink_e2e::test] - async fn emits_inline_event( - mut client: Client, - ) -> E2EResult<()> { + async fn emits_inline_event(mut client: Client) -> E2EResult<()> { // given let init_value = false; let mut constructor = EventsRef::new(init_value); @@ -365,9 +361,7 @@ pub mod events { } #[ink_e2e::test()] - async fn emits_inline_anonymous_event( - mut client: Client, - ) -> E2EResult<()> { + async fn emits_inline_anonymous_event(mut client: Client) -> E2EResult<()> { use ink::env::hash::{ Blake2x256, CryptoHash, @@ -431,9 +425,7 @@ pub mod events { } #[ink_e2e::test] - async fn emits_event_with_option_topic_none( - mut client: Client, - ) -> E2EResult<()> { + async fn emits_event_with_option_topic_none(mut client: Client) -> E2EResult<()> { // given let init_value = false; let mut constructor = EventsRef::new(init_value); @@ -478,9 +470,7 @@ pub mod events { } #[ink_e2e::test] - async fn emits_custom_signature_event( - mut client: Client, - ) -> E2EResult<()> { + async fn emits_custom_signature_event(mut client: Client) -> E2EResult<()> { // given let init_value = false; let mut constructor = EventsRef::new(init_value); diff --git a/integration-tests/public/fallible-setter/lib.rs b/integration-tests/public/fallible-setter/lib.rs index 5740ace7fcc..e32c487a4a4 100644 --- a/integration-tests/public/fallible-setter/lib.rs +++ b/integration-tests/public/fallible-setter/lib.rs @@ -90,7 +90,7 @@ pub mod fallible_setter { type E2EResult = std::result::Result>; #[ink_e2e::test] - async fn it_works(mut client: Client) -> E2EResult<()> { + async fn it_works(mut client: Client) -> E2EResult<()> { // given let mut constructor = FallibleSetterRef::new(0); let contract = client diff --git a/integration-tests/public/flipper/lib.rs b/integration-tests/public/flipper/lib.rs index 60eec1b81c7..9ab3412ed19 100644 --- a/integration-tests/public/flipper/lib.rs +++ b/integration-tests/public/flipper/lib.rs @@ -48,7 +48,7 @@ pub mod flipper { type E2EResult = std::result::Result>; #[ink_e2e::test] - async fn it_works(mut client: Client) -> E2EResult<()> { + async fn it_works(mut client: Client) -> E2EResult<()> { // given let mut constructor = FlipperRef::new(false); let contract = client @@ -107,9 +107,7 @@ pub mod flipper { /// The test is marked as ignored, as it has the above pre-conditions to succeed. #[ink_e2e::test] #[ignore] - async fn e2e_test_deployed_contract( - mut client: Client, - ) -> E2EResult<()> { + async fn e2e_test_deployed_contract(mut client: Client) -> E2EResult<()> { // given use ink::Address; let addr = std::env::var("CONTRACT_ADDR_HEX") diff --git a/integration-tests/public/fuzz-testing/Cargo.toml b/integration-tests/public/fuzz-testing/Cargo.toml index ff762f18782..fe80cc1e365 100644 --- a/integration-tests/public/fuzz-testing/Cargo.toml +++ b/integration-tests/public/fuzz-testing/Cargo.toml @@ -10,7 +10,7 @@ ink = { path = "../../../crates/ink", default-features = false } [dev-dependencies] ink_e2e = { path = "../../../crates/e2e" } -ink_sandbox = { path = "../../../crates/sandbox" } +ink_runtime = { path = "../../../crates/runtime" } # for fuzz testing quickcheck = { version = "1" } diff --git a/integration-tests/public/fuzz-testing/lib.rs b/integration-tests/public/fuzz-testing/lib.rs index 9ac1bed217d..ab57f64b416 100644 --- a/integration-tests/public/fuzz-testing/lib.rs +++ b/integration-tests/public/fuzz-testing/lib.rs @@ -42,15 +42,12 @@ pub mod fuzz_testing { use ink_e2e::ContractsBackend; use quickcheck_macros::quickcheck; - /// We use `backend(runtime_only)` here. It doesn't start a node for each test, - /// but instead interacts with a sandboxed `pallet-revive`. + /// We use `#[ink_e2e::test(runtime)]` here. It doesn't start a node for each + /// test, but instead interacts with an in-process `pallet-revive`. /// /// See /// for more details. - #[ink_sandbox::test(replace_test_attr = "#[quickcheck]", backend(runtime_only( - sandbox = ink_sandbox::DefaultSandbox, - client = ink_sandbox::SandboxClient - )))] + #[ink_e2e::test(runtime, replace_test_attr = "#[quickcheck]")] async fn fuzzing_works_runtime(val: bool) -> bool { let mut constructor = FuzzTestingRef::new(val); let contract = client @@ -70,12 +67,9 @@ pub mod fuzz_testing { /// This means that, by default, for every test run a node process will /// be spawned. You can work around this by setting the env variable /// `CONTRACTS_NODE_URL`. But still, interactions with a real node will - /// always be more heavy-weight than "just" interacting with a sandboxed + /// always be more heavy-weight than "just" interacting with an in-process /// `pallet-revive`. - #[ink_sandbox::test(replace_test_attr = "#[quickcheck]", backend(runtime_only( - sandbox = ink_sandbox::DefaultSandbox, - client = ink_sandbox::SandboxClient - )))] + #[ink_e2e::test(runtime, replace_test_attr = "#[quickcheck]")] async fn fuzzing_works_node(val: bool) -> bool { let mut constructor = FuzzTestingRef::new(val); let contract = client @@ -105,10 +99,7 @@ pub mod fuzz_testing { } } - #[ink_sandbox::test(replace_test_attr = "#[quickcheck]", backend(runtime_only( - sandbox = ink_sandbox::DefaultSandbox, - client = ink_sandbox::SandboxClient - )))] + #[ink_e2e::test(runtime, replace_test_attr = "#[quickcheck]")] async fn fuzzing_custom_struct_works(val: Point) -> bool { ink_e2e::tracing::info!("fuzzing with value {val:?}"); diff --git a/integration-tests/public/lazyvec/lib.rs b/integration-tests/public/lazyvec/lib.rs index 54924d4ee51..8635334bd86 100755 --- a/integration-tests/public/lazyvec/lib.rs +++ b/integration-tests/public/lazyvec/lib.rs @@ -96,9 +96,7 @@ mod lazyvec { type E2EResult = std::result::Result>; #[ink_e2e::test] - async fn create_and_vote( - mut client: Client, - ) -> E2EResult<()> { + async fn create_and_vote(mut client: Client) -> E2EResult<()> { // given let mut constructor = LazyVectorRef::default(); let contract = client diff --git a/integration-tests/public/multi-contract-caller/lib.rs b/integration-tests/public/multi-contract-caller/lib.rs index adcbfa5f0cc..e86369943c6 100644 --- a/integration-tests/public/multi-contract-caller/lib.rs +++ b/integration-tests/public/multi-contract-caller/lib.rs @@ -126,9 +126,7 @@ mod multi_contract_caller { type E2EResult = std::result::Result>; #[ink_e2e::test] - async fn e2e_multi_contract_caller( - mut client: Client, - ) -> E2EResult<()> { + async fn e2e_multi_contract_caller(mut client: Client) -> E2EResult<()> { // given let accumulator_hash = client .upload("accumulator", &ink_e2e::alice()) diff --git a/integration-tests/public/runtime-call-contract/Cargo.toml b/integration-tests/public/runtime-call-contract/Cargo.toml index c7c0a722450..9e2343a6aaa 100644 --- a/integration-tests/public/runtime-call-contract/Cargo.toml +++ b/integration-tests/public/runtime-call-contract/Cargo.toml @@ -1,5 +1,5 @@ [workspace] -members = ["sandbox-runtime", "traits"] +members = ["custom-runtime", "traits"] [workspace.package] authors = ["Use Ink "] @@ -33,8 +33,8 @@ flipper-traits = { path = "traits", default-features = false } [dev-dependencies] ink_e2e = { path = "../../../crates/e2e" } -ink_sandbox = { path = "../../../crates/sandbox" } -sandbox-runtime = { path = "sandbox-runtime", default-features = false } +ink_runtime = { path = "../../../crates/runtime" } +custom-runtime = { path = "custom-runtime", default-features = false } scale-value = "0.18.0" # can't use workspace dependency because of `cargo-contract` build not # working with workspace dependencies @@ -47,7 +47,7 @@ path = "lib.rs" default = ["std"] std = [ "ink/std", - "sandbox-runtime/std", + "custom-runtime/std", "flipper-traits/std", ] ink-as-dependency = [] diff --git a/integration-tests/public/runtime-call-contract/sandbox-runtime/Cargo.toml b/integration-tests/public/runtime-call-contract/custom-runtime/Cargo.toml similarity index 87% rename from integration-tests/public/runtime-call-contract/sandbox-runtime/Cargo.toml rename to integration-tests/public/runtime-call-contract/custom-runtime/Cargo.toml index 88e72d7a059..768020022ca 100644 --- a/integration-tests/public/runtime-call-contract/sandbox-runtime/Cargo.toml +++ b/integration-tests/public/runtime-call-contract/custom-runtime/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "sandbox-runtime" +name = "custom-runtime" version = "0.1.0" authors.workspace = true edition.workspace = true @@ -9,7 +9,7 @@ license.workspace = true repository.workspace = true [dependencies] -ink_sandbox = { path = "../../../../crates/sandbox" } +ink_runtime = { path = "../../../../crates/runtime" } pallet-revive-caller = { path = "pallet-revive-caller", default-features = false } frame-support = { workspace = true } frame-system = { workspace = true } diff --git a/integration-tests/public/runtime-call-contract/sandbox-runtime/pallet-revive-caller/Cargo.toml b/integration-tests/public/runtime-call-contract/custom-runtime/pallet-revive-caller/Cargo.toml similarity index 95% rename from integration-tests/public/runtime-call-contract/sandbox-runtime/pallet-revive-caller/Cargo.toml rename to integration-tests/public/runtime-call-contract/custom-runtime/pallet-revive-caller/Cargo.toml index 3e6f9b25833..70830042d9b 100644 --- a/integration-tests/public/runtime-call-contract/sandbox-runtime/pallet-revive-caller/Cargo.toml +++ b/integration-tests/public/runtime-call-contract/custom-runtime/pallet-revive-caller/Cargo.toml @@ -22,7 +22,7 @@ sp-runtime = { workspace = true, default-features = false } pallet-revive = { workspace = true, default-features = false, features = ["try-runtime"] } flipper-traits = { path = "../../traits", default-features = false } ink = { path = "../../../../../crates/ink", features = ["no-panic-handler", "no-allocator"] } -ink_sandbox = { path = "../../../../../crates/sandbox" } +ink_runtime = { path = "../../../../../crates/runtime" } [features] default = ["std"] diff --git a/integration-tests/public/runtime-call-contract/sandbox-runtime/pallet-revive-caller/src/executor.rs b/integration-tests/public/runtime-call-contract/custom-runtime/pallet-revive-caller/src/executor.rs similarity index 97% rename from integration-tests/public/runtime-call-contract/sandbox-runtime/pallet-revive-caller/src/executor.rs rename to integration-tests/public/runtime-call-contract/custom-runtime/pallet-revive-caller/src/executor.rs index f113f959d87..5474f2df537 100644 --- a/integration-tests/public/runtime-call-contract/sandbox-runtime/pallet-revive-caller/src/executor.rs +++ b/integration-tests/public/runtime-call-contract/custom-runtime/pallet-revive-caller/src/executor.rs @@ -60,7 +60,7 @@ where let result = pallet_revive::Pallet::::bare_call( self.origin.clone(), self.contract, - ink_sandbox::balance_to_evm_value::(self.value), + ink_runtime::balance_to_evm_value::(self.value), self.gas_limit, // self.storage_deposit_limit, BalanceOf::::max_value(), // todo diff --git a/integration-tests/public/runtime-call-contract/sandbox-runtime/pallet-revive-caller/src/lib.rs b/integration-tests/public/runtime-call-contract/custom-runtime/pallet-revive-caller/src/lib.rs similarity index 100% rename from integration-tests/public/runtime-call-contract/sandbox-runtime/pallet-revive-caller/src/lib.rs rename to integration-tests/public/runtime-call-contract/custom-runtime/pallet-revive-caller/src/lib.rs diff --git a/integration-tests/public/runtime-call-contract/sandbox-runtime/src/lib.rs b/integration-tests/public/runtime-call-contract/custom-runtime/src/lib.rs similarity index 53% rename from integration-tests/public/runtime-call-contract/sandbox-runtime/src/lib.rs rename to integration-tests/public/runtime-call-contract/custom-runtime/src/lib.rs index fa8aa18d666..7e5eff32faa 100644 --- a/integration-tests/public/runtime-call-contract/sandbox-runtime/src/lib.rs +++ b/integration-tests/public/runtime-call-contract/custom-runtime/src/lib.rs @@ -4,8 +4,8 @@ #![cfg_attr(not(feature = "std"), no_std)] -ink_sandbox::create_sandbox!(ContractCallerSandbox, ContractCallerSandboxRuntime, (), { +ink_runtime::create_runtime!(ContractCallerRuntime, ContractCallerRuntimeInner, (), { ContractCaller: pallet_revive_caller, }); -impl pallet_revive_caller::Config for ContractCallerSandboxRuntime {} +impl pallet_revive_caller::Config for ContractCallerRuntimeInner {} diff --git a/integration-tests/public/runtime-call-contract/e2e_tests.rs b/integration-tests/public/runtime-call-contract/e2e_tests.rs index bd16521214f..4255363e7b1 100644 --- a/integration-tests/public/runtime-call-contract/e2e_tests.rs +++ b/integration-tests/public/runtime-call-contract/e2e_tests.rs @@ -7,11 +7,8 @@ use ink_e2e::{ type E2EResult = Result>; /// Just instantiate a contract using non-default runtime. -#[ink_sandbox::test(backend(runtime_only( - sandbox = sandbox_runtime::ContractCallerSandbox, - client = ink_sandbox::SandboxClient -)))] -async fn instantiate_and_get(mut client: Client) -> E2EResult<()> { +#[ink_e2e::test(runtime(custom_runtime::ContractCallerRuntime))] +async fn instantiate_and_get(mut client: Client) -> E2EResult<()> { use flipper_traits::Flip; let initial_value = false; diff --git a/integration-tests/public/trait-dyn-cross-contract-calls/lib.rs b/integration-tests/public/trait-dyn-cross-contract-calls/lib.rs index f777728a27a..441828494b0 100644 --- a/integration-tests/public/trait-dyn-cross-contract-calls/lib.rs +++ b/integration-tests/public/trait-dyn-cross-contract-calls/lib.rs @@ -63,9 +63,7 @@ mod e2e_tests { /// The test verifies that we can increment the value of the `Incrementer` contract /// through the `Caller` contract. #[ink_e2e::test] - async fn e2e_cross_contract_calls( - mut client: Client, - ) -> E2EResult<()> { + async fn e2e_cross_contract_calls(mut client: Client) -> E2EResult<()> { let _ = client .upload("trait-incrementer", &ink_e2e::alice()) .submit() diff --git a/integration-tests/public/upgradeable-contracts/delegator/lib.rs b/integration-tests/public/upgradeable-contracts/delegator/lib.rs index 7018a663d89..b5dd7d01184 100644 --- a/integration-tests/public/upgradeable-contracts/delegator/lib.rs +++ b/integration-tests/public/upgradeable-contracts/delegator/lib.rs @@ -132,9 +132,7 @@ pub mod delegator { type E2EResult = std::result::Result>; #[ink_e2e::test] - async fn e2e_counter_mutated( - mut client: Client, - ) -> E2EResult<()> { + async fn e2e_counter_mutated(mut client: Client) -> E2EResult<()> { // given let origin = client .create_and_fund_account(&ink_e2e::alice(), 10_000_000_000_000) @@ -203,9 +201,7 @@ pub mod delegator { } #[ink_e2e::test] - async fn e2e_mapping_mutated( - mut client: Client, - ) -> E2EResult<()> { + async fn e2e_mapping_mutated(mut client: Client) -> E2EResult<()> { let origin = client .create_and_fund_account(&ink_e2e::alice(), 10_000_000_000_000) .await; @@ -276,9 +272,7 @@ pub mod delegator { } #[ink_e2e::test] - async fn update_delegate( - mut client: Client, - ) -> E2EResult<()> { + async fn update_delegate(mut client: Client) -> E2EResult<()> { // given let origin = client .create_and_fund_account(&ink_e2e::alice(), 10_000_000_000_000) diff --git a/integration-tests/public/upgradeable-contracts/set-code-hash-migration/e2e_tests.rs b/integration-tests/public/upgradeable-contracts/set-code-hash-migration/e2e_tests.rs index 89badcf3caa..cb419978fe4 100644 --- a/integration-tests/public/upgradeable-contracts/set-code-hash-migration/e2e_tests.rs +++ b/integration-tests/public/upgradeable-contracts/set-code-hash-migration/e2e_tests.rs @@ -4,7 +4,7 @@ use ink_e2e::ContractsBackend; type E2EResult = std::result::Result>; #[ink_e2e::test] -async fn migration_works(mut client: Client) -> E2EResult<()> { +async fn migration_works(mut client: Client) -> E2EResult<()> { // Given let mut constructor = IncrementerRef::new(); let contract = client diff --git a/integration-tests/public/upgradeable-contracts/set-code-hash/lib.rs b/integration-tests/public/upgradeable-contracts/set-code-hash/lib.rs index 959544a9983..0ae182e99be 100644 --- a/integration-tests/public/upgradeable-contracts/set-code-hash/lib.rs +++ b/integration-tests/public/upgradeable-contracts/set-code-hash/lib.rs @@ -77,7 +77,7 @@ pub mod incrementer { type E2EResult = std::result::Result>; #[ink_e2e::test] - async fn set_code_works(mut client: Client) -> E2EResult<()> { + async fn set_code_works(mut client: Client) -> E2EResult<()> { // Given let mut constructor = IncrementerRef::new(); let contract = client diff --git a/integration-tests/public/wildcard-selector/lib.rs b/integration-tests/public/wildcard-selector/lib.rs index ddc4e1bf5e5..5bcdce5c493 100644 --- a/integration-tests/public/wildcard-selector/lib.rs +++ b/integration-tests/public/wildcard-selector/lib.rs @@ -95,7 +95,7 @@ pub mod wildcard_selector { } #[ink_e2e::test(features = ["emit-event"])] - async fn arbitrary_selectors_handled_by_wildcard( + async fn arbitrary_selectors_handled_by_wildcard( mut client: Client, ) -> E2EResult<()> { // given @@ -167,9 +167,7 @@ pub mod wildcard_selector { } #[ink_e2e::test] - async fn wildcard_complement_works( - mut client: Client, - ) -> E2EResult<()> { + async fn wildcard_complement_works(mut client: Client) -> E2EResult<()> { // given let mut constructor = WildcardSelectorRef::new(); let contract_acc_id = client diff --git a/integration-tests/solidity-abi/events/lib.rs b/integration-tests/solidity-abi/events/lib.rs index 239809fb292..dd821d780bf 100644 --- a/integration-tests/solidity-abi/events/lib.rs +++ b/integration-tests/solidity-abi/events/lib.rs @@ -278,9 +278,7 @@ pub mod events { type E2EResult = std::result::Result>; #[ink_e2e::test] - async fn emits_foreign_event( - mut client: Client, - ) -> E2EResult<()> { + async fn emits_foreign_event(mut client: Client) -> E2EResult<()> { // given let init_value = false; let mut constructor = EventsRef::new(init_value); @@ -321,9 +319,7 @@ pub mod events { } #[ink_e2e::test] - async fn emits_event_with_option_topic_some( - mut client: Client, - ) -> E2EResult<()> { + async fn emits_event_with_option_topic_some(mut client: Client) -> E2EResult<()> { // given let init_value = false; let mut constructor = EventsRef::new(init_value); @@ -371,9 +367,7 @@ pub mod events { } #[ink_e2e::test] - async fn emits_event_with_option_topic_none( - mut client: Client, - ) -> E2EResult<()> { + async fn emits_event_with_option_topic_none(mut client: Client) -> E2EResult<()> { // given let init_value = false; let mut constructor = EventsRef::new(init_value); diff --git a/integration-tests/solidity-abi/sol-cross-contract/Cargo.toml b/integration-tests/solidity-abi/sol-cross-contract/Cargo.toml index ab86ac18689..3f66084e2f6 100755 --- a/integration-tests/solidity-abi/sol-cross-contract/Cargo.toml +++ b/integration-tests/solidity-abi/sol-cross-contract/Cargo.toml @@ -12,7 +12,7 @@ sha3 = { version = "0.10", default-features = false } [dev-dependencies] ink_env = { path = "../../../crates/env" } ink_e2e = { path = "../../../crates/e2e" } -ink_sandbox = { path = "../../../crates/sandbox" } +ink_runtime = { path = "../../../crates/runtime" } ink_revive_types = { path = "../../../crates/revive-types" } sha3 = { version = "0.10" } other-contract-sol = { path = "other-contract-sol" } diff --git a/integration-tests/solidity-abi/sol-cross-contract/e2e_tests.rs b/integration-tests/solidity-abi/sol-cross-contract/e2e_tests.rs index 3a35774bfd8..349757b8d39 100644 --- a/integration-tests/solidity-abi/sol-cross-contract/e2e_tests.rs +++ b/integration-tests/solidity-abi/sol-cross-contract/e2e_tests.rs @@ -1,8 +1,8 @@ use super::sol_cross_contract::*; use ink_e2e::ContractsRegistry; -use ink_sandbox::{ - DefaultSandbox, - Sandbox, +use ink_runtime::{ + DefaultRuntime, + RuntimeEnv, api::prelude::{ BalanceAPI, ContractAPI, @@ -15,7 +15,7 @@ use ink::{ SolEncode, }; use ink_revive_types::ExecReturnValue; -use ink_sandbox::frame_system::pallet_prelude::OriginFor; +use ink_runtime::frame_system::pallet_prelude::OriginFor; const STORAGE_DEPOSIT_LIMIT: u128 = u128::MAX; @@ -24,17 +24,17 @@ fn call_sol_encoded_message() { let built_contracts = ::ink_e2e::build_root_and_contract_dependencies(vec![]); let contracts = ContractsRegistry::new(built_contracts); - let mut sandbox = ink_sandbox::DefaultSandbox::default(); + let mut runtime = ink_runtime::DefaultRuntime::default(); let caller = ink_e2e::alice(); let origin = - DefaultSandbox::convert_account_to_origin(DefaultSandbox::default_actor()); + DefaultRuntime::convert_account_to_origin(DefaultRuntime::default_actor()); - sandbox + runtime .mint_into(&caller.public_key().0.into(), 1_000_000_000_000_000u128) .unwrap_or_else(|_| panic!("Failed to mint tokens")); - sandbox - .map_account(&DefaultSandbox::default_actor()) + runtime + .map_account(&DefaultRuntime::default_actor()) .expect("unable to map"); // upload other contract (callee) @@ -47,19 +47,19 @@ fn call_sol_encoded_message() { let exec_input = params.exec_input(); let code = contracts.load_code("other-contract-sol"); - let other_contract_addr = ::deploy_contract( - &mut sandbox, + let other_contract_addr = ::deploy_contract( + &mut runtime, code, 0, exec_input.encode(), // salt None, origin.clone(), - ::default_gas_limit(), + ::default_gas_limit(), STORAGE_DEPOSIT_LIMIT, ) .result - .expect("sandbox deploy contract failed") + .expect("runtime deploy contract failed") .addr; // upload main contract (caller) @@ -72,8 +72,8 @@ fn call_sol_encoded_message() { let exec_input = params.exec_input(); let code = contracts.load_code("sol-cross-contract"); - let contract_addr = ::deploy_contract( - &mut sandbox, + let contract_addr = ::deploy_contract( + &mut runtime, code, 0, exec_input.encode(), @@ -81,14 +81,14 @@ fn call_sol_encoded_message() { // TODO (@peterwht): figure out why no salt is causing `DuplicateContract` Some([1u8; 32]), origin.clone(), - ::default_gas_limit(), + ::default_gas_limit(), STORAGE_DEPOSIT_LIMIT, ) .result - .expect("sandbox deploy contract failed") + .expect("runtime deploy contract failed") .addr; - let mut contracts = ContractSandbox { sandbox }; + let mut contracts = ContractRuntime { runtime }; // get value let value: bool = contracts.call_with_return_value( @@ -121,17 +121,17 @@ fn call_sol_encoded_message() { assert!(value, "value should have been set to true"); } -struct ContractSandbox { - sandbox: ink_sandbox::DefaultSandbox, +struct ContractRuntime { + runtime: ink_runtime::DefaultRuntime, } -impl ContractSandbox { +impl ContractRuntime { fn call_with_return_value( &mut self, contract_addr: Address, message: &str, args: Args, - origin: OriginFor<::Runtime>, + origin: OriginFor<::Runtime>, ) -> Ret where Args: for<'a> SolEncode<'a>, @@ -146,7 +146,7 @@ impl ContractSandbox { contract_addr: Address, message: &str, args: Args, - origin: OriginFor<::Runtime>, + origin: OriginFor<::Runtime>, ) -> Vec where Args: for<'a> SolEncode<'a>, @@ -164,19 +164,19 @@ impl ContractSandbox { &mut self, contract_addr: Address, data: Vec, - origin: OriginFor<::Runtime>, + origin: OriginFor<::Runtime>, ) -> ExecReturnValue { - let result = ::call_contract( - &mut self.sandbox, + let result = ::call_contract( + &mut self.runtime, contract_addr, 0, data, origin, - ::default_gas_limit(), + ::default_gas_limit(), STORAGE_DEPOSIT_LIMIT, ); - let call_raw = result.result.expect("sandbox call contract failed"); + let call_raw = result.result.expect("runtime call contract failed"); ExecReturnValue { flags: ink_env::ReturnFlags::from_bits_truncate(call_raw.flags.bits()), data: call_raw.data, diff --git a/integration-tests/solidity-abi/sol-encoding/Cargo.toml b/integration-tests/solidity-abi/sol-encoding/Cargo.toml index 4a37400ea30..2191b1b6b3c 100755 --- a/integration-tests/solidity-abi/sol-encoding/Cargo.toml +++ b/integration-tests/solidity-abi/sol-encoding/Cargo.toml @@ -11,7 +11,7 @@ ink = { path = "../../../crates/ink", default-features = false } [dev-dependencies] ink_env = { path = "../../../crates/env" } ink_e2e = { path = "../../../crates/e2e" } -ink_sandbox = { path = "../../../crates/sandbox" } +ink_runtime = { path = "../../../crates/runtime" } ink_revive_types = { path = "../../../crates/revive-types" } sha3 = { version = "0.10" } diff --git a/integration-tests/solidity-abi/sol-encoding/e2e_tests.rs b/integration-tests/solidity-abi/sol-encoding/e2e_tests.rs index e189a1b3cd1..0fe1c574447 100644 --- a/integration-tests/solidity-abi/sol-encoding/e2e_tests.rs +++ b/integration-tests/solidity-abi/sol-encoding/e2e_tests.rs @@ -6,9 +6,9 @@ use ink::{ }; use ink_e2e::ContractsRegistry; use ink_revive_types::ExecReturnValue; -use ink_sandbox::{ - DefaultSandbox, - Sandbox, +use ink_runtime::{ + DefaultRuntime, + RuntimeEnv, api::prelude::{ BalanceAPI, ContractAPI, @@ -23,17 +23,17 @@ fn call_solidity_encoded_message() { let built_contracts = ::ink_e2e::build_root_and_contract_dependencies(vec![]); let contracts = ContractsRegistry::new(built_contracts); - let mut sandbox = DefaultSandbox::default(); + let mut runtime = DefaultRuntime::default(); let caller = ink_e2e::alice(); let origin = - DefaultSandbox::convert_account_to_origin(DefaultSandbox::default_actor()); + DefaultRuntime::convert_account_to_origin(DefaultRuntime::default_actor()); - sandbox + runtime .mint_into(&caller.public_key().0.into(), 1_000_000_000_000_000u128) .unwrap_or_else(|_| panic!("Failed to mint tokens")); - sandbox - .map_account(&DefaultSandbox::default_actor()) + runtime + .map_account(&DefaultRuntime::default_actor()) .expect("unable to map"); let constructor = SolEncodingRef::new(false); @@ -45,23 +45,23 @@ fn call_solidity_encoded_message() { let exec_input = params.exec_input(); let code = contracts.load_code("sol_encoding"); - let contract_addr = ::deploy_contract( - &mut sandbox, + let contract_addr = ::deploy_contract( + &mut runtime, code, 0, exec_input.encode(), // salt None, origin.clone(), - ::default_gas_limit(), + ::default_gas_limit(), STORAGE_DEPOSIT_LIMIT, ) .result - .expect("sandbox deploy contract failed") + .expect("runtime deploy contract failed") .addr; - let mut contract = ContractSandbox { - sandbox, + let mut contract = ContractRuntime { + runtime, contract_addr, }; @@ -75,17 +75,17 @@ fn call_solidity_encoded_message() { assert!(value, "value should have been set to true"); } -struct ContractSandbox { - sandbox: DefaultSandbox, +struct ContractRuntime { + runtime: DefaultRuntime, contract_addr: Address, } -impl ContractSandbox { +impl ContractRuntime { fn call_with_return_value( &mut self, message: &str, args: Args, - origin: OriginFor<::Runtime>, + origin: OriginFor<::Runtime>, ) -> Ret where Args: for<'a> SolEncode<'a>, @@ -99,7 +99,7 @@ impl ContractSandbox { &mut self, message: &str, args: Args, - origin: OriginFor<::Runtime>, + origin: OriginFor<::Runtime>, ) -> Vec where Args: for<'a> SolEncode<'a>, @@ -116,19 +116,19 @@ impl ContractSandbox { fn call_raw( &mut self, data: Vec, - origin: OriginFor<::Runtime>, + origin: OriginFor<::Runtime>, ) -> ExecReturnValue { - let call_raw = ::call_contract( - &mut self.sandbox, + let call_raw = ::call_contract( + &mut self.runtime, self.contract_addr, 0, data, origin, - ::default_gas_limit(), + ::default_gas_limit(), STORAGE_DEPOSIT_LIMIT, ) .result - .expect("sandbox call contract failed"); + .expect("runtime call contract failed"); ExecReturnValue { flags: ink_env::ReturnFlags::from_bits_truncate(call_raw.flags.bits()), data: call_raw.data, diff --git a/integration-tests/solidity-abi/solidity-calls-flipper/e2e_tests.rs b/integration-tests/solidity-abi/solidity-calls-flipper/e2e_tests.rs index 41fd75e351c..ba6d9072928 100644 --- a/integration-tests/solidity-abi/solidity-calls-flipper/e2e_tests.rs +++ b/integration-tests/solidity-abi/solidity-calls-flipper/e2e_tests.rs @@ -32,9 +32,7 @@ type E2EResult = Result>; // scripts. #[ignore] #[ink_e2e::test] -async fn solidity_calls_ink_works( - mut client: Client, -) -> E2EResult<()> { +async fn solidity_calls_ink_works(mut client: Client) -> E2EResult<()> { let constructor = FlipperRef::new(false); let params = constructor .endowment(0u32.into()) diff --git a/integration-tests/solidity-abi/trait-dyn-cross-contract-calls/lib.rs b/integration-tests/solidity-abi/trait-dyn-cross-contract-calls/lib.rs index f777728a27a..441828494b0 100644 --- a/integration-tests/solidity-abi/trait-dyn-cross-contract-calls/lib.rs +++ b/integration-tests/solidity-abi/trait-dyn-cross-contract-calls/lib.rs @@ -63,9 +63,7 @@ mod e2e_tests { /// The test verifies that we can increment the value of the `Incrementer` contract /// through the `Caller` contract. #[ink_e2e::test] - async fn e2e_cross_contract_calls( - mut client: Client, - ) -> E2EResult<()> { + async fn e2e_cross_contract_calls(mut client: Client) -> E2EResult<()> { let _ = client .upload("trait-incrementer", &ink_e2e::alice()) .submit()