Skip to content

Commit

Permalink
Fix error type in try-runtime code
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrylavrenov committed Nov 4, 2024
1 parent 38cd651 commit 4638b9c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 21 deletions.
12 changes: 5 additions & 7 deletions crates/pallet-dummy-precompiles-code/src/upgrade_init.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//! Upgrade init implementation.

#[cfg(feature = "try-runtime")]
use frame_support::{sp_runtime::TryRuntimeError, sp_std::vec::Vec, traits::GetStorageVersion};
use frame_support::{
sp_std,
sp_tracing::info,
traits::{Get, OnRuntimeUpgrade},
weights::Weight,
};
#[cfg(feature = "try-runtime")]
use frame_support::{sp_std::vec::Vec, traits::GetStorageVersion};

use crate::{
Config, LastExecutionVersion, LastForceExecuteAskCounter, Pallet, CURRENT_EXECUTION_VERSION,
Expand Down Expand Up @@ -41,13 +41,13 @@ impl<T: Config> OnRuntimeUpgrade for UpgradeInit<T> {
}

#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, TryRuntimeError> {
fn pre_upgrade() -> Result<Vec<u8>, &'static str> {
// Do nothing.
Ok(Vec::new())
}

#[cfg(feature = "try-runtime")]
fn post_upgrade(_state: Vec<u8>) -> Result<(), TryRuntimeError> {
fn post_upgrade(_state: Vec<u8>) -> Result<(), &'static str> {
use crate::DUMMY_CODE;

let mut not_created_precompiles = Vec::new();
Expand All @@ -60,9 +60,7 @@ impl<T: Config> OnRuntimeUpgrade for UpgradeInit<T> {
}

if !not_created_precompiles.is_empty() {
return Err(TryRuntimeError::Other(
"precompiles not created properly: {:not_created_precompiles}",
));
return Err("precompiles not created properly: {:not_created_precompiles}");
}

assert_eq!(
Expand Down
11 changes: 4 additions & 7 deletions crates/pallet-erc20-support/src/migrations/v1.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
//! Migration to Version 1.

#[cfg(feature = "try-runtime")]
use frame_support::sp_std::{vec, vec::Vec};
use frame_support::{
pallet_prelude::*,
sp_std,
sp_tracing::info,
traits::{Get, OnRuntimeUpgrade},
weights::Weight,
};
#[cfg(feature = "try-runtime")]
use frame_support::{
sp_runtime::TryRuntimeError,
sp_std::{vec, vec::Vec},
};

use crate::{Approvals, BalanceOf, Config, Pallet};

Expand All @@ -24,12 +21,12 @@ impl<T: Config<I>, I: 'static> OnRuntimeUpgrade for MigrationToV1<T, I> {
}

#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, TryRuntimeError> {
fn pre_upgrade() -> Result<Vec<u8>, &'static str> {
Ok(vec![])
}

#[cfg(feature = "try-runtime")]
fn post_upgrade(_state: Vec<u8>) -> Result<(), TryRuntimeError> {
fn post_upgrade(_state: Vec<u8>) -> Result<(), &'static str> {
ensure!(
<Pallet<T, I>>::on_chain_storage_version() == <Pallet<T, I>>::current_storage_version(),
"the current storage version and onchain storage version should be the same"
Expand Down
11 changes: 4 additions & 7 deletions crates/pallet-humanode-session/src/migrations/v1.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Migration to Version 1.

#[cfg(feature = "try-runtime")]
use frame_support::sp_std::{vec, vec::Vec};
use frame_support::{
pallet_prelude::*,
sp_std,
Expand All @@ -8,11 +10,6 @@ use frame_support::{
traits::{Get, OnRuntimeUpgrade},
weights::Weight,
};
#[cfg(feature = "try-runtime")]
use frame_support::{
sp_runtime::TryRuntimeError,
sp_std::{vec, vec::Vec},
};

use crate::{Config, CurrentSessionIndex, IdentificationFor, Pallet, SessionIdentities};

Expand All @@ -25,12 +22,12 @@ impl<T: Config> OnRuntimeUpgrade for MigrationToV1<T> {
}

#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, TryRuntimeError> {
fn pre_upgrade() -> Result<Vec<u8>, &'static str> {
Ok(pre_migrate::<T>())
}

#[cfg(feature = "try-runtime")]
fn post_upgrade(state: Vec<u8>) -> Result<(), TryRuntimeError> {
fn post_upgrade(state: Vec<u8>) -> Result<(), &'static str> {
post_migrate::<T>(state);
Ok(())
}
Expand Down

0 comments on commit 4638b9c

Please sign in to comment.