Skip to content

Commit

Permalink
Renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
pgherveou committed Jan 8, 2024
1 parent 09f318f commit f33e0f1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 30 deletions.
4 changes: 2 additions & 2 deletions crates/e2e/macro/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions crates/e2e/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand All @@ -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::{
Expand All @@ -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")]
Expand Down
44 changes: 21 additions & 23 deletions crates/e2e/src/node_proc.rs → crates/e2e/src/test_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ use subxt::{
};

/// Spawn a local substrate node for testing.
pub struct TestNodeProcess<R: Config> {
pub struct TestNode<R: Config> {
proc: Option<process::Child>,
rpc: RpcClient,
client: OnlineClient<R>,
url: String,
}

impl<R> Drop for TestNodeProcess<R>
impl<R> Drop for TestNode<R>
where
R: Config,
{
Expand All @@ -48,23 +48,23 @@ where
}
}

impl<R> TestNodeProcess<R>
impl<R> TestNode<R>
where
R: Config,
{
/// Construct a builder for spawning a test node process.
pub fn build<S>(program: S) -> TestNodeProcessBuilder<R>
pub fn build<S>(program: S) -> TestNodeBuilder<R>
where
S: AsRef<OsStr> + 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<TestNodeProcess<R>, String> {
pub async fn from_url(url: String) -> Result<TestNode<R>, String> {
let rpc = RpcClient::from_url(url.clone())
.await
.map_err(|err| format!("Error initializing rpc client: {err}"))?;
Expand All @@ -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<R> {
pub fn build_with_env_or_default() -> TestNodeBuilder<R> {
const DEFAULT_CONTRACTS_NODE: &str = "substrate-contracts-node";

// Use the user supplied `CONTRACTS_NODE` or default to `DEFAULT_CONTRACTS_NODE`.
Expand Down Expand Up @@ -136,17 +136,17 @@ where
}

/// Construct a test node process.
pub struct TestNodeProcessBuilder<R> {
pub struct TestNodeBuilder<R> {
node_path: OsString,
authority: Option<AccountKeyring>,
marker: std::marker::PhantomData<R>,
}

impl<R> TestNodeProcessBuilder<R>
impl<R> TestNodeBuilder<R>
where
R: Config,
{
pub fn new<P>(node_path: P) -> TestNodeProcessBuilder<R>
pub fn new<P>(node_path: P) -> TestNodeBuilder<R>
where
P: AsRef<OsStr>,
{
Expand All @@ -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<TestNodeProcess<R>, String> {
pub async fn spawn(&self) -> Result<TestNode<R>, String> {
let mut cmd = process::Command::new(&self.node_path);
cmd.env("RUST_LOG", "info")
.arg("--dev")
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -266,18 +266,16 @@ mod tests {
let mut client2: Option<LegacyRpcMethods<SubxtConfig>> = None;

{
let node_proc1 =
TestNodeProcess::<SubxtConfig>::build("substrate-contracts-node")
.spawn()
.await
.unwrap();
let node_proc1 = TestNode::<SubxtConfig>::build("substrate-contracts-node")
.spawn()
.await
.unwrap();
client1 = Some(LegacyRpcMethods::new(node_proc1.rpc()));

let node_proc2 =
TestNodeProcess::<SubxtConfig>::build("substrate-contracts-node")
.spawn()
.await
.unwrap();
let node_proc2 = TestNode::<SubxtConfig>::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;
Expand Down

0 comments on commit f33e0f1

Please sign in to comment.