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
Prev Previous commit
Next Next commit
write tests and tweak api
  • Loading branch information
liamaharon committed Nov 21, 2023
commit e40ce03721391f835431f6a64a8c7d0af0c3e61d
2 changes: 1 addition & 1 deletion core/src/commands/execute_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ where

// Get state for the prev block
let runtime_checks = RuntimeChecks {
name_matches: shared.check_spec_name,
name_matches: !shared.disable_spec_name_check,
version_increases: false,
try_runtime_feature_enabled: true,
};
Expand Down
2 changes: 1 addition & 1 deletion core/src/commands/fast_forward.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ where
{
let executor = build_executor::<HostFns>(&shared);
let runtime_checks = RuntimeChecks {
name_matches: shared.check_spec_name,
name_matches: !shared.disable_spec_name_check,
version_increases: false,
try_runtime_feature_enabled: true,
};
Expand Down
2 changes: 1 addition & 1 deletion core/src/commands/follow_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ where
hashed_prefixes: vec![],
});
let runtime_checks = RuntimeChecks {
name_matches: shared.check_spec_name,
name_matches: !shared.disable_spec_name_check,
version_increases: false,
try_runtime_feature_enabled: true,
};
Expand Down
2 changes: 1 addition & 1 deletion core/src/commands/offchain_worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ where
// Get state for the prev block
let prev_block_live_state = live_state.to_prev_block_live_state::<Block>().await?;
let runtime_checks = RuntimeChecks {
name_matches: shared.check_spec_name,
name_matches: !shared.disable_spec_name_check,
version_increases: false,
try_runtime_feature_enabled: true,
};
Expand Down
17 changes: 9 additions & 8 deletions core/src/commands/on_runtime_upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,14 @@ pub struct Command {
#[clap(long, default_value = "false", default_missing_value = "true")]
pub no_weight_warnings: bool,

/// Whether to enforce the new runtime `spec_version` is greater or equal to the existing
/// `spec_version`.
#[clap(long, default_value = "true", default_missing_value = "true")]
pub check_spec_version: bool,
/// Whether to skip enforcing that the new runtime `spec_version` is greater or equal to the
/// existing `spec_version`.
#[clap(long, default_value = "false", default_missing_value = "true")]
pub disable_spec_version_check: bool,

/// Whether to disable migration idempotency checks
#[clap(long, default_value = "false", default_missing_value = "true")]
pub no_idempotency_checks: bool,
pub disable_idempotency_checks: bool,
}

// Runs the `on-runtime-upgrade` command.
Expand All @@ -82,8 +83,8 @@ where
{
let executor = build_executor(&shared);
let runtime_checks = RuntimeChecks {
name_matches: shared.check_spec_name,
version_increases: command.check_spec_version,
name_matches: !shared.disable_spec_name_check,
version_increases: !command.disable_spec_version_check,
try_runtime_feature_enabled: true,
};
let ext = command
Expand Down Expand Up @@ -143,7 +144,7 @@ where
};

// Check idempotency
let idempotency_ok = match command.no_idempotency_checks {
let idempotency_ok = match command.disable_idempotency_checks {
true => {
log::info!("ℹ Skipping idempotency check");
true
Expand Down
6 changes: 3 additions & 3 deletions core/src/shared_parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ pub struct SharedParams {
#[arg(long, default_value = "existing")]
pub runtime: Runtime,

/// Whether to enforce the new runtime `spec_name` matches the existing `spec_name`.
#[clap(long, default_value = "true", default_missing_value = "true")]
pub check_spec_name: bool,
/// Whether to disable enforcing the new runtime `spec_name` matches the existing `spec_name`.
#[clap(long, default_value = "false", default_missing_value = "true")]
pub disable_spec_name_check: bool,

/// Type of wasm execution used.
#[arg(
Expand Down
14 changes: 8 additions & 6 deletions core/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ pub enum State {
}

/// Checks to perform on the given runtime, compared to the existing runtime.
#[derive(Debug)]
pub struct RuntimeChecks {
/// Enforce the `spec_name`s match
pub name_matches: bool,
Expand Down Expand Up @@ -305,18 +306,19 @@ impl State {
new_code_hash
);

dbg!(&runtime_checks);

if runtime_checks.name_matches && new_version.spec_name != old_version.spec_name {
return Err("Spec names must match.".into());
} else {
log::info!("Skipping spec name check.")
return Err(
"Spec names must match. Use `--disable-spec-name-check` to disable this check."
.into(),
);
}

if runtime_checks.version_increases
&& new_version.spec_version <= old_version.spec_version
{
return Err("New runtime spec version must be greater than the on-chain runtime spec version.".into());
} else {
log::info!("Skipping spec version check.")
return Err("New runtime spec version must be greater than the on-chain runtime spec version. Use `--disable-spec-version-check` to disable this check.".into());
}
}

Expand Down
101 changes: 92 additions & 9 deletions core/tests/on_runtime_upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,16 @@ mod on_runtime_upgrade {
fn on_runtime_upgrade(
snap_path: &str,
runtime_path: &str,
extra_args: &[&str],
command_extra_args: &[&str],
sub_command_extra_args: &[&str],
) -> tokio::process::Child {
Command::new(cargo_bin("try-runtime"))
.stdout(std::process::Stdio::piped())
.stderr(std::process::Stdio::piped())
.arg(format!("--runtime={}", runtime_path))
.args(command_extra_args)
.arg("on-runtime-upgrade")
.args(extra_args)
.args(sub_command_extra_args)
.args(["snap", format!("--path={}", snap_path).as_str()])
.kill_on_drop(true)
.spawn()
Expand All @@ -51,7 +53,7 @@ mod on_runtime_upgrade {
project_root
);
dbg!(&runtime_path, &snap_path);
let child = on_runtime_upgrade(snap_path.as_str(), runtime_path.as_str(), &[]);
let child = on_runtime_upgrade(snap_path.as_str(), runtime_path.as_str(), &[], &[]);
let out = child.wait_with_output().await.unwrap();
dbg!(&out);
assert!(out.status.success());
Expand All @@ -65,10 +67,10 @@ mod on_runtime_upgrade {
let project_root = env!("CARGO_MANIFEST_DIR");
let snap_path = format!("{}/tests/snaps/rococo-bridge-hub.snap", project_root);
let runtime_path = format!(
"{}/tests/runtimes/bridge_hub_rococo_runtime_WEIGHT_ISSUE.compact.compressed.wasm",
"{}/tests/runtimes/bridge_hub_rococo_runtime_weight_issue.compact.compressed.wasm",
project_root
);
let child = on_runtime_upgrade(snap_path.as_str(), runtime_path.as_str(), &[]);
let child = on_runtime_upgrade(snap_path.as_str(), runtime_path.as_str(), &[], &[]);
let out = child.wait_with_output().await.unwrap();
assert!(!out.status.success());
})
Expand All @@ -88,6 +90,7 @@ mod on_runtime_upgrade {
let child = on_runtime_upgrade(
snap_path.as_str(),
runtime_path.as_str(),
&[],
&["--no-weight-warnings"],
);
let out = child.wait_with_output().await.unwrap();
Expand All @@ -106,7 +109,7 @@ mod on_runtime_upgrade {
project_root
);

let child = on_runtime_upgrade(snap_path.as_str(), runtime_path.as_str(), &[]);
let child = on_runtime_upgrade(snap_path.as_str(), runtime_path.as_str(), &[], &[]);
let out = child.wait_with_output().await.unwrap();
assert!(!out.status.success());
})
Expand All @@ -126,7 +129,8 @@ mod on_runtime_upgrade {
let child = on_runtime_upgrade(
snap_path.as_str(),
runtime_path.as_str(),
&["--no-idempotency-checks"],
&[],
&["--disable-idempotency-checks"],
);
let out = child.wait_with_output().await.unwrap();
assert!(out.status.success());
Expand All @@ -144,7 +148,7 @@ mod on_runtime_upgrade {
project_root
);

let child = on_runtime_upgrade(snap_path.as_str(), runtime_path.as_str(), &[]);
let child = on_runtime_upgrade(snap_path.as_str(), runtime_path.as_str(), &[], &[]);
let out = child.wait_with_output().await.unwrap();
assert!(!out.status.success());
})
Expand All @@ -163,11 +167,90 @@ mod on_runtime_upgrade {
let child = on_runtime_upgrade(
snap_path.as_str(),
runtime_path.as_str(),
&["--no-idempotency-checks"],
&[],
&["--disable-idempotency-checks"],
);
let out = child.wait_with_output().await.unwrap();
assert!(out.status.success());
})
.await;
}

#[tokio::test]
async fn non_matching_spec_name_fails() {
common::run_with_timeout(Duration::from_secs(300), async move {
let project_root = env!("CARGO_MANIFEST_DIR");
let snap_path = format!("{}/tests/snaps/rococo-bridge-hub.snap", project_root);
let runtime_path = format!(
"{}/tests/runtimes/bridge_hub_rococo_runtime_bad_spec_name.compact.compressed.wasm",
project_root
);

let child = on_runtime_upgrade(snap_path.as_str(), runtime_path.as_str(), &[], &[]);
let out = child.wait_with_output().await.unwrap();
assert!(!out.status.success());
})
.await;
}

#[tokio::test]
async fn non_matching_spec_name_can_be_ignored() {
common::run_with_timeout(Duration::from_secs(300), async move {
let project_root = env!("CARGO_MANIFEST_DIR");
let snap_path = format!("{}/tests/snaps/rococo-bridge-hub.snap", project_root);
let runtime_path = format!(
"{}/tests/runtimes/bridge_hub_rococo_runtime_bad_spec_name.compact.compressed.wasm",
project_root
);
let child = on_runtime_upgrade(
snap_path.as_str(),
runtime_path.as_str(),
&["--disable-spec-name-check"],
&[],
);
let out = child.wait_with_output().await.unwrap();
dbg!(&out);
assert!(out.status.success());
})
.await;
}

#[tokio::test]
async fn non_incrementing_spec_version_fails() {
common::run_with_timeout(Duration::from_secs(300), async move {
let project_root = env!("CARGO_MANIFEST_DIR");
let snap_path = format!("{}/tests/snaps/rococo-bridge-hub.snap", project_root);
let runtime_path = format!(
"{}/tests/runtimes/bridge_hub_rococo_runtime_non_incrementing_spec_version.compact.compressed.wasm",
project_root
);

let child = on_runtime_upgrade(snap_path.as_str(), runtime_path.as_str(), &[], &[]);
let out = child.wait_with_output().await.unwrap();
assert!(!out.status.success());
})
.await;
}

#[tokio::test]
async fn non_incrementing_spec_version_can_be_ignored() {
common::run_with_timeout(Duration::from_secs(300), async move {
let project_root = env!("CARGO_MANIFEST_DIR");
let snap_path = format!("{}/tests/snaps/rococo-bridge-hub.snap", project_root);
let runtime_path = format!(
"{}/tests/runtimes/bridge_hub_rococo_runtime_non_incrementing_spec_version.compact.compressed.wasm",
project_root
);
let child = on_runtime_upgrade(
snap_path.as_str(),
runtime_path.as_str(),
&[],
&["--disable-spec-version-check"],
);
let out = child.wait_with_output().await.unwrap();
dbg!(&out);
assert!(out.status.success());
})
.await;
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified core/tests/snaps/rococo-bridge-hub.snap
Binary file not shown.