From 40dca235625642b92684e7fdef42a31bcd58fb07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Wed, 30 Aug 2023 13:13:15 +0200 Subject: [PATCH 01/16] Configuration --- crates/e2e/macro/src/config.rs | 96 +++++++++++++++++++++++++++++++++- 1 file changed, 94 insertions(+), 2 deletions(-) diff --git a/crates/e2e/macro/src/config.rs b/crates/e2e/macro/src/config.rs index 917fc50e90..123cec21de 100644 --- a/crates/e2e/macro/src/config.rs +++ b/crates/e2e/macro/src/config.rs @@ -73,6 +73,9 @@ pub struct E2EConfig { environment: Option, /// The type of the architecture that should be used to run test. backend: Backend, + /// The runtime to use for the runtime-only test. + #[cfg(any(test, feature = "drink"))] + runtime: Option, } impl TryFrom for E2EConfig { @@ -82,6 +85,8 @@ impl TryFrom for E2EConfig { let mut additional_contracts: Option<(syn::LitStr, ast::MetaNameValue)> = None; let mut environment: Option<(syn::Path, ast::MetaNameValue)> = None; let mut backend: Option<(syn::LitStr, ast::MetaNameValue)> = None; + #[cfg(any(test, feature = "drink"))] + let mut runtime: Option<(syn::Path, ast::MetaNameValue)> = None; for arg in args.into_iter() { if arg.name.is_ident("additional_contracts") { @@ -125,6 +130,28 @@ impl TryFrom for E2EConfig { "expected a string literal for `backend` ink! E2E test configuration argument", )); } + } else if arg.name.is_ident("runtime") { + #[cfg(any(test, feature = "drink"))] + { + if let Some((_, ast)) = runtime { + return Err(duplicate_config_err(ast, arg, "runtime", "E2E test")) + } + if let ast::MetaValue::Path(path) = &arg.value { + runtime = Some((path.clone(), arg)) + } else { + return Err(format_err_spanned!( + arg, + "expected a path for `runtime` ink! E2E test configuration argument", + )); + } + } + #[cfg(not(any(test, feature = "drink")))] + { + return Err(format_err_spanned!( + arg, + "the `runtime` ink! E2E test configuration argument is not available because the `drink` feature is not enabled", + )); + } } else { return Err(format_err_spanned!( arg, @@ -141,10 +168,22 @@ impl TryFrom for E2EConfig { .transpose()? .unwrap_or_default(); + #[cfg(any(test, feature = "drink"))] + { + if backend == Backend::Full && runtime.is_some() { + return Err(format_err_spanned!( + runtime.unwrap().1, + "ink! E2E test `runtime` configuration argument is available for `runtime-only` backend only", + )); + } + } + Ok(E2EConfig { additional_contracts, environment, backend, + #[cfg(any(test, feature = "drink"))] + runtime: runtime.map(|(path, _)| path), }) } } @@ -165,6 +204,12 @@ impl E2EConfig { pub fn backend(&self) -> Backend { self.backend } + + /// The runtime to use for the runtime-only test. + #[cfg(any(test, feature = "drink"))] + pub fn runtime(&self) -> Option { + self.runtime.clone() + } } #[cfg(test)] @@ -276,13 +321,59 @@ mod tests { ); } + #[test] + fn runtime_must_be_path() { + assert_try_from( + syn::parse_quote! { runtime = "MinimalRuntime" }, + Err("expected a path for `runtime` ink! E2E test configuration argument"), + ); + } + + #[test] + fn duplicate_runtime_fails() { + assert_try_from( + syn::parse_quote! { + runtime = ::drink::MinimalRuntime, + runtime = ::drink::MaximalRuntime, + }, + Err("encountered duplicate ink! E2E test `runtime` configuration argument"), + ); + } + + #[test] + fn runtime_is_for_runtime_only_backend_only() { + assert_try_from( + syn::parse_quote! { + backend = "full", + runtime = ::drink::MinimalRuntime + }, + Err("ink! E2E test `runtime` configuration argument is available for `runtime-only` backend only"), + ); + } + + #[test] + fn specifying_runtime_works() { + assert_try_from( + syn::parse_quote! { + backend = "runtime-only", + runtime = ::drink::MinimalRuntime + }, + Ok(E2EConfig { + backend: Backend::RuntimeOnly, + runtime: Some(syn::parse_quote! { ::drink::MinimalRuntime }), + ..Default::default() + }), + ); + } + #[test] fn full_config_works() { assert_try_from( syn::parse_quote! { additional_contracts = "adder/Cargo.toml flipper/Cargo.toml", environment = crate::CustomEnvironment, - backend = "full", + backend = "runtime-only", + runtime = ::drink::MinimalRuntime, }, Ok(E2EConfig { additional_contracts: vec![ @@ -290,7 +381,8 @@ mod tests { "flipper/Cargo.toml".into(), ], environment: Some(syn::parse_quote! { crate::CustomEnvironment }), - backend: Backend::Full, + backend: Backend::RuntimeOnly, + runtime: Some(syn::parse_quote! { ::drink::MinimalRuntime }), }), ); } From df0150b1bbd039f695ab422007d4d4cefc8d30e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Wed, 30 Aug 2023 13:23:27 +0200 Subject: [PATCH 02/16] Change client implementation --- crates/e2e/src/drink_client.rs | 38 ++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/crates/e2e/src/drink_client.rs b/crates/e2e/src/drink_client.rs index 6f8884e64e..d9e5e88684 100644 --- a/crates/e2e/src/drink_client.rs +++ b/crates/e2e/src/drink_client.rs @@ -20,10 +20,7 @@ use crate::{ use drink::{ chain_api::ChainApi, contract_api::ContractApi, - runtime::{ - MinimalRuntime, - Runtime, - }, + runtime::Runtime as RuntimeT, Sandbox, DEFAULT_GAS_LIMIT, }; @@ -51,15 +48,18 @@ use std::{ use subxt::dynamic::Value; use subxt_signer::sr25519::Keypair; -pub struct Client { - sandbox: Sandbox, +pub struct Client { + sandbox: Sandbox, contracts: ContractsRegistry, _phantom: PhantomData<(AccountId, Hash)>, } -unsafe impl Send for 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 { +impl Client { pub fn new>(contracts: impl IntoIterator) -> Self { let mut sandbox = Sandbox::new().expect("Failed to initialize Drink! sandbox"); Self::fund_accounts(&mut sandbox); @@ -71,7 +71,7 @@ impl Client { } } - fn fund_accounts(sandbox: &mut Sandbox) { + fn fund_accounts(sandbox: &mut Sandbox) { const TOKENS: u128 = 1_000_000_000_000_000; let accounts = [ @@ -93,7 +93,9 @@ impl Client { } #[async_trait] -impl + Send, Hash> ChainBackend for Client { +impl + Send, Hash, Runtime: RuntimeT> ChainBackend + for Client +{ type AccountId = AccountId; type Balance = u128; type Error = (); @@ -133,9 +135,10 @@ impl + Send, Hash> ChainBackend for Client + AsRef<[u8; 32]>, - Hash: From<[u8; 32]>, + Hash: Copy + From<[u8; 32]>, + Runtime: RuntimeT, E: Environment + 'static, - > ContractsBackend for Client + > ContractsBackend for Client { type Error = (); type EventLog = (); @@ -221,10 +224,12 @@ impl< } }; + let code_hash_raw: [u8; 32] = result.code_hash.as_ref().try_into().expect(""); + let code_hash = Hash::from(code_hash_raw); Ok(UploadResult { - code_hash: result.code_hash.0.into(), + code_hash, dry_run: Ok(CodeUploadReturnValue { - code_hash: result.code_hash.0.into(), + code_hash, deposit: result.deposit, }), events: (), @@ -287,9 +292,10 @@ impl< impl< AccountId: Clone + Send + Sync + From<[u8; 32]> + AsRef<[u8; 32]>, - Hash: From<[u8; 32]>, + Hash: Copy + From<[u8; 32]>, + Runtime: RuntimeT, E: Environment + 'static, - > E2EBackend for Client + > E2EBackend for Client { } From 8c48c68ab7d1d54f2c541a256a6b15fb349a4147 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Wed, 30 Aug 2023 13:38:04 +0200 Subject: [PATCH 03/16] Update codegen --- crates/e2e/macro/src/codegen.rs | 8 +++++--- crates/e2e/src/drink_client.rs | 5 ++++- crates/e2e/src/lib.rs | 7 +++++-- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/crates/e2e/macro/src/codegen.rs b/crates/e2e/macro/src/codegen.rs index 5ab34fb8eb..e9b7064b49 100644 --- a/crates/e2e/macro/src/codegen.rs +++ b/crates/e2e/macro/src/codegen.rs @@ -19,6 +19,7 @@ use crate::{ use derive_more::From; use proc_macro2::TokenStream as TokenStream2; use quote::quote; +use syn::Path; const DEFAULT_CONTRACTS_NODE: &str = "substrate-contracts-node"; @@ -69,7 +70,7 @@ impl InkE2ETest { let client_building = match self.test.config.backend() { Backend::Full => build_full_client(&environment, exec_build_contracts), #[cfg(any(test, feature = "drink"))] - Backend::RuntimeOnly => build_runtime_client(exec_build_contracts), + Backend::RuntimeOnly => build_runtime_client(exec_build_contracts, self.test.config.runtime()), }; quote! { @@ -146,9 +147,10 @@ fn build_full_client(environment: &syn::Path, contracts: TokenStream2) -> TokenS } #[cfg(any(test, feature = "drink"))] -fn build_runtime_client(contracts: TokenStream2) -> TokenStream2 { +fn build_runtime_client(contracts: TokenStream2, runtime: Option) -> TokenStream2 { + let runtime = runtime.unwrap_or_else(|| syn::parse_quote! { ::ink_e2e::MinimalRuntime }); quote! { let contracts = #contracts; - let mut client = ::ink_e2e::DrinkClient::new(contracts); + let mut client = ::ink_e2e::DrinkClient::<_, _, #runtime>::new(contracts); } } diff --git a/crates/e2e/src/drink_client.rs b/crates/e2e/src/drink_client.rs index d9e5e88684..ea9cf4ca95 100644 --- a/crates/e2e/src/drink_client.rs +++ b/crates/e2e/src/drink_client.rs @@ -57,7 +57,10 @@ 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 {} +unsafe impl Send + for Client +{ +} impl Client { pub fn new>(contracts: impl IntoIterator) -> Self { diff --git a/crates/e2e/src/lib.rs b/crates/e2e/src/lib.rs index 8cfcf81ac8..bc3f49a19e 100644 --- a/crates/e2e/src/lib.rs +++ b/crates/e2e/src/lib.rs @@ -47,8 +47,6 @@ pub use contract_results::{ InstantiationResult, UploadResult, }; -#[cfg(feature = "drink")] -pub use drink_client::Client as DrinkClient; pub use ink_e2e_macro::test; pub use node_proc::{ TestNodeProcess, @@ -69,6 +67,11 @@ pub use subxt_signer::sr25519::{ }; pub use tokio; pub use tracing_subscriber; +#[cfg(feature = "drink")] +pub use { + drink::runtime::MinimalRuntime, + drink_client::Client as DrinkClient, +}; use pallet_contracts_primitives::{ ContractExecResult, From 920b2a1e51b5eb097438c0ed69ac8ad6c0e5cffb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Wed, 30 Aug 2023 13:42:59 +0200 Subject: [PATCH 04/16] Verify in test --- .../e2e-runtime-only-backend/Cargo.toml | 1 + .../e2e-runtime-only-backend/lib.rs | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/integration-tests/e2e-runtime-only-backend/Cargo.toml b/integration-tests/e2e-runtime-only-backend/Cargo.toml index ef9c7871a1..04363edda7 100644 --- a/integration-tests/e2e-runtime-only-backend/Cargo.toml +++ b/integration-tests/e2e-runtime-only-backend/Cargo.toml @@ -13,6 +13,7 @@ scale-info = { version = "2.6", default-features = false, features = ["derive"], [dev-dependencies] ink_e2e = { path = "../../crates/e2e", features = ["drink"] } +drink = { version = "0.1.3" } [lib] path = "lib.rs" diff --git a/integration-tests/e2e-runtime-only-backend/lib.rs b/integration-tests/e2e-runtime-only-backend/lib.rs index 6f9eb11b71..3160569aa3 100644 --- a/integration-tests/e2e-runtime-only-backend/lib.rs +++ b/integration-tests/e2e-runtime-only-backend/lib.rs @@ -73,5 +73,22 @@ pub mod flipper { Ok(()) } + + /// Just instantiate a contract using non-default runtime. + #[ink_e2e::test(backend = "runtime-only", runtime = drink::runtime::MinimalRuntime)] + async fn custom_runtime(mut client: Client) -> E2EResult<()> { + client + .instantiate( + "e2e-runtime-only-backend", + &ink_e2e::alice(), + FlipperRef::new(false), + 0, + None, + ) + .await + .expect("instantiate failed"); + + Ok(()) + } } } From 008a8c26a16525ed99a6886d8ef4a29c432284aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Wed, 30 Aug 2023 13:57:51 +0200 Subject: [PATCH 05/16] Fmt, ui --- crates/e2e/macro/src/codegen.rs | 7 +++++-- .../ui/contract/fail/message-returns-non-codec.stderr | 2 +- .../ui/trait_def/fail/message_output_non_codec.stderr | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/crates/e2e/macro/src/codegen.rs b/crates/e2e/macro/src/codegen.rs index e9b7064b49..acc1b31feb 100644 --- a/crates/e2e/macro/src/codegen.rs +++ b/crates/e2e/macro/src/codegen.rs @@ -70,7 +70,9 @@ impl InkE2ETest { let client_building = match self.test.config.backend() { Backend::Full => build_full_client(&environment, exec_build_contracts), #[cfg(any(test, feature = "drink"))] - Backend::RuntimeOnly => build_runtime_client(exec_build_contracts, self.test.config.runtime()), + Backend::RuntimeOnly => { + build_runtime_client(exec_build_contracts, self.test.config.runtime()) + } }; quote! { @@ -148,7 +150,8 @@ fn build_full_client(environment: &syn::Path, contracts: TokenStream2) -> TokenS #[cfg(any(test, feature = "drink"))] fn build_runtime_client(contracts: TokenStream2, runtime: Option) -> TokenStream2 { - let runtime = runtime.unwrap_or_else(|| syn::parse_quote! { ::ink_e2e::MinimalRuntime }); + let runtime = + runtime.unwrap_or_else(|| syn::parse_quote! { ::ink_e2e::MinimalRuntime }); quote! { let contracts = #contracts; let mut client = ::ink_e2e::DrinkClient::<_, _, #runtime>::new(contracts); diff --git a/crates/ink/tests/ui/contract/fail/message-returns-non-codec.stderr b/crates/ink/tests/ui/contract/fail/message-returns-non-codec.stderr index 877500181f..b1b22479ad 100644 --- a/crates/ink/tests/ui/contract/fail/message-returns-non-codec.stderr +++ b/crates/ink/tests/ui/contract/fail/message-returns-non-codec.stderr @@ -52,7 +52,7 @@ error[E0599]: the method `try_invoke` exists for struct `CallBuilder $CARGO/parity-scale-codec-3.6.4/src/codec.rs + --> $CARGO/parity-scale-codec-3.6.5/src/codec.rs | | pub trait Decode: Sized { | ^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/crates/ink/tests/ui/trait_def/fail/message_output_non_codec.stderr b/crates/ink/tests/ui/trait_def/fail/message_output_non_codec.stderr index f232190395..27ce117e51 100644 --- a/crates/ink/tests/ui/trait_def/fail/message_output_non_codec.stderr +++ b/crates/ink/tests/ui/trait_def/fail/message_output_non_codec.stderr @@ -36,7 +36,7 @@ error[E0599]: the method `try_invoke` exists for struct `CallBuilder $CARGO/parity-scale-codec-3.6.4/src/codec.rs + --> $CARGO/parity-scale-codec-3.6.5/src/codec.rs | | pub trait Decode: Sized { | ^^^^^^^^^^^^^^^^^^^^^^^ From 02dd60896835916ee31de0ce7a6a4c132ab05cc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Wed, 30 Aug 2023 14:05:19 +0200 Subject: [PATCH 06/16] Explicit syn::Path --- crates/e2e/macro/src/codegen.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/e2e/macro/src/codegen.rs b/crates/e2e/macro/src/codegen.rs index acc1b31feb..94b75ff7d7 100644 --- a/crates/e2e/macro/src/codegen.rs +++ b/crates/e2e/macro/src/codegen.rs @@ -19,7 +19,6 @@ use crate::{ use derive_more::From; use proc_macro2::TokenStream as TokenStream2; use quote::quote; -use syn::Path; const DEFAULT_CONTRACTS_NODE: &str = "substrate-contracts-node"; @@ -149,7 +148,10 @@ fn build_full_client(environment: &syn::Path, contracts: TokenStream2) -> TokenS } #[cfg(any(test, feature = "drink"))] -fn build_runtime_client(contracts: TokenStream2, runtime: Option) -> TokenStream2 { +fn build_runtime_client( + contracts: TokenStream2, + runtime: Option, +) -> TokenStream2 { let runtime = runtime.unwrap_or_else(|| syn::parse_quote! { ::ink_e2e::MinimalRuntime }); quote! { From de1f51d62ccaa9d2029b6507875e40993d72e123 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Thu, 7 Sep 2023 16:45:09 +0200 Subject: [PATCH 07/16] No need for drink dependency --- integration-tests/e2e-runtime-only-backend/Cargo.toml | 1 - integration-tests/e2e-runtime-only-backend/lib.rs | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/integration-tests/e2e-runtime-only-backend/Cargo.toml b/integration-tests/e2e-runtime-only-backend/Cargo.toml index 09f1cf7a45..9dd257f4fd 100644 --- a/integration-tests/e2e-runtime-only-backend/Cargo.toml +++ b/integration-tests/e2e-runtime-only-backend/Cargo.toml @@ -10,7 +10,6 @@ ink = { path = "../../crates/ink", default-features = false } [dev-dependencies] ink_e2e = { path = "../../crates/e2e", features = ["drink"] } -drink = { version = "0.1.3" } [lib] path = "lib.rs" diff --git a/integration-tests/e2e-runtime-only-backend/lib.rs b/integration-tests/e2e-runtime-only-backend/lib.rs index 3160569aa3..16394d34a3 100644 --- a/integration-tests/e2e-runtime-only-backend/lib.rs +++ b/integration-tests/e2e-runtime-only-backend/lib.rs @@ -75,7 +75,7 @@ pub mod flipper { } /// Just instantiate a contract using non-default runtime. - #[ink_e2e::test(backend = "runtime-only", runtime = drink::runtime::MinimalRuntime)] + #[ink_e2e::test(backend = "runtime-only", runtime = ink_e2e::MinimalRuntime)] async fn custom_runtime(mut client: Client) -> E2EResult<()> { client .instantiate( From ad087c49d46d7cb0358775924219c71149c19d26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Thu, 7 Sep 2023 16:52:19 +0200 Subject: [PATCH 08/16] Fix drink version --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index ada0acdb96..a59a39d80e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,7 +38,7 @@ cargo_metadata = { version = "0.17.0" } cfg-if = { version = "1.0" } contract-build = { version = "3.2.0" } derive_more = { version = "0.99.17", default-features = false } -drink = { version = "0.1.2" } +drink = { version = "=0.1.2" } either = { version = "1.5", default-features = false } funty = { version = "2.0.0" } heck = { version = "0.4.0" } From 657536331d72eb04e94112e82d033e5ce04f7905 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Thu, 7 Sep 2023 16:58:11 +0200 Subject: [PATCH 09/16] Fix codec version --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a59a39d80e..044709aeac 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,7 +38,7 @@ cargo_metadata = { version = "0.17.0" } cfg-if = { version = "1.0" } contract-build = { version = "3.2.0" } derive_more = { version = "0.99.17", default-features = false } -drink = { version = "=0.1.2" } +drink = { version = "=0.1.3" } either = { version = "1.5", default-features = false } funty = { version = "2.0.0" } heck = { version = "0.4.0" } @@ -54,7 +54,7 @@ quickcheck = { version = "1" } quickcheck_macros = { version = "1" } quote = { version = "1" } rlibc = { version = "1" } -scale = { package = "parity-scale-codec", version = "3.4", default-features = false, features = ["derive"] } +scale = { package = "parity-scale-codec", version = "=3.6.5", default-features = false, features = ["derive"] } scale-decode = { version = "0.9.0", default-features = false } scale-encode = { version = "0.5.0", default-features = false } scale-info = { version = "2.6", default-features = false } From 28fa7e5638137df1d438efcd3b49bac1a271a6a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Thu, 7 Sep 2023 17:20:17 +0200 Subject: [PATCH 10/16] revert: Fix codec version --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 044709aeac..eb9a2090c4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -54,7 +54,7 @@ quickcheck = { version = "1" } quickcheck_macros = { version = "1" } quote = { version = "1" } rlibc = { version = "1" } -scale = { package = "parity-scale-codec", version = "=3.6.5", default-features = false, features = ["derive"] } +scale = { package = "parity-scale-codec", version = "3.4", default-features = false, features = ["derive"] } scale-decode = { version = "0.9.0", default-features = false } scale-encode = { version = "0.5.0", default-features = false } scale-info = { version = "2.6", default-features = false } From 82c980ce8813c747799cef24839fe5d62cb41d8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Thu, 7 Sep 2023 19:14:11 +0200 Subject: [PATCH 11/16] Expect with reason --- crates/e2e/src/drink_client.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/e2e/src/drink_client.rs b/crates/e2e/src/drink_client.rs index 27efe2dded..465a096c9c 100644 --- a/crates/e2e/src/drink_client.rs +++ b/crates/e2e/src/drink_client.rs @@ -260,7 +260,11 @@ impl< } }; - let code_hash_raw: [u8; 32] = result.code_hash.as_ref().try_into().expect(""); + let code_hash_raw: [u8; 32] = result + .code_hash + .as_ref() + .try_into() + .expect("Invalid code hash"); let code_hash = Hash::from(code_hash_raw); Ok(UploadResult { code_hash, From 9adced3d025added1e2ccb9c68d728efb77b49c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Thu, 7 Sep 2023 19:18:22 +0200 Subject: [PATCH 12/16] Lol --- crates/e2e/src/drink_client.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/e2e/src/drink_client.rs b/crates/e2e/src/drink_client.rs index 465a096c9c..6fcaeabfa0 100644 --- a/crates/e2e/src/drink_client.rs +++ b/crates/e2e/src/drink_client.rs @@ -24,6 +24,7 @@ use drink::{ }, contract_api::ContractApi, runtime::Runtime as RuntimeT, + MinimalRuntime, Sandbox, DEFAULT_GAS_LIMIT, }; From 0ac75b6c4a960672e754822e4d4ac23e43b06790 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Thu, 7 Sep 2023 19:26:37 +0200 Subject: [PATCH 13/16] wtf --- crates/e2e/src/drink_client.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/e2e/src/drink_client.rs b/crates/e2e/src/drink_client.rs index 6fcaeabfa0..a8b41455eb 100644 --- a/crates/e2e/src/drink_client.rs +++ b/crates/e2e/src/drink_client.rs @@ -23,8 +23,10 @@ use drink::{ RuntimeCall, }, contract_api::ContractApi, - runtime::Runtime as RuntimeT, - MinimalRuntime, + runtime::{ + MinimalRuntime, + Runtime as RuntimeT, + }, Sandbox, DEFAULT_GAS_LIMIT, }; From a5c9beda489484f9f188055589c6b241b208cb81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Fri, 8 Sep 2023 09:18:00 +0200 Subject: [PATCH 14/16] Update drink --- Cargo.toml | 2 +- crates/e2e/src/drink_client.rs | 39 +++++++++++++++++++++------------- crates/ink/macro/src/scale.rs | 2 +- 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c5969f2466..21bf8b4446 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,7 +38,7 @@ cargo_metadata = { version = "0.17.0" } cfg-if = { version = "1.0" } contract-build = { version = "3.2.0" } derive_more = { version = "0.99.17", default-features = false } -drink = { version = "=0.1.3" } +drink = { version = "=0.1.6" } either = { version = "1.5", default-features = false } funty = { version = "2.0.0" } heck = { version = "0.4.0" } diff --git a/crates/e2e/src/drink_client.rs b/crates/e2e/src/drink_client.rs index a8b41455eb..b39ab2d62e 100644 --- a/crates/e2e/src/drink_client.rs +++ b/crates/e2e/src/drink_client.rs @@ -23,10 +23,7 @@ use drink::{ RuntimeCall, }, contract_api::ContractApi, - runtime::{ - MinimalRuntime, - Runtime as RuntimeT, - }, + runtime::Runtime as RuntimeT, Sandbox, DEFAULT_GAS_LIMIT, }; @@ -43,7 +40,6 @@ use scale::{ Encode, }; use sp_core::{ - crypto::AccountId32, sr25519::Pair, Pair as _, }; @@ -71,7 +67,12 @@ unsafe impl Send { } -impl Client { +type RuntimeAccountId = ::AccountId; + +impl Client +where + RuntimeAccountId: From<[u8; 32]>, +{ pub fn new>(contracts: impl IntoIterator) -> Self { let mut sandbox = Sandbox::new().expect("Failed to initialize Drink! sandbox"); Self::fund_accounts(&mut sandbox); @@ -97,7 +98,7 @@ impl Client { crate::two(), ] .map(|kp| kp.public_key().0) - .map(AccountId32::new); + .map(From::from); for account in accounts.into_iter() { sandbox.add_tokens(account, TOKENS); } @@ -107,6 +108,8 @@ impl Client { #[async_trait] impl + Send, Hash, Runtime: RuntimeT> ChainBackend for Client +where + RuntimeAccountId: From<[u8; 32]>, { type AccountId = AccountId; type Balance = u128; @@ -129,7 +132,7 @@ impl + Send, Hash, Runtime: RuntimeT> ChainBackend &mut self, account: Self::AccountId, ) -> Result { - let account = AccountId32::new(*account.as_ref()); + let account = RuntimeAccountId::::from(*account.as_ref()); Ok(self.sandbox.balance(&account)) } @@ -147,7 +150,7 @@ impl + Send, Hash, Runtime: RuntimeT> ChainBackend // Get metadata of the drink! runtime, 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 = MinimalRuntime::metadata().into(); + let raw_metadata: Vec = Runtime::get_metadata().into(); let metadata = subxt_metadata::Metadata::decode(&mut raw_metadata.as_slice()) .expect("Failed to decode metadata"); @@ -158,13 +161,15 @@ impl + Send, Hash, Runtime: RuntimeT> ChainBackend // 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()) - .expect("Failed to decode runtime call"); + let decoded_call = RuntimeCall::::decode(&mut encoded_call.as_slice()) + .expect("Failed to decode runtime call"); // Execute the call. self.sandbox - .runtime_call(decoded_call, Some(keypair_to_account(origin)).into()) + .runtime_call( + decoded_call, + Runtime::convert_account_to_origin(keypair_to_account(origin)), + ) .map_err(|_| ())?; Ok(()) @@ -178,6 +183,8 @@ impl< Runtime: RuntimeT, E: Environment + 'static, > ContractsBackend for Client +where + RuntimeAccountId: From<[u8; 32]> + AsRef<[u8; 32]>, { type Error = (); type EventLog = (); @@ -339,9 +346,11 @@ impl< Runtime: RuntimeT, E: Environment + 'static, > E2EBackend for Client +where + RuntimeAccountId: From<[u8; 32]> + AsRef<[u8; 32]>, { } -fn keypair_to_account(keypair: &Keypair) -> AccountId32 { - AccountId32::from(keypair.public_key().0) +fn keypair_to_account>(keypair: &Keypair) -> AccountId { + AccountId::from(keypair.public_key().0) } diff --git a/crates/ink/macro/src/scale.rs b/crates/ink/macro/src/scale.rs index 5868342850..52bce8a2ea 100644 --- a/crates/ink/macro/src/scale.rs +++ b/crates/ink/macro/src/scale.rs @@ -36,7 +36,7 @@ pub fn derive(attr: TokenStream2, item: TokenStream2) -> syn::Result Date: Fri, 8 Sep 2023 09:37:19 +0200 Subject: [PATCH 15/16] Trigger CI --- crates/e2e/src/drink_client.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/crates/e2e/src/drink_client.rs b/crates/e2e/src/drink_client.rs index b39ab2d62e..3b05e8c41f 100644 --- a/crates/e2e/src/drink_client.rs +++ b/crates/e2e/src/drink_client.rs @@ -59,9 +59,8 @@ pub struct Client { _phantom: PhantomData<(AccountId, Hash)>, } -// 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. +// 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 { From f3d24dfdb2616c133b3bfd49ca139f4521807326 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Fri, 8 Sep 2023 09:40:16 +0200 Subject: [PATCH 16/16] fmt --- crates/e2e/src/drink_client.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/e2e/src/drink_client.rs b/crates/e2e/src/drink_client.rs index 3b05e8c41f..b39ab2d62e 100644 --- a/crates/e2e/src/drink_client.rs +++ b/crates/e2e/src/drink_client.rs @@ -59,8 +59,9 @@ pub struct Client { _phantom: PhantomData<(AccountId, Hash)>, } -// 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. +// 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 {