diff --git a/CHANGELOG.md b/CHANGELOG.md index e81a30944a5..f585cf31346 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added +- [E2E] Allow testing with live-chain state - [#1949](https://github.com/paritytech/ink/pull/1949) - [E2E] Call builders and extra gas margin option - [#1917](https://github.com/paritytech/ink/pull/1917) - Make `set_code_hash` generic - [#1906](https://github.com/paritytech/ink/pull/1906) - Clean E2E configuration parsing - [#1922](https://github.com/paritytech/ink/pull/1922) diff --git a/crates/e2e/macro/src/codegen.rs b/crates/e2e/macro/src/codegen.rs index d146ee389c2..40c7a91ce6d 100644 --- a/crates/e2e/macro/src/codegen.rs +++ b/crates/e2e/macro/src/codegen.rs @@ -32,7 +32,7 @@ impl InkE2ETest { pub fn generate_code(&self) -> TokenStream2 { #[cfg(clippy)] if true { - return quote! {} + return quote! {}; } let item_fn = &self.test.item_fn.item_fn; @@ -64,8 +64,12 @@ impl InkE2ETest { } }; + let node_url = self.test.config.node_url(); + let client_building = match self.test.config.backend() { - Backend::Full => build_full_client(&environment, exec_build_contracts), + Backend::Full => { + build_full_client(&environment, exec_build_contracts, node_url) + } #[cfg(any(test, feature = "drink"))] Backend::RuntimeOnly { runtime } => { build_runtime_client(exec_build_contracts, runtime) @@ -110,22 +114,42 @@ impl InkE2ETest { } } -fn build_full_client(environment: &syn::Path, contracts: TokenStream2) -> TokenStream2 { - quote! { - // Spawn a contracts node process just for this test. - let node_proc = ::ink_e2e::TestNodeProcess::<::ink_e2e::PolkadotConfig> - ::build_with_env_or_default() - .spawn() - .await - .unwrap_or_else(|err| - ::core::panic!("Error spawning substrate-contracts-node: {err:?}") - ); - - let contracts = #contracts; - let mut client = ::ink_e2e::Client::< - ::ink_e2e::PolkadotConfig, - #environment - >::new(node_proc.rpc(), contracts).await?; +fn build_full_client( + environment: &syn::Path, + contracts: TokenStream2, + node_url: Option, +) -> TokenStream2 { + match node_url { + Some(url) => { + quote! { + let rpc = ::ink_e2e::RpcClient::from_url(#url) + .await + .unwrap_or_else(|err| + ::core::panic!("Error connecting to Chopsticks node: {err:?}") + ); + let contracts = #contracts; + let mut client = ::ink_e2e::Client::< + ::ink_e2e::PolkadotConfig, + #environment + >::new(rpc, contracts).await?; + } + } + None => { + quote! { + let node_rpc = ::ink_e2e::TestNodeProcess::<::ink_e2e::PolkadotConfig> + ::build_with_env_or_default() + .spawn() + .await + .unwrap_or_else(|err| + ::core::panic!("Error spawning substrate-contracts-node: {err:?}") + ); + let contracts = #contracts; + let mut client = ::ink_e2e::Client::< + ::ink_e2e::PolkadotConfig, + #environment + >::new(node_rpc.rpc(), contracts).await?; + } + } } } diff --git a/crates/e2e/macro/src/config.rs b/crates/e2e/macro/src/config.rs index 383e9c27b69..481c8e468ed 100644 --- a/crates/e2e/macro/src/config.rs +++ b/crates/e2e/macro/src/config.rs @@ -46,6 +46,9 @@ pub struct E2EConfig { /// The type of the architecture that should be used to run test. #[darling(default)] backend: Backend, + /// The URL to the running node. If not set then a default node instance will be + /// spawned per test. + node_url: Option, } impl E2EConfig { @@ -73,6 +76,12 @@ impl E2EConfig { pub fn backend(&self) -> Backend { self.backend.clone() } + + /// The URL to the running node. If not set then a default node instance will be + /// spawned per test. + pub fn node_url(&self) -> Option { + self.node_url.clone() + } } #[cfg(test)] @@ -90,6 +99,7 @@ mod tests { additional_contracts = "adder/Cargo.toml flipper/Cargo.toml", environment = crate::CustomEnvironment, backend(runtime_only()), + node_url = "ws://127.0.0.1:8000" }; let config = E2EConfig::from_list(&NestedMeta::parse_meta_list(input).unwrap()).unwrap(); @@ -104,6 +114,7 @@ mod tests { ); assert_eq!(config.backend(), Backend::RuntimeOnly { runtime: None }); + assert_eq!(config.node_url(), Some(String::from("ws://127.0.0.1:8000"))) } #[test] @@ -120,5 +131,6 @@ mod tests { runtime: Some(syn::parse_quote! { ::ink_e2e::MinimalRuntime }) } ); + assert_eq!(config.node_url(), None) } } diff --git a/crates/e2e/src/lib.rs b/crates/e2e/src/lib.rs index b620c34d764..3891fab4cb8 100644 --- a/crates/e2e/src/lib.rs +++ b/crates/e2e/src/lib.rs @@ -59,7 +59,10 @@ pub use node_proc::{ }; pub use sp_core::H256; pub use sp_keyring::AccountKeyring; -pub use subxt; +pub use subxt::{ + self, + backend::rpc::RpcClient, +}; pub use subxt_client::{ CallBuilderFinal, Client, diff --git a/integration-tests/e2e-call-runtime/Cargo.toml b/integration-tests/e2e-call-runtime/Cargo.toml index aba6b35386e..9df477a7558 100644 --- a/integration-tests/e2e-call-runtime/Cargo.toml +++ b/integration-tests/e2e-call-runtime/Cargo.toml @@ -10,7 +10,6 @@ ink = { path = "../../crates/ink", default-features = false } [dev-dependencies] ink_e2e = { path = "../../crates/e2e" } -subxt = { version = "0.32.1", default-features = false } [lib] path = "lib.rs"