Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix none at
  • Loading branch information
liamaharon committed Apr 29, 2024
commit 7910de3b925dd5314f7765db03d4ae663d45ccdb
22 changes: 21 additions & 1 deletion core/src/commands/execute_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,27 @@ where
let rpc = ws_client(&block_ws_uri).await?;

let live_state = match command.state {
State::Live(live_state) => live_state,
State::Live(live_state) => {
// If no --at is provided, get the latest block to replay
if let Some(_) = live_state.at {
live_state
} else {
let header =
ChainApi::<(), Block::Hash, Block::Header, SignedBlock<Block>>::header(
&rpc, None,
)
.await
.map_err(rpc_err_handler)?
.expect("header exists, block should also exist; qed");
LiveState {
uri: block_ws_uri,
at: Some(hex::encode(header.hash().encode())),
pallet: Default::default(),
hashed_prefixes: Default::default(),
child_tree: Default::default(),
}
}
}
_ => {
unreachable!("execute block currently only supports Live state")
}
Expand Down
42 changes: 41 additions & 1 deletion core/tests/execute_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ use tokio::process::Command;
#[tokio::test]
async fn execute_block_works() {
let port = 45789;
let ws_url = format!("ws://localhost:{}", port);

// Spawn a dev node.
let _ = std::thread::spawn(move || {
Expand All @@ -46,7 +45,10 @@ async fn execute_block_works() {
// Wait some time to ensure the node is warmed up.
std::thread::sleep(Duration::from_secs(90));

// Test passing --at
common::run_with_timeout(Duration::from_secs(60), async move {
let ws_url = format!("ws://localhost:{}", port);

fn execute_block(ws_url: &str, at: Hash) -> tokio::process::Child {
Command::new(cargo_bin("try-runtime"))
.stdout(std::process::Stdio::piped())
Expand Down Expand Up @@ -83,5 +85,43 @@ async fn execute_block_works() {
.status
.success());
})
.await;

// Test not passing --at
common::run_with_timeout(Duration::from_secs(60), async move {
let ws_url = format!("ws://localhost:{}", port);

fn execute_block(ws_url: &str) -> tokio::process::Child {
Command::new(cargo_bin("try-runtime"))
.stdout(std::process::Stdio::piped())
.stderr(std::process::Stdio::piped())
.arg("--runtime=existing")
.args(["execute-block"])
.args(["live", format!("--uri={}", ws_url).as_str()])
.kill_on_drop(true)
.spawn()
.unwrap()
}

// Try to execute the block.
let mut block_execution = execute_block(&ws_url);

// The execute-block command is actually executing the next block.
let expected_output = r".*Block #(\d+) successfully executed";
let re = Regex::new(expected_output).unwrap();
let matched =
common::wait_for_stream_pattern_match(block_execution.stderr.take().unwrap(), re).await;

// Assert that the block-execution process has executed the expected block.
assert!(matched.is_ok());

// Assert that the block-execution exited succesfully
assert!(block_execution
.wait_with_output()
.await
.unwrap()
.status
.success());
})
.await
}