Skip to content

Commit

Permalink
Fix port passing from node process (#2336)
Browse files Browse the repository at this point in the history
* Have port parsing handle comma-separated list

* Update changelog
  • Loading branch information
cmichi authored Dec 4, 2024
1 parent 67cc07a commit 92a62a7
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -37,7 +40,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:
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/e2e/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
34 changes: 32 additions & 2 deletions crates/e2e/src/node_proc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 92a62a7

Please sign in to comment.