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
clippy
  • Loading branch information
liamaharon committed Aug 8, 2023
commit ff8d5f06929386f634cbbe60d0e2d2de6228d285
4 changes: 2 additions & 2 deletions core/src/commands/create_snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ where
command.from.at.clone().unwrap_or("latest".to_owned())
);
log::info!(target: LOG_TARGET, "snapshot path not provided (-s), using '{}'", path_str);
path_str.into()
path_str
}
};

let executor = build_executor::<HostFns>(&shared);
let _ = State::Live(command.from)
.into_ext::<Block, HostFns>(&shared, &executor, Some(path.into()), false)
.to_ext::<Block, HostFns>(&shared, &executor, Some(path.into()), false)
.await?;

Ok(())
Expand Down
11 changes: 4 additions & 7 deletions core/src/commands/execute_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,7 @@ pub struct Command {
}

impl Command {
fn block_ws_uri<Block: BlockT>(&self) -> String
where
<Block::Hash as FromStr>::Err: Debug,
{
fn block_ws_uri(&self) -> String {
match (&self.block_ws_uri, &self.state) {
(Some(block_ws_uri), State::Snap { .. }) => block_ws_uri.to_owned(),
(Some(block_ws_uri), State::Live { .. }) => {
Expand Down Expand Up @@ -100,11 +97,11 @@ where
let executor = build_executor::<HostFns>(&shared);
let ext = command
.state
.into_ext::<Block, HostFns>(&shared, &executor, None, true)
.to_ext::<Block, HostFns>(&shared, &executor, None, true)
.await?;

// get the block number associated with this block.
let block_ws_uri = command.block_ws_uri::<Block>();
let block_ws_uri = command.block_ws_uri();
let rpc = ws_client(&block_ws_uri).await?;
let next_hash = next_hash_of::<Block>(&rpc, ext.block_hash).await?;

Expand Down Expand Up @@ -136,7 +133,7 @@ where
)
.encode();

let _ = state_machine_call_with_proof::<Block, HostFns>(
let _ = state_machine_call_with_proof::<HostFns>(
&ext,
&executor,
"TryRuntime_execute_block",
Expand Down
10 changes: 5 additions & 5 deletions core/src/commands/follow_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ where
let block =
ChainApi::<(), Block::Hash, Block::Header, SignedBlock<Block>>::block(&rpc, Some(hash))
.await
.or_else(|e| {
.map_err(|e| {
if matches!(e, substrate_rpc_client::Error::ParseError(_)) {
log::error!(
target: LOG_TARGET,
Expand All @@ -118,7 +118,7 @@ where
block with an empty one."
);
}
Err(rpc_err_handler(e))
rpc_err_handler(e)
})?
.expect("if header exists, block should also exist.")
.block;
Expand All @@ -142,7 +142,7 @@ where
child_tree: true,
});
let ext = state
.into_ext::<Block, HostFns>(&shared, &executor, None, true)
.to_ext::<Block, HostFns>(&shared, &executor, None, true)
.await?;
maybe_state_ext = Some(ext);
}
Expand All @@ -151,7 +151,7 @@ where
.as_mut()
.expect("state_ext either existed or was just created");

let result = state_machine_call_with_proof::<Block, HostFns>(
let result = state_machine_call_with_proof::<HostFns>(
state_ext,
&executor,
"TryRuntime_execute_block",
Expand All @@ -167,7 +167,7 @@ where
shared
.export_proof
.as_ref()
.map(|path| path.as_path().join(&format!("{}.json", number))),
.map(|path| path.as_path().join(format!("{}.json", number))),
);

if let Err(why) = result {
Expand Down
11 changes: 4 additions & 7 deletions core/src/commands/offchain_worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,7 @@ pub struct Command {
}

impl Command {
fn header_ws_uri<Block: BlockT>(&self) -> String
where
<Block::Hash as FromStr>::Err: Debug,
{
fn header_ws_uri(&self) -> String {
match (&self.header_ws_uri, &self.state) {
(Some(header_ws_uri), State::Snap { .. }) => header_ws_uri.to_owned(),
(Some(header_ws_uri), State::Live { .. }) => {
Expand Down Expand Up @@ -81,10 +78,10 @@ where
// we first build the externalities with the remote code.
let ext = command
.state
.into_ext::<Block, HostFns>(&shared, &executor, None, true)
.to_ext::<Block, HostFns>(&shared, &executor, None, true)
.await?;

let header_ws_uri = command.header_ws_uri::<Block>();
let header_ws_uri = command.header_ws_uri();

let rpc = ws_client(&header_ws_uri).await?;
let next_hash = next_hash_of::<Block>(&rpc, ext.block_hash).await?;
Expand All @@ -96,7 +93,7 @@ where
.map(|maybe_header| maybe_header.ok_or("Header does not exist"))??;
let payload = header.encode();

let _ = state_machine_call::<Block, HostFns>(
let _ = state_machine_call::<HostFns>(
&ext,
&executor,
"OffchainWorkerApi_offchain_worker",
Expand Down
4 changes: 2 additions & 2 deletions core/src/commands/on_runtime_upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ where
let executor = build_executor(&shared);
let ext = command
.state
.into_ext::<Block, HostFns>(&shared, &executor, None, true)
.to_ext::<Block, HostFns>(&shared, &executor, None, true)
.await?;

let (_, encoded_result) = state_machine_call_with_proof::<Block, HostFns>(
let (_, encoded_result) = state_machine_call_with_proof::<HostFns>(
&ext,
&executor,
"TryRuntime_on_runtime_upgrade",
Expand Down
4 changes: 2 additions & 2 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ fn ensure_try_runtime<Block: BlockT, HostFns: HostFunctions>(

/// Execute the given `method` and `data` on top of `ext`, returning the results (encoded) and the
/// state `changes`.
pub(crate) fn state_machine_call<Block: BlockT, HostFns: HostFunctions>(
pub(crate) fn state_machine_call<HostFns: HostFunctions>(
ext: &TestExternalities,
executor: &WasmExecutor<HostFns>,
method: &'static str,
Expand Down Expand Up @@ -128,7 +128,7 @@ pub(crate) fn state_machine_call<Block: BlockT, HostFns: HostFunctions>(
/// size and formats.
///
/// Make sure [`LOG_TARGET`] is enabled in logging.
pub(crate) fn state_machine_call_with_proof<Block: BlockT, HostFns: HostFunctions>(
pub(crate) fn state_machine_call_with_proof<HostFns: HostFunctions>(
ext: &TestExternalities,
executor: &WasmExecutor<HostFns>,
method: &'static str,
Expand Down
2 changes: 1 addition & 1 deletion core/src/shared_parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl FromStr for Runtime {
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(match s.to_lowercase().as_ref() {
"existing" => Runtime::Existing,
x @ _ => Runtime::Path(x.into()),
x => Runtime::Path(x.into()),
})
}
}
8 changes: 3 additions & 5 deletions core/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl State {
///
/// This will override the code as it sees fit based on [`Runtime`]. It will also check the
/// spec-version and name.
pub(crate) async fn into_ext<Block: BlockT + DeserializeOwned, HostFns: HostFunctions>(
pub(crate) async fn to_ext<Block: BlockT + DeserializeOwned, HostFns: HostFunctions>(
&self,
shared: &SharedParams,
executor: &WasmExecutor<HostFns>,
Expand Down Expand Up @@ -203,10 +203,8 @@ impl State {
}

// whatever runtime we have in store now must have been compiled with try-runtime feature.
if try_runtime_check {
if !ensure_try_runtime::<Block, HostFns>(&executor, &mut ext) {
return Err("given runtime is NOT compiled with try-runtime feature!".into());
}
if try_runtime_check && !ensure_try_runtime::<Block, HostFns>(executor, &mut ext) {
return Err("given runtime is NOT compiled with try-runtime feature!".into());
}

Ok(ext)
Expand Down
10 changes: 5 additions & 5 deletions core/tests/create_snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,20 @@ async fn create_snapshot_works() {
.stdout(std::process::Stdio::piped())
.stderr(std::process::Stdio::piped())
.arg("--runtime=existing")
.args(&["create-snapshot", format!("--uri={}", ws_url).as_str()])
.args(["create-snapshot", format!("--uri={}", ws_url).as_str()])
.arg(snap_file)
.args(&["--at", format!("{:?}", at).as_str()])
.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();
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 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 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;
Expand Down
10 changes: 5 additions & 5 deletions core/tests/execute_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,19 @@ async fn execute_block_works() {
.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()])
.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();
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);
let mut block_execution = execute_block(ws_url, block_hash);

// The execute-block command is actually executing the next block.
let expected_output = format!(
Expand Down
6 changes: 3 additions & 3 deletions core/tests/follow_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ async fn follow_chain_works() {
.stdout(std::process::Stdio::piped())
.stderr(std::process::Stdio::piped())
.arg("--runtime=existing")
.args(&["follow-chain", format!("--uri={}", ws_url).as_str()])
.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 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;

Expand Down