Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[E2E] Allow testing with live-chain state #1949

Merged
merged 17 commits into from
Nov 16, 2023
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added
- [E2E] Allow testing with live-chain state - [#1949](https://github.com/paritytech/ink/pull/1949)
- [E2E] Call builders and extra gas margin option - [#1917](https://github.com/paritytech/ink/pull/1917)
- Make `set_code_hash` generic - [#1906](https://github.com/paritytech/ink/pull/1906)
- Clean E2E configuration parsing - [#1922](https://github.com/paritytech/ink/pull/1922)
Expand Down
1 change: 1 addition & 0 deletions crates/e2e/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ scale-info = { workspace = true, features = ["derive"] }
[features]
default = ["std"]
std = []
live-state-test = ["subxt/unstable-light-client"]
drink = [
"dep:drink",
"subxt-metadata",
Expand Down
27 changes: 15 additions & 12 deletions crates/e2e/src/node_proc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,20 @@ where
e
)
})?;

// Wait for RPC port to be logged (it's logged to stderr):
let stderr = proc.stderr.take().unwrap();
let port = find_substrate_port_from_output(stderr);
let url = format!("ws://127.0.0.1:{port}");
// Wait for RPC port to be logged (it's logged to stderr):
let port_str: String = match option_env!("WS_PORT") {
ascjones marked this conversation as resolved.
Show resolved Hide resolved
Some(v) => v.to_string(),
None => {
// expect to have a number here (the chars after '127.0.0.1:').
find_substrate_port_from_output(stderr)
}
};

let ws_port: u16 = port_str
.parse()
.unwrap_or_else(|_| panic!("valid port number expected, got '{port_str}'"));
let url = format!("ws://127.0.0.1:{ws_port}");

// Connect to the node with a `subxt` client:
let rpc = RpcClient::from_url(url.clone())
Expand Down Expand Up @@ -195,7 +204,7 @@ where

// Consume a stderr reader from a spawned substrate command and
// locate the port number that is logged out to it.
fn find_substrate_port_from_output(r: impl Read + Send + 'static) -> u16 {
fn find_substrate_port_from_output(r: impl Read + Send + 'static) -> String {
BufReader::new(r)
.lines()
.find_map(|line| {
Expand All @@ -215,13 +224,7 @@ fn find_substrate_port_from_output(r: impl Read + Send + 'static) -> u16 {
// 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());

// expect to have a number here (the chars after '127.0.0.1:') and parse them
// into a u16.
let port_num = port_str.parse().unwrap_or_else(|_| {
panic!("valid port expected for tracing line, got '{port_str}'")
});

Some(port_num)
Some(port_str.to_string())
})
.expect("We should find a port before the reader ends")
}
Expand Down
3 changes: 1 addition & 2 deletions integration-tests/e2e-call-runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ publish = false
ink = { path = "../../crates/ink", default-features = false }

[dev-dependencies]
ink_e2e = { path = "../../crates/e2e" }
subxt = { version = "0.32.1", default-features = false }
ink_e2e = { path = "../../crates/e2e", features = ["live-state-test"]}

[lib]
path = "lib.rs"
Expand Down