diff --git a/crates/pop-common/src/lib.rs b/crates/pop-common/src/lib.rs index 70dbcc8f8..8e3022f24 100644 --- a/crates/pop-common/src/lib.rs +++ b/crates/pop-common/src/lib.rs @@ -49,16 +49,18 @@ pub fn target() -> Result<&'static str, Error> { } match ARCH { - "aarch64" => + "aarch64" => { return match OS { "macos" => Ok("aarch64-apple-darwin"), _ => Ok("aarch64-unknown-linux-gnu"), - }, - "x86_64" | "x86" => + } + }, + "x86_64" | "x86" => { return match OS { "macos" => Ok("x86_64-apple-darwin"), _ => Ok("x86_64-unknown-linux-gnu"), - }, + } + }, &_ => {}, } Err(Error::UnsupportedPlatform { arch: ARCH, os: OS }) diff --git a/crates/pop-contracts/src/call.rs b/crates/pop-contracts/src/call.rs index 03effcb0a..546415ec5 100644 --- a/crates/pop-contracts/src/call.rs +++ b/crates/pop-contracts/src/call.rs @@ -179,7 +179,7 @@ mod tests { use crate::{ contracts_node_generator, dry_run_gas_estimate_instantiate, errors::Error, instantiate_smart_contract, mock_build_process, new_environment, run_contracts_node, - set_up_deployment, UpOpts, + set_up_deployment, testing::find_free_port, UpOpts, }; use anyhow::Result; use pop_common::{find_free_port, set_executable_permission}; diff --git a/crates/pop-contracts/src/lib.rs b/crates/pop-contracts/src/lib.rs index 69897be33..e775d7f08 100644 --- a/crates/pop-contracts/src/lib.rs +++ b/crates/pop-contracts/src/lib.rs @@ -20,7 +20,7 @@ pub use new::{create_smart_contract, is_valid_contract_name}; pub use node::{contracts_node_generator, is_chain_alive, run_contracts_node}; pub use templates::{Contract, ContractType}; pub use test::{test_e2e_smart_contract, test_smart_contract}; -pub use testing::{mock_build_process, new_environment}; +pub use testing::{find_free_port, mock_build_process, new_environment}; pub use up::{ dry_run_gas_estimate_instantiate, dry_run_upload, get_code_hash_from_event, get_contract_code, get_instantiate_payload, get_upload_payload, instantiate_contract_signed, diff --git a/crates/pop-contracts/src/node/mod.rs b/crates/pop-contracts/src/node/mod.rs index be5680a04..7818d53d5 100644 --- a/crates/pop-contracts/src/node/mod.rs +++ b/crates/pop-contracts/src/node/mod.rs @@ -166,6 +166,8 @@ fn release_directory_by_target(tag: Option<&str>) -> Result<&'static str, Error> #[cfg(test)] mod tests { + use crate::testing::find_free_port; + use super::*; use anyhow::{Error, Result}; use pop_common::find_free_port; diff --git a/crates/pop-contracts/src/testing.rs b/crates/pop-contracts/src/testing.rs index 6a8abfcd9..c10bd4e5f 100644 --- a/crates/pop-contracts/src/testing.rs +++ b/crates/pop-contracts/src/testing.rs @@ -4,6 +4,7 @@ use crate::{create_smart_contract, Contract}; use anyhow::Result; use std::{ fs::{copy, create_dir}, + net::TcpListener, path::Path, }; @@ -37,3 +38,12 @@ where copy(metadata_file, target_contract_dir.join("ink/testing.json"))?; Ok(()) } + +/// Finds an available port by binding to port 0 and retrieving the assigned port. +pub fn find_free_port() -> u16 { + TcpListener::bind("127.0.0.1:0") + .expect("Failed to bind to an available port") + .local_addr() + .expect("Failed to retrieve local address") + .port() +} diff --git a/crates/pop-contracts/src/up.rs b/crates/pop-contracts/src/up.rs index 66dd54980..b731b1c31 100644 --- a/crates/pop-contracts/src/up.rs +++ b/crates/pop-contracts/src/up.rs @@ -381,7 +381,7 @@ mod tests { use super::*; use crate::{ contracts_node_generator, errors::Error, mock_build_process, new_environment, - run_contracts_node, + run_contracts_node, testing::find_free_port, }; use anyhow::Result; use pop_common::{find_free_port, set_executable_permission}; diff --git a/crates/pop-parachains/src/build.rs b/crates/pop-parachains/src/build.rs index 1e369f371..1cc869e31 100644 --- a/crates/pop-parachains/src/build.rs +++ b/crates/pop-parachains/src/build.rs @@ -51,8 +51,8 @@ pub fn is_supported(path: Option<&Path>) -> Result { const DEPENDENCIES: [&str; 4] = ["cumulus-client-collator", "cumulus-primitives-core", "parachains-common", "polkadot-sdk"]; Ok(DEPENDENCIES.into_iter().any(|d| { - manifest.dependencies.contains_key(d) || - manifest.workspace.as_ref().map_or(false, |w| w.dependencies.contains_key(d)) + manifest.dependencies.contains_key(d) + || manifest.workspace.as_ref().map_or(false, |w| w.dependencies.contains_key(d)) })) }