diff --git a/crates/e2e/macro/src/codegen.rs b/crates/e2e/macro/src/codegen.rs index 406667f8a8..f7043c45e4 100644 --- a/crates/e2e/macro/src/codegen.rs +++ b/crates/e2e/macro/src/codegen.rs @@ -137,13 +137,13 @@ fn build_full_client( None => { quote! { let node_rpc = if let Ok(url) = ::std::env::var("CONTRACTS_NODE_URL") { - ::ink_e2e::TestNodeProcess::<::ink_e2e::PolkadotConfig>::from_url(url.clone()) + ::ink_e2e::TestNode::<::ink_e2e::PolkadotConfig>::from_url(url.clone()) .await .unwrap_or_else(|err| ::core::panic!("Error using existing substrate-contracts-node at {url:?}: {err:?}") ) } else { - ::ink_e2e::TestNodeProcess::<::ink_e2e::PolkadotConfig> + ::ink_e2e::TestNode::<::ink_e2e::PolkadotConfig> ::build_with_env_or_default() .spawn() .await diff --git a/crates/e2e/src/lib.rs b/crates/e2e/src/lib.rs index ad8bc89895..8640988888 100644 --- a/crates/e2e/src/lib.rs +++ b/crates/e2e/src/lib.rs @@ -29,8 +29,8 @@ mod contract_results; mod drink_client; mod error; pub mod events; -mod node_proc; mod subxt_client; +mod test_node; mod xts; pub use crate::contract_build::{ @@ -54,10 +54,6 @@ pub use contract_results::{ UploadResult, }; pub use ink_e2e_macro::test; -pub use node_proc::{ - TestNodeProcess, - TestNodeProcessBuilder, -}; pub use sp_core::H256; pub use sp_keyring::AccountKeyring; pub use subxt::{ @@ -74,6 +70,10 @@ pub use subxt_signer::sr25519::{ dev::*, Keypair, }; +pub use test_node::{ + TestNode, + TestNodeBuilder, +}; pub use tokio; pub use tracing_subscriber; #[cfg(feature = "drink")] diff --git a/crates/e2e/src/node_proc.rs b/crates/e2e/src/test_node.rs similarity index 89% rename from crates/e2e/src/node_proc.rs rename to crates/e2e/src/test_node.rs index 124274cc0b..68be35e267 100644 --- a/crates/e2e/src/node_proc.rs +++ b/crates/e2e/src/test_node.rs @@ -32,14 +32,14 @@ use subxt::{ }; /// Spawn a local substrate node for testing. -pub struct TestNodeProcess { +pub struct TestNode { proc: Option, rpc: RpcClient, client: OnlineClient, url: String, } -impl Drop for TestNodeProcess +impl Drop for TestNode where R: Config, { @@ -48,23 +48,23 @@ where } } -impl TestNodeProcess +impl TestNode where R: Config, { /// Construct a builder for spawning a test node process. - pub fn build(program: S) -> TestNodeProcessBuilder + pub fn build(program: S) -> TestNodeBuilder where S: AsRef + Clone, { - TestNodeProcessBuilder::new(program) + TestNodeBuilder::new(program) } /// Construct a test node process from a URL. /// - /// This is used when the `CONTRACTS_NODE_URL` environment variable is set, to run e2e + /// This is used when the `CONTRACTS_NODE_URL` environment variable is set, to run E2E /// tests against a running node. - pub async fn from_url(url: String) -> Result, String> { + pub async fn from_url(url: String) -> Result, String> { let rpc = RpcClient::from_url(url.clone()) .await .map_err(|err| format!("Error initializing rpc client: {err}"))?; @@ -83,7 +83,7 @@ where /// Construct a builder for spawning a test node process, using the environment /// variable `CONTRACTS_NODE`, otherwise using the default contracts node. - pub fn build_with_env_or_default() -> TestNodeProcessBuilder { + pub fn build_with_env_or_default() -> TestNodeBuilder { const DEFAULT_CONTRACTS_NODE: &str = "substrate-contracts-node"; // Use the user supplied `CONTRACTS_NODE` or default to `DEFAULT_CONTRACTS_NODE`. @@ -136,17 +136,17 @@ where } /// Construct a test node process. -pub struct TestNodeProcessBuilder { +pub struct TestNodeBuilder { node_path: OsString, authority: Option, marker: std::marker::PhantomData, } -impl TestNodeProcessBuilder +impl TestNodeBuilder where R: Config, { - pub fn new

(node_path: P) -> TestNodeProcessBuilder + pub fn new

(node_path: P) -> TestNodeBuilder where P: AsRef, { @@ -164,7 +164,7 @@ where } /// Spawn the substrate node at the given path, and wait for RPC to be initialized. - pub async fn spawn(&self) -> Result, String> { + pub async fn spawn(&self) -> Result, String> { let mut cmd = process::Command::new(&self.node_path); cmd.env("RUST_LOG", "info") .arg("--dev") @@ -199,7 +199,7 @@ where let client = OnlineClient::from_url(url.clone()).await; match client { Ok(client) => { - Ok(TestNodeProcess { + Ok(TestNode { proc: Some(proc), rpc, client, @@ -266,18 +266,16 @@ mod tests { let mut client2: Option> = None; { - let node_proc1 = - TestNodeProcess::::build("substrate-contracts-node") - .spawn() - .await - .unwrap(); + let node_proc1 = TestNode::::build("substrate-contracts-node") + .spawn() + .await + .unwrap(); client1 = Some(LegacyRpcMethods::new(node_proc1.rpc())); - let node_proc2 = - TestNodeProcess::::build("substrate-contracts-node") - .spawn() - .await - .unwrap(); + let node_proc2 = TestNode::::build("substrate-contracts-node") + .spawn() + .await + .unwrap(); client2 = Some(LegacyRpcMethods::new(node_proc2.rpc())); let res1 = client1.clone().unwrap().chain_get_block_hash(None).await;