From cc778b1f840a930df4cccfe5711cf50a6148c53b Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Wed, 4 Dec 2024 10:47:32 +0100 Subject: [PATCH 1/2] Have port parsing handle comma-separated list --- CHANGELOG.md | 2 +- Cargo.lock | 1 + crates/e2e/Cargo.toml | 1 + crates/e2e/src/node_proc.rs | 34 ++++++++++++++++++++++++++++++++-- 4 files changed, 35 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e9f8ff4054..81ee9016b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,7 +37,7 @@ to cross-contract calls, but can now execute cross-parachain calls. We added a contract example that demonstrates the usage: [`contract-xcm`](https://github.com/use-ink/ink-examples/tree/main/contract-xcm) -We also added a new page on our documentation website: +We also added a new page on our documentation website: [https://use.ink/basics/xcm](https://use.ink/basics/xcm). You can view the Rust docs of the two functions here: diff --git a/Cargo.lock b/Cargo.lock index 27af21a7dd..12ad9387ab 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2792,6 +2792,7 @@ dependencies = [ "pallet-contracts", "pallet-contracts-mock-network", "parity-scale-codec", + "regex", "scale-info", "serde", "serde_json", diff --git a/crates/e2e/Cargo.toml b/crates/e2e/Cargo.toml index 0ef4d60a11..c1a43a79d6 100644 --- a/crates/e2e/Cargo.toml +++ b/crates/e2e/Cargo.toml @@ -47,6 +47,7 @@ sp-core = { workspace = true } sp-keyring = { workspace = true } sp-runtime = { workspace = true } sp-weights = { workspace = true } +regex = "1.11.1" [dev-dependencies] # Required for the doctest of `MessageBuilder::call` diff --git a/crates/e2e/src/node_proc.rs b/crates/e2e/src/node_proc.rs index 8df4f3cab2..ed70795324 100644 --- a/crates/e2e/src/node_proc.rs +++ b/crates/e2e/src/node_proc.rs @@ -212,8 +212,17 @@ fn find_substrate_port_from_output(r: impl Read + Send + 'static) -> u16 { .or_else(|| line.rsplit_once("Running JSON-RPC server: addr=127.0.0.1:")) .map(|(_, port_str)| port_str)?; - // trim non-numeric chars from the end of the port part of the line. - let port_str = line_end.trim_end_matches(|b: char| !b.is_ascii_digit()); + // match the first group of digits + let re = regex::Regex::new(r"^\d+").expect("regex creation failed"); + let port_capture = re + .captures(line_end) + .unwrap_or_else(|| panic!("unable to extract port from '{}'", line_end)); + assert!( + port_capture.len() == 1, + "captured more than one port from '{}'", + line_end + ); + let port_str = &port_capture[0]; // expect to have a number here (the chars after '127.0.0.1:') and parse them // into a u16. @@ -269,4 +278,25 @@ mod tests { assert!(res1.is_err()); assert!(res2.is_err()); } + + #[test] + fn parse_port_from_node_output() { + let log = "2024-12-04 10:57:03.893 INFO main sc_rpc_server: Running JSON-RPC server: addr=127.0.0.1:9944,[::1]:9944 "; + let port = find_substrate_port_from_output(log.as_bytes()); + assert_eq!(port, 9944); + + let log = "2024-12-04 10:57:03.893 INFO main sc_rpc_server: Running JSON-RPC server: addr=127.0.0.1:9944 "; + let port = find_substrate_port_from_output(log.as_bytes()); + assert_eq!(port, 9944); + + let log = r#"2024-12-04 11:02:24.637 INFO main sc_cli::runner: 👤 Role: AUTHORITY +2024-12-04 11:02:24.637 INFO main sc_cli::runner: 💾 Database: RocksDb at /var/folders/s5/5gcp8ck95k39z006fj059_0c0000gn/T/substrateHZoRbb/chains/dev/db/full +2024-12-04 11:02:25.324 WARN main sc_service::config: Using default protocol ID "sup" because none is configured in the chain specs +2024-12-04 11:02:25.327 INFO main sc_rpc_server: Running JSON-RPC server: addr=127.0.0.1:9944,[::1]:9944 +2024-12-04 11:02:24.637 INFO main sc_cli::runner: 💾 Database: RocksDb at /var/folders/s5/5gcp8ck95k39z006fj059_0c0000gn/T/substrateHZoRbb/chains/dev/db/full +2024-12-04 11:02:24.637 INFO main sc_cli::runner: 💾 Database: RocksDb at /var/folders/s5/5gcp8ck95k39z006fj059_0c0000gn/T/substrateHZoRbb/chains/dev/db/full +"#; + let port = find_substrate_port_from_output(log.as_bytes()); + assert_eq!(port, 9944); + } } From 7c8b78ab932d6bbb943ccb8745e9ba50f16a852e Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Wed, 4 Dec 2024 11:11:22 +0100 Subject: [PATCH 2/2] Update changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 81ee9016b9..8d577f4a3e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Changed - Restrict which `cfg` attributes can be used ‒ [#2313](https://github.com/use-ink/ink/pull/2313) +## Fixed +- [E2E] Have port parsing handle comma-separated list ‒ [#2336](https://github.com/use-ink/ink/pull/2336) + ## Version 5.1.0 This is the first ink! release outside of Parity. ink! was started at Parity and