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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
- Stabilize `call_runtime` ‒ [#1749](https://github.com/paritytech/ink/pull/1749)

### Added
- [E2E] Allow testing with live-chain state - [#1949](https://github.com/paritytech/ink/pull/1949)
- Stabilize `call_runtime` ‒ [#1749](https://github.com/paritytech/ink/pull/1749)
- Schema generation - [#1765](https://github.com/paritytech/ink/pull/1765)
- Add `set_block_number` to off-chain test api `Engine` - [#1806](https://github.com/paritytech/ink/pull/1806)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was it intentional to add all those unrelated ones here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, just a mistake during merge


Expand Down
1 change: 1 addition & 0 deletions crates/e2e/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ scale-info = { workspace = true, features = ["derive"] }
[features]
default = ["std"]
std = []
live-state-test = ["subxt/unstable-light-client"]
30 changes: 15 additions & 15 deletions crates/e2e/src/node_proc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,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 client = OnlineClient::from_url(url.clone()).await;
Expand All @@ -150,9 +159,6 @@ where
Err(err) => {
let err = format!("Failed to connect to node rpc at {url}: {err}");
tracing::error!("{}", err);
proc.kill().map_err(|e| {
format!("Error killing substrate process '{}': {}", proc.id(), e)
})?;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accidental removal?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep

Err(err)
}
}
Expand All @@ -161,7 +167,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 @@ -181,13 +187,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 @@ -12,8 +12,7 @@ scale = { package = "parity-scale-codec", version = "3", default-features = fals
scale-info = { version = "2.6", default-features = false, features = ["derive"], optional = true }

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

[lib]
path = "lib.rs"
Expand Down
7 changes: 6 additions & 1 deletion integration-tests/e2e-call-runtime/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@ pub mod e2e_call_runtime {

// Send funds from Alice to the contract using Balances::transfer
client
.runtime_call(&ink_e2e::alice(), "Balances", "transfer", call_data)
.runtime_call(
&ink_e2e::alice(),
"Balances",
"transfer_keep_alive",
call_data,
)
.await
.expect("runtime call failed");

Expand Down