Skip to content

Commit

Permalink
fix: support new substrate-contracts-node structure and stabilize int…
Browse files Browse the repository at this point in the history
…egration tests (#360)

* fix: parse new structure substrate-contracts-node

* fix: paseo+coretime integration test

* fix: sourcing latest version substrate-contracts-node

* refactor: set_executable_permission function

* fix: clippy

* chore: CI configuration

* test: specify port in run_contracts_node

* fix: use random ports instead of hardcoded ones
  • Loading branch information
AlexD10S committed Dec 13, 2024
1 parent e0d5711 commit 63fcb22
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 9 deletions.
10 changes: 6 additions & 4 deletions crates/pop-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down
2 changes: 1 addition & 1 deletion crates/pop-contracts/src/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
2 changes: 1 addition & 1 deletion crates/pop-contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions crates/pop-contracts/src/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions crates/pop-contracts/src/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::{create_smart_contract, Contract};
use anyhow::Result;
use std::{
fs::{copy, create_dir},
net::TcpListener,
path::Path,
};

Expand Down Expand Up @@ -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()
}
2 changes: 1 addition & 1 deletion crates/pop-contracts/src/up.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
4 changes: 2 additions & 2 deletions crates/pop-parachains/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ pub fn is_supported(path: Option<&Path>) -> Result<bool, Error> {
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))
}))
}

Expand Down

0 comments on commit 63fcb22

Please sign in to comment.