Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
80b0d94
work with latest substrate
liamaharon Aug 3, 2023
2b85c22
sync code with latest substrate
liamaharon Aug 3, 2023
722902f
remove sc_cli shared params
liamaharon Aug 3, 2023
28d9dd0
fix comment
liamaharon Aug 3, 2023
0aaac86
add missing stable commands
liamaharon Aug 3, 2023
e55ea4d
migrate tests
liamaharon Aug 7, 2023
552655b
test rust docs action
liamaharon Aug 7, 2023
13e1bdc
install protoc
liamaharon Aug 7, 2023
ac51c96
add rusttoolchain
liamaharon Aug 7, 2023
17a1f87
remove rust-toolchain
liamaharon Aug 7, 2023
9ec0873
add licence
liamaharon Aug 7, 2023
d2b13ef
lint
liamaharon Aug 7, 2023
cfda821
add toolchain
liamaharon Aug 7, 2023
0061269
try to fix github actions build
liamaharon Aug 7, 2023
afd1fb7
docs
liamaharon Aug 7, 2023
ff8d5f0
clippy
liamaharon Aug 8, 2023
0955e4d
update homepage
liamaharon Aug 8, 2023
ba66524
update cargo.lock
liamaharon Aug 8, 2023
64c8f61
tweak docs
liamaharon Aug 8, 2023
4d08d01
fix no deps arg
liamaharon Aug 8, 2023
8055e80
update readme
liamaharon Aug 8, 2023
1d14feb
update docs
liamaharon Aug 8, 2023
198e164
rust docs workflow
liamaharon Aug 8, 2023
7be1543
update descriptions
liamaharon Aug 8, 2023
dddd24a
fix docs link
liamaharon Aug 8, 2023
523dfa2
improve docs
liamaharon Aug 8, 2023
e80051f
typo
liamaharon Aug 8, 2023
549278a
update tests
liamaharon Aug 8, 2023
503ebeb
prepare for merging
liamaharon Aug 8, 2023
81ec69d
use latest substrate in tests
liamaharon Aug 8, 2023
0ba460e
try fix test ci
liamaharon Aug 9, 2023
a519be5
disable ci tests
liamaharon Aug 9, 2023
fd89392
update readme
liamaharon Aug 9, 2023
8746e55
update readme
liamaharon Aug 9, 2023
77cb19f
remove -cli suffix from binary
liamaharon Aug 10, 2023
347c0b2
update tests
liamaharon Aug 10, 2023
e47ffcd
use resolver = 2
liamaharon Aug 10, 2023
2119508
set default runtime value
liamaharon Aug 10, 2023
affc4c8
remove redundant comment
liamaharon Aug 15, 2023
6d27cb1
test removing rust toolchain from rust-docs.yaml
liamaharon Aug 15, 2023
79ec8e8
minor doc improvement
liamaharon Aug 15, 2023
1749cab
try stable toolchain
liamaharon Aug 15, 2023
27c82fc
organise deps
liamaharon Aug 15, 2023
ef307f7
update description
liamaharon Aug 15, 2023
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
Prev Previous commit
Next Next commit
migrate tests
  • Loading branch information
liamaharon committed Aug 7, 2023
commit e55ea4d0b892a580d72f490f0b341d845c172f8a
15 changes: 12 additions & 3 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,16 @@ sp-weights = { git = "https://github.com/paritytech/substrate", branch = "master

substrate-rpc-client = { git = "https://github.com/paritytech/substrate", branch = "master" }

[dev-dependencies]
sc-service = { git = "https://github.com/paritytech/substrate", branch = "master" }
assert_cmd = "2.0.10"
regex = "1.7.3"
tempfile = "3.1.0"
tokio = "1.27.0"
node-primitives = { git = "https://github.com/paritytech/substrate", branch = "master" }
substrate-cli-test-utils = { git = "https://github.com/paritytech/substrate", branch = "master" }
node-template = { git = "https://github.com/paritytech/substrate", branch = "master", features = ["try-runtime"] }
node-executor = { git = "https://github.com/paritytech/substrate", branch = "master" }

[features]
cli = [
"clap",
]
cli = ["clap"]
4 changes: 2 additions & 2 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ use crate::shared_parameters::SharedParams;
pub mod commands;
#[cfg(feature = "cli")]
mod parse;
mod shared_parameters;
mod state;
pub mod shared_parameters;
pub mod state;

pub(crate) const LOG_TARGET: &str = "try-runtime::cli";

Expand Down
79 changes: 79 additions & 0 deletions core/tests/create_snapshot.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#![cfg(unix)]

use std::{
path::{Path, PathBuf},
time::Duration,
};

use assert_cmd::cargo::cargo_bin;
use frame_remote_externalities::{Builder, Mode, OfflineConfig, SnapshotConfig};
use node_primitives::{Block, Hash};
use regex::Regex;
use substrate_cli_test_utils as common;
use tokio::process::Command;

#[tokio::test]
async fn create_snapshot_works() {
let ws_url = "ws://localhost:45789";

// Spawn a dev node.
let _ = std::thread::spawn(move || {
common::start_node_without_binary();
});
// Wait 30 seconds to ensure the node is warmed up.
std::thread::sleep(Duration::from_secs(30));

// Run the command with tokio
let temp_dir = tempfile::Builder::new()
.prefix("try-runtime-cli-test-dir")
.tempdir()
.expect("Failed to create a tempdir");
let snap_file_path = temp_dir.path().join("snapshot.snap");

common::run_with_timeout(Duration::from_secs(60), async move {
fn create_snapshot(ws_url: &str, snap_file: &PathBuf, at: Hash) -> tokio::process::Child {
Command::new(cargo_bin("try-runtime-cli"))
.stdout(std::process::Stdio::piped())
.stderr(std::process::Stdio::piped())
.arg("--runtime=existing")
.args(&["create-snapshot", format!("--uri={}", ws_url).as_str()])
.arg(snap_file)
.args(&["--at", format!("{:?}", at).as_str()])
.kill_on_drop(true)
.spawn()
.unwrap()
}
let block_number = 2;
let block_hash = common::block_hash(block_number, &ws_url).await.unwrap();

// Try to create a snapshot.
let mut snapshot_creation = create_snapshot(&ws_url, &snap_file_path, block_hash);

let re = Regex::new(r#".*writing snapshot of (\d+) bytes to .*"#).unwrap();
let matched =
common::wait_for_stream_pattern_match(snapshot_creation.stderr.take().unwrap(), re)
.await;

// Assert that the snapshot creation succeded.
assert!(matched.is_ok(), "Failed to create snapshot");

let snapshot_is_on_disk = Path::new(&snap_file_path).exists();
assert!(snapshot_is_on_disk, "Snapshot was not written to disk");

// Try and load the snapshot we have created by running `create-snapshot`.
let snapshot_loading_result = Builder::<Block>::new()
.mode(Mode::Offline(OfflineConfig {
state_snapshot: SnapshotConfig {
path: snap_file_path,
},
}))
.build()
.await;

assert!(
snapshot_loading_result.is_ok(),
"Snapshot couldn't be loaded"
);
})
.await;
}
55 changes: 55 additions & 0 deletions core/tests/execute_block.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#![cfg(unix)]

use std::time::Duration;

use assert_cmd::cargo::cargo_bin;
use node_primitives::Hash;
use regex::Regex;
use substrate_cli_test_utils as common;
use tokio::process::Command;

#[tokio::test]
async fn execute_block_works() {
let ws_url = "ws://localhost:45789";

// Spawn a dev node.
let _ = std::thread::spawn(move || {
common::start_node_without_binary();
});
// Wait 30 seconds to ensure the node is warmed up.
std::thread::sleep(Duration::from_secs(30));

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

let block_number = 1;
let block_hash = common::block_hash(block_number, &ws_url).await.unwrap();

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

// The execute-block command is actually executing the next block.
let expected_output = format!(
r#".*Block #{} successfully executed"#,
block_number.saturating_add(1)
);
let re = Regex::new(expected_output.as_str()).unwrap();
let matched =
common::wait_for_stream_pattern_match(block_execution.stderr.take().unwrap(), re).await;

// Assert that the block-execution process has executed a block.
assert!(matched.is_ok());
})
.await
}
43 changes: 43 additions & 0 deletions core/tests/follow_chain.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#![cfg(unix)]

use std::time::Duration;

use assert_cmd::cargo::cargo_bin;
use regex::Regex;
use substrate_cli_test_utils as common;
use tokio::process::Command;

#[tokio::test]
async fn follow_chain_works() {
let ws_url = "ws://localhost:45789";

// Spawn a dev node.
let _ = std::thread::spawn(move || {
common::start_node_without_binary();
});
// Wait 30 seconds to ensure the node is warmed up.
std::thread::sleep(Duration::from_secs(30));

common::run_with_timeout(Duration::from_secs(60), async move {
fn start_follow(ws_url: &str) -> tokio::process::Child {
Command::new(cargo_bin("try-runtime-cli"))
.stdout(std::process::Stdio::piped())
.stderr(std::process::Stdio::piped())
.arg("--runtime=existing")
.args(&["follow-chain", format!("--uri={}", ws_url).as_str()])
.kill_on_drop(true)
.spawn()
.unwrap()
}

// Kick off the follow-chain process and wait for it to process at least 3 blocks.
let mut follow = start_follow(&ws_url);
let re = Regex::new(r#".*executed block ([3-9]|[1-9]\d+).*"#).unwrap();
let matched =
common::wait_for_stream_pattern_match(follow.stderr.take().unwrap(), re).await;

// Assert that the follow-chain process has followed at least 3 blocks.
assert!(matched.is_ok());
})
.await
}