diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md index 09b0478429..efc9b0d5c8 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 +As contracts are executed in an isolated runtime environment on the blockchain itself 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-only 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-only 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/Cargo.toml b/Cargo.toml index 2c6d8db133..45eb927c5d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 b1e5d22bd4..4afd715585 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 crates/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 `crates/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 emulator 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/src/config.rs b/crates/e2e/macro/src/config.rs index 97dbea96f9..91ee38b5dd 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,8 +76,8 @@ 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_runtime::DefaultRuntime`) - 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_runtime::RuntimeClient`) pub client: syn::Path, @@ -74,7 +85,7 @@ pub struct RuntimeOnly { 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_runtime::DefaultRuntime, client = ::ink_runtime::RuntimeClient)), + 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,25 +266,24 @@ mod tests { assert_eq!( config.backend(), Backend::RuntimeOnly(RuntimeOnly { - sandbox: syn::parse_quote! { ::ink_runtime::DefaultRuntime }, + 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_runtime::DefaultRuntime }, + runtime: syn::parse_quote! { ::ink_runtime::DefaultRuntime }, client: syn::parse_quote! { ::ink_runtime::RuntimeClient }, }) ); @@ -184,15 +292,42 @@ mod tests { #[test] fn config_works_runtime_only_with_custom_backend() { let input = quote! { - backend(runtime_only(sandbox = ::ink_runtime::DefaultRuntime, client = ::ink_runtime::RuntimeClient)), + 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_runtime::DefaultRuntime }, + 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 7cbc623e08..0b92ec9a2c 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 2d26d7ac2d..7f65bc2a64 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_runtime::test(backend(runtime_only(sandbox = ink_runtime::DefaultRuntime, client = ink_runtime::RuntimeClient)))] -/// 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/runtime/src/api/assets_api.rs b/crates/runtime/src/api/assets_api.rs index cf63810dba..3bb103e96e 100644 --- a/crates/runtime/src/api/assets_api.rs +++ b/crates/runtime/src/api/assets_api.rs @@ -23,7 +23,7 @@ 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 @@ -327,52 +327,52 @@ mod tests { #[test] fn create_works() { - let mut sandbox = DefaultRuntime::default(); + 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 = DefaultRuntime::default(); + 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 = DefaultRuntime::default(); + 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 = DefaultRuntime::default(); + 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 = DefaultRuntime::default(); + 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 = DefaultRuntime::default(); + 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 = DefaultRuntime::default(); + 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 = DefaultRuntime::default(); + 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 = DefaultRuntime::default(); + 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 = DefaultRuntime::default(); + 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/runtime/src/api/balance_api.rs b/crates/runtime/src/api/balance_api.rs index a49a415468..d74872c590 100644 --- a/crates/runtime/src/api/balance_api.rs +++ b/crates/runtime/src/api/balance_api.rs @@ -11,7 +11,7 @@ use pallet_revive::sp_runtime::traits::StaticLookup; type BalanceOf = ::Balance; -/// Balance API for the sandbox. +/// Balance API for the runtime. pub trait BalanceAPI where T: RuntimeEnv, @@ -99,15 +99,15 @@ mod test { use crate::DefaultRuntime; #[test] fn mint_works() { - let mut sandbox = DefaultRuntime::default(); - let balance = sandbox.free_balance(&DefaultRuntime::default_actor()); + let mut runtime = DefaultRuntime::default(); + let balance = runtime.free_balance(&DefaultRuntime::default_actor()); - sandbox + runtime .mint_into(&DefaultRuntime::default_actor(), 100) .unwrap(); assert_eq!( - sandbox.free_balance(&DefaultRuntime::default_actor()), + runtime.free_balance(&DefaultRuntime::default_actor()), balance + 100 ); } diff --git a/crates/runtime/src/api/revive_api.rs b/crates/runtime/src/api/revive_api.rs index ce72ce613b..73af49d6b2 100644 --- a/crates/runtime/src/api/revive_api.rs +++ b/crates/runtime/src/api/revive_api.rs @@ -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 + 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(|_| { + 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 = DefaultRuntime::default(); + let mut runtime = DefaultRuntime::default(); let contract_binary = compile_module("dummy"); - warm_up::(&mut sandbox); + warm_up::(&mut runtime); use sha3::{ Digest, @@ -363,7 +363,7 @@ mod tests { let origin = DefaultRuntime::convert_account_to_origin(DefaultRuntime::default_actor()); - let result = sandbox.upload_contract(contract_binary, origin, 100000000000000); + let result = runtime.upload_contract(contract_binary, origin, 100000000000000); assert!(result.is_ok()); assert_eq!(hash, result.unwrap().code_hash); @@ -371,18 +371,18 @@ mod tests { #[test] fn can_deploy_contract() { - let mut sandbox = DefaultRuntime::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 = DefaultRuntime::default_actor(); - sandbox.map_account(&default_actor).expect("cannot map"); + runtime.map_account(&default_actor).expect("cannot map"); let origin = DefaultRuntime::convert_account_to_origin(default_actor); - let result = sandbox.deploy_contract( + let result = runtime.deploy_contract( contract_binary.clone(), 0, vec![], @@ -395,7 +395,7 @@ mod tests { 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![], @@ -411,15 +411,15 @@ mod tests { #[test] fn can_call_contract() { - let mut sandbox = DefaultRuntime::default(); + 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 = DefaultRuntime::default_actor(); - sandbox.map_account(&default_actor).expect("unable to map"); + runtime.map_account(&default_actor).expect("unable to map"); let origin = DefaultRuntime::convert_account_to_origin(default_actor); - let result = sandbox.deploy_contract( + let result = runtime.deploy_contract( contract_binary, 0, vec![], @@ -432,9 +432,9 @@ mod tests { 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![], @@ -445,7 +445,7 @@ mod tests { 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, diff --git a/crates/runtime/src/api/system_api.rs b/crates/runtime/src/api/system_api.rs index 407c07d2a3..23ce373c7e 100644 --- a/crates/runtime/src/api/system_api.rs +++ b/crates/runtime/src/api/system_api.rs @@ -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; @@ -114,7 +114,7 @@ mod tests { }; fn make_transfer( - sandbox: &mut DefaultRuntime, + runtime: &mut DefaultRuntime, dest: AccountId32, value: u128, ) -> DispatchResultWithInfo< @@ -125,7 +125,7 @@ mod tests { dest, "make_transfer should send to account different than default_actor" ); - sandbox.runtime_call( + runtime.runtime_call( RuntimeCall::>::Balances(pallet_balances::Call::< RuntimeOf, >::transfer_allow_death { @@ -138,43 +138,43 @@ mod tests { #[test] fn dry_run_works() { - let mut sandbox = DefaultRuntime::default(); + let mut runtime = DefaultRuntime::default(); let actor = DefaultRuntime::default_actor(); - let initial_balance = sandbox.free_balance(&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 = DefaultRuntime::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 = DefaultRuntime::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, @@ -184,39 +184,39 @@ mod tests { #[test] fn resetting_events() { - let mut sandbox = DefaultRuntime::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 = DefaultRuntime::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/runtime/src/api/timestamp_api.rs b/crates/runtime/src/api/timestamp_api.rs index 8de279b575..ebbc8bb3f4 100644 --- a/crates/runtime/src/api/timestamp_api.rs +++ b/crates/runtime/src/api/timestamp_api.rs @@ -46,13 +46,13 @@ mod tests { #[test] fn getting_and_setting_timestamp_works() { - let mut sandbox = DefaultRuntime::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/runtime/src/client.rs b/crates/runtime/src/client.rs index 5133fef0d9..c63d0a7f23 100644 --- a/crates/runtime/src/client.rs +++ b/crates/runtime/src/client.rs @@ -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,30 +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: RuntimeEnv> 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 Balance = BalanceOf; type Error = RuntimeErr; - type EventLog = Vec>; + type EventLog = Vec>; async fn create_and_fund_account( &mut self, @@ -190,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"); @@ -201,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>( @@ -219,7 +219,7 @@ where // 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"); @@ -233,20 +233,20 @@ where // 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| { 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) } @@ -259,12 +259,12 @@ 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| { RuntimeErr::new(format!("transfer_allow_death failed: {err:?}")) @@ -275,19 +275,19 @@ where #[async_trait] impl< AccountId: Clone + Send + Sync + From<[u8; 32]> + AsRef<[u8; 32]>, - S: RuntimeEnv, - 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 { @@ -311,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, @@ -337,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(), @@ -379,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 { @@ -404,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> { @@ -440,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()), ) }); @@ -494,10 +494,10 @@ 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, @@ -507,7 +507,7 @@ where } }; - let all = self.sandbox.events(); + let all = self.runtime.events(); let events = all[start..].to_vec(); Ok(UploadResult { code_hash: result.code_hash, @@ -524,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 @@ -548,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, @@ -574,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(), @@ -600,7 +600,7 @@ where _ => None, }; - let all = self.sandbox.events(); + let all = self.runtime.events(); let events = all[start..].to_vec(); Ok((events, trace)) } @@ -646,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()), ) }); @@ -700,11 +700,11 @@ 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| { RuntimeErr::new(format!("map_account: execution error {err:?}")) }) @@ -714,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()), @@ -753,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() } @@ -764,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: RuntimeEnv, - 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; @@ -820,19 +820,19 @@ where #[async_trait] impl< AccountId: Clone + Send + Sync + From<[u8; 32]> + AsRef<[u8; 32]>, - S: RuntimeEnv, - 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 = RuntimeErr; - type EventLog = Vec>; + 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 @@ -843,17 +843,17 @@ pub mod preset { BlockBuilder, Extension, RuntimeMetadataPrefixed, - Sandbox, + RuntimeEnv, Snapshot, }; pub use pallet_revive_mock_network::*; use sp_runtime::traits::Dispatchable; - /// A [`ink_runtime::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 = MockNetworkRuntime, client = ink_runtime::RuntimeClient)))] + /// #[ink_e2e::test(runtime(MockNetworkRuntime))] /// async fn my_test(mut client: Client) -> E2EResult<()> { /// // ... /// } @@ -863,7 +863,7 @@ pub mod preset { dry_run: bool, } - impl Sandbox for MockNetworkRuntime { + impl RuntimeEnv for MockNetworkRuntime { type Runtime = parachain::Runtime; fn execute_with(&mut self, execute: impl FnOnce() -> T) -> T { @@ -956,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: RuntimeEnv, - 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/runtime/src/macros.rs b/crates/runtime/src/macros.rs index 37f5e8da3d..df0714a260 100644 --- a/crates/runtime/src/macros.rs +++ b/crates/runtime/src/macros.rs @@ -500,15 +500,3 @@ pub use construct_runtime::{ } create_runtime!(DefaultRuntime); - -/// Backward compatibility alias for `create_runtime!`. -/// -/// This macro is deprecated and will be removed in a future version. -/// Please use `create_runtime!` instead. -#[macro_export] -#[deprecated(since = "6.0.0", note = "Use `create_runtime!` instead")] -macro_rules! create_sandbox { - ($($tt:tt)*) => { - $crate::create_runtime!($($tt)*) - }; -} diff --git a/integration-tests/internal/e2e-runtime-only-backend/lib.rs b/integration-tests/internal/e2e-runtime-only-backend/lib.rs index ace4d09051..5e89f22eb6 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_runtime::test(backend(runtime_only( - sandbox = ink_runtime::DefaultRuntime, - client = ink_runtime::RuntimeClient - )))] - 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_runtime::test(backend(runtime_only( - sandbox = ink_runtime::DefaultRuntime, - client = ink_runtime::RuntimeClient - )))] + #[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_runtime::test(backend(runtime_only( - sandbox = ink_runtime::DefaultRuntime, - client = ink_runtime::RuntimeClient - )))] - 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/public/assets-precompile/lib.rs b/integration-tests/public/assets-precompile/lib.rs index d752b32fcf..86d455b382 100644 --- a/integration-tests/public/assets-precompile/lib.rs +++ b/integration-tests/public/assets-precompile/lib.rs @@ -190,9 +190,7 @@ mod e2e_tests { bob, }; use ink_runtime::{ - DefaultRuntime, E2EError, - RuntimeClient, api::prelude::{ AssetsAPI, ContractAPI, @@ -204,11 +202,8 @@ mod e2e_tests { type E2EResult = std::result::Result; - #[ink_runtime::test(backend(runtime_only( - sandbox = DefaultRuntime, - client = RuntimeClient - )))] - 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_runtime::test(backend(runtime_only( - sandbox = DefaultRuntime, - client = RuntimeClient - )))] - 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_runtime::test(backend(runtime_only( - sandbox = DefaultRuntime, - client = RuntimeClient - )))] - 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_runtime::test(backend(runtime_only( - sandbox = DefaultRuntime, - client = RuntimeClient - )))] - 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_runtime::test(backend(runtime_only( - sandbox = DefaultRuntime, - client = RuntimeClient - )))] - 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_runtime::test(backend(runtime_only( - sandbox = DefaultRuntime, - client = RuntimeClient - )))] - 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_runtime::test(backend(runtime_only( - sandbox = DefaultRuntime, - client = RuntimeClient - )))] - 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/contract-transfer/lib.rs b/integration-tests/public/contract-transfer/lib.rs index f1ec51d1cd..abce84a31b 100644 --- a/integration-tests/public/contract-transfer/lib.rs +++ b/integration-tests/public/contract-transfer/lib.rs @@ -225,11 +225,8 @@ pub mod give_me { Ok(()) } - #[ink_runtime::test(backend(runtime_only( - sandbox = ink_runtime::DefaultRuntime, - client = ink_runtime::RuntimeClient - )))] - 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/debugging-strategies/lib.rs b/integration-tests/public/debugging-strategies/lib.rs index 6fc1ebd833..9a6a8af81f 100755 --- a/integration-tests/public/debugging-strategies/lib.rs +++ b/integration-tests/public/debugging-strategies/lib.rs @@ -312,6 +312,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/fuzz-testing/lib.rs b/integration-tests/public/fuzz-testing/lib.rs index 655696d2c9..ab57f64b41 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_runtime::test(replace_test_attr = "#[quickcheck]", backend(runtime_only( - sandbox = ink_runtime::DefaultRuntime, - client = ink_runtime::RuntimeClient - )))] + #[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_runtime::test(replace_test_attr = "#[quickcheck]", backend(runtime_only( - sandbox = ink_runtime::DefaultRuntime, - client = ink_runtime::RuntimeClient - )))] + #[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_runtime::test(replace_test_attr = "#[quickcheck]", backend(runtime_only( - sandbox = ink_runtime::DefaultRuntime, - client = ink_runtime::RuntimeClient - )))] + #[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/runtime-call-contract/custom-runtime/src/lib.rs b/integration-tests/public/runtime-call-contract/custom-runtime/src/lib.rs index f730cd5928..7e5eff32fa 100644 --- a/integration-tests/public/runtime-call-contract/custom-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_runtime::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 c14e0a1181..4255363e7b 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_runtime::test(backend(runtime_only( - sandbox = sandbox_runtime::ContractCallerSandbox, - client = ink_runtime::RuntimeClient -)))] -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/solidity-abi/sol-cross-contract/e2e_tests.rs b/integration-tests/solidity-abi/sol-cross-contract/e2e_tests.rs index 89506eddc9..349757b8d3 100644 --- a/integration-tests/solidity-abi/sol-cross-contract/e2e_tests.rs +++ b/integration-tests/solidity-abi/sol-cross-contract/e2e_tests.rs @@ -2,7 +2,7 @@ use super::sol_cross_contract::*; use ink_e2e::ContractsRegistry; use ink_runtime::{ DefaultRuntime, - Sandbox, + RuntimeEnv, api::prelude::{ BalanceAPI, ContractAPI, @@ -24,16 +24,16 @@ 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_runtime::DefaultRuntime::default(); + let mut runtime = ink_runtime::DefaultRuntime::default(); let caller = ink_e2e::alice(); let origin = 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 + runtime .map_account(&DefaultRuntime::default_actor()) .expect("unable to map"); @@ -48,18 +48,18 @@ fn call_sol_encoded_message() { let code = contracts.load_code("other-contract-sol"); let other_contract_addr = ::deploy_contract( - &mut sandbox, + &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) @@ -73,7 +73,7 @@ fn call_sol_encoded_message() { let code = contracts.load_code("sol-cross-contract"); let contract_addr = ::deploy_contract( - &mut sandbox, + &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_runtime::DefaultRuntime, +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, + &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/e2e_tests.rs b/integration-tests/solidity-abi/sol-encoding/e2e_tests.rs index c00423548a..0fe1c57444 100644 --- a/integration-tests/solidity-abi/sol-encoding/e2e_tests.rs +++ b/integration-tests/solidity-abi/sol-encoding/e2e_tests.rs @@ -8,7 +8,7 @@ use ink_e2e::ContractsRegistry; use ink_revive_types::ExecReturnValue; use ink_runtime::{ DefaultRuntime, - Sandbox, + RuntimeEnv, api::prelude::{ BalanceAPI, ContractAPI, @@ -23,16 +23,16 @@ 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 = DefaultRuntime::default(); + let mut runtime = DefaultRuntime::default(); let caller = ink_e2e::alice(); let origin = 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 + runtime .map_account(&DefaultRuntime::default_actor()) .expect("unable to map"); @@ -46,22 +46,22 @@ fn call_solidity_encoded_message() { let code = contracts.load_code("sol_encoding"); let contract_addr = ::deploy_contract( - &mut sandbox, + &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: DefaultRuntime, +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, + &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,