Skip to content

Commit e29538c

Browse files
committed
Add Clap wrapper for enum UpgradeCheckSelect
Signed-off-by: Oliver Tale-Yazdi <[email protected]>
1 parent 1f9eb3a commit e29538c

File tree

2 files changed

+30
-24
lines changed

2 files changed

+30
-24
lines changed

frame/support/src/traits/try_runtime.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -106,21 +106,6 @@ impl UpgradeCheckSelect {
106106
}
107107
}
108108

109-
#[cfg(feature = "std")]
110-
impl core::str::FromStr for UpgradeCheckSelect {
111-
type Err = &'static str;
112-
113-
fn from_str(s: &str) -> Result<Self, Self::Err> {
114-
match s.to_lowercase().as_str() {
115-
"none" => Ok(Self::None),
116-
"all" => Ok(Self::All),
117-
"pre-and-post" => Ok(Self::PreAndPost),
118-
"try-state" => Ok(Self::TryState),
119-
_ => Err("Invalid CheckSelector"),
120-
}
121-
}
122-
}
123-
124109
/// Execute some checks to ensure the internal state of a pallet is consistent.
125110
///
126111
/// Usually, these checks should check all of the invariants that are expected to be held on all of

utils/frame/try-runtime/cli/src/commands/on_runtime_upgrade.rs

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
// limitations under the License.
1717

1818
use crate::{build_executor, state_machine_call_with_proof, SharedParams, State, LOG_TARGET};
19-
use frame_try_runtime::UpgradeCheckSelect;
2019
use parity_scale_codec::{Decode, Encode};
2120
use sc_executor::sp_wasm_interface::HostFunctions;
2221
use sp_runtime::traits::{Block as BlockT, NumberFor};
@@ -30,18 +29,39 @@ pub struct OnRuntimeUpgradeCmd {
3029
#[command(subcommand)]
3130
pub state: State,
3231

33-
/// Select which optional checks to perform:
34-
///
35-
/// - `all`: Perform all checks (default).
36-
/// - `pre-and-post`: Perform pre- and post-upgrade checks.
37-
/// - `try-state`: Perform the try-state checks.
38-
/// - `none`: Perform no checks.
32+
/// Select which optional checks to perform.
3933
///
4034
/// Performing any checks will potentially invalidate the measured PoV/Weight.
41-
#[clap(long, default_value = "All", verbatim_doc_comment)]
35+
#[clap(long, value_enum, default_value_t = UpgradeCheckSelect::All)]
4236
pub checks: UpgradeCheckSelect,
4337
}
4438

39+
/// This is an adapter for [`frame_try_runtime::UpgradeCheckSelect`] since that does not implement
40+
/// `clap::ValueEnum`.
41+
#[derive(clap::ValueEnum, Debug, Clone, Copy)]
42+
#[value(rename_all = "kebab-case")]
43+
pub enum UpgradeCheckSelect {
44+
/// Perform no checks.
45+
None,
46+
/// Perform all checks.
47+
All,
48+
/// Perform pre- and post-upgrade checks.
49+
PreAndPost,
50+
/// Perform the try-state checks.
51+
TryState,
52+
}
53+
54+
impl From<UpgradeCheckSelect> for frame_try_runtime::UpgradeCheckSelect {
55+
fn from(x: UpgradeCheckSelect) -> Self {
56+
match x {
57+
UpgradeCheckSelect::None => Self::None,
58+
UpgradeCheckSelect::All => Self::All,
59+
UpgradeCheckSelect::PreAndPost => Self::PreAndPost,
60+
UpgradeCheckSelect::TryState => Self::TryState,
61+
}
62+
}
63+
}
64+
4565
pub(crate) async fn on_runtime_upgrade<Block, HostFns>(
4666
shared: SharedParams,
4767
command: OnRuntimeUpgradeCmd,
@@ -57,12 +77,13 @@ where
5777
{
5878
let executor = build_executor(&shared);
5979
let ext = command.state.into_ext::<Block, HostFns>(&shared, &executor, None).await?;
80+
let checks: frame_try_runtime::UpgradeCheckSelect = command.checks.into();
6081

6182
let (_, encoded_result) = state_machine_call_with_proof::<Block, HostFns>(
6283
&ext,
6384
&executor,
6485
"TryRuntime_on_runtime_upgrade",
65-
command.checks.encode().as_ref(),
86+
checks.encode().as_ref(),
6687
Default::default(), // we don't really need any extensions here.
6788
shared.export_proof,
6889
)?;

0 commit comments

Comments
 (0)