Skip to content

Commit

Permalink
Fix build errors with runtime-benchmarks feature enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
Cem Eliguzel committed Sep 20, 2023
1 parent 966ec12 commit 03f4c34
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 31 deletions.
5 changes: 3 additions & 2 deletions pallets/author-mapping/src/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,11 @@ mod tests {
use crate::mock::Runtime;
use frame_support::assert_ok;
use sp_io::TestExternalities;
use sp_runtime::BuildStorage;

pub fn new_test_ext() -> TestExternalities {
let t = frame_system::GenesisConfig::default()
.build_storage::<Runtime>()
let t = frame_system::GenesisConfig::<Runtime>::default()
.build_storage()
.unwrap();
TestExternalities::new(t)
}
Expand Down
5 changes: 3 additions & 2 deletions pallets/author-slot-filter/src/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ benchmarks! {
mod tests {
use crate::tests::Test;
use sp_io::TestExternalities;
use sp_runtime::BuildStorage;

pub fn new_test_ext() -> TestExternalities {
let t = frame_system::GenesisConfig::default()
.build_storage::<Test>()
let t = frame_system::GenesisConfig::<Test>::default()
.build_storage()
.unwrap();
TestExternalities::new(t)
}
Expand Down
9 changes: 3 additions & 6 deletions pallets/author-slot-filter/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,15 @@ use frame_support::traits::ConstU32;
use frame_support::weights::RuntimeDbWeight;
use frame_support_test::TestRandomness;
use sp_core::H256;
use sp_runtime::{
traits::{BlakeTwo256, IdentityLookup},
BuildStorage,
};
use sp_runtime::{traits::{BlakeTwo256, IdentityLookup}, BuildStorage};

type Block = frame_system::mocking::MockBlock<Test>;

frame_support::construct_runtime!(
pub enum Test
{
System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>},
AuthorSlotFilter: pallet_testing::{Pallet, Call, Storage, Event},
System: frame_system,
AuthorSlotFilter: pallet_testing,
}
);

Expand Down
5 changes: 3 additions & 2 deletions pallets/author-slot-filter/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
// along with Moonkit. If not, see <http://www.gnu.org/licenses/>.

use super::*;
use crate::mock::*;
pub use crate::mock::*;
use crate::num::NonZeroU32;

use frame_support::assert_ok;
use frame_support::{traits::OnRuntimeUpgrade, weights::Weight};
use frame_support::traits::OnRuntimeUpgrade;
use frame_support::weights::Weight;
use sp_runtime::Percent;

#[test]
Expand Down
22 changes: 11 additions & 11 deletions pallets/migrations/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ pub struct MockMigrationManager<'test> {
name_fn_callbacks: Vec<Box<dyn 'test + FnMut() -> &'static str>>,
migrate_fn_callbacks: Vec<Box<dyn 'test + FnMut(Weight) -> Weight>>,
pre_upgrade_fn_callbacks:
Vec<Box<dyn 'test + FnMut() -> Result<(), sp_runtime::DispatchError>>>,
Vec<Box<dyn 'test + FnMut() -> Result<Vec<u8>, sp_runtime::DispatchError>>>,
post_upgrade_fn_callbacks:
Vec<Box<dyn 'test + FnMut() -> Result<(), sp_runtime::DispatchError>>>,
}
Expand All @@ -170,7 +170,7 @@ impl<'test> MockMigrationManager<'test> {
{
self.name_fn_callbacks.push(Box::new(name_fn));
self.migrate_fn_callbacks.push(Box::new(migrate_fn));
self.pre_upgrade_fn_callbacks.push(Box::new(|| Ok(())));
self.pre_upgrade_fn_callbacks.push(Box::new(|| Ok(Vec::new())));
self.post_upgrade_fn_callbacks.push(Box::new(|| Ok(())));
}
#[cfg(feature = "try-runtime")]
Expand All @@ -183,9 +183,9 @@ impl<'test> MockMigrationManager<'test> {
) where
FN: 'test + FnMut() -> &'static str,
FM: 'test + FnMut(Weight) -> Weight,
FT1: 'test + FnMut() -> Result<(), &'static str>,
FT1: 'test + FnMut() -> Result<Vec<u8>, sp_runtime::DispatchError>,
// no two closures, even if identical, have the same type
FT2: 'test + FnMut() -> Result<(), &'static str>,
FT2: 'test + FnMut() -> Result<(), sp_runtime::DispatchError>,
{
self.name_fn_callbacks.push(Box::new(name_fn));
self.migrate_fn_callbacks.push(Box::new(migrate_fn));
Expand All @@ -206,7 +206,7 @@ impl<'test> MockMigrationManager<'test> {
pub(crate) fn invoke_pre_upgrade(
&mut self,
index: usize,
) -> Result<(), sp_runtime::DispatchError> {
) -> Result<Vec<u8>, sp_runtime::DispatchError> {
self.pre_upgrade_fn_callbacks[index]()
}

Expand Down Expand Up @@ -272,16 +272,16 @@ impl Migration for MockMigration {
result
}
#[cfg(feature = "try-runtime")]
fn pre_upgrade(&self) -> Result<(), sp_runtime::DispatchError> {
let mut result: Result<(), &'static str> = Err("closure didn't set result");
fn pre_upgrade(&self) -> Result<Vec<u8>, sp_runtime::DispatchError> {
let mut result = Ok(vec![]);
MOCK_MIGRATIONS_LIST::with(|mgr: &mut MockMigrationManager| {
result = mgr.invoke_pre_upgrade(self.index);
});
result
}
#[cfg(feature = "try-runtime")]
fn post_upgrade(&self) -> Result<(), sp_runtime::DispatchError> {
let mut result: Result<(), &'static str> = Err("closure didn't set result");
fn post_upgrade(&self, _state: Vec<u8>) -> Result<(), sp_runtime::DispatchError> {
let mut result = Ok(());
MOCK_MIGRATIONS_LIST::with(|mgr: &mut MockMigrationManager| {
result = mgr.invoke_post_upgrade(self.index);
});
Expand Down Expand Up @@ -370,9 +370,9 @@ pub(crate) fn events() -> Vec<pallet_migrations::Event<Runtime>> {

#[cfg(feature = "try-runtime")]
pub(crate) fn invoke_all_upgrade_hooks() -> Weight {
Migrations::pre_upgrade().expect("pre-upgrade hook succeeds");
let val = Migrations::pre_upgrade().expect("pre-upgrade hook succeeds");
let weight = Migrations::on_runtime_upgrade();
Migrations::post_upgrade().expect("post-upgrade hook succeeds");
Migrations::post_upgrade(val).expect("post-upgrade hook succeeds");

weight
}
Expand Down
6 changes: 3 additions & 3 deletions pallets/migrations/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,11 +301,11 @@ fn try_runtime_functions_work() {
mgr.register_callback_with_try_fns(
move || "dummy_step",
move |_| -> Weight { 0u64.into() },
move || -> Result<(), &'static str> {
move || -> Result<Vec<u8>, sp_runtime::DispatchError> {
*pre_fn_called.lock().unwrap() = true;
Ok(())
Ok(vec![])
},
move || -> Result<(), &'static str> {
move || -> Result<(), sp_runtime::DispatchError> {
*post_fn_called.lock().unwrap() = true;
Ok(())
},
Expand Down
5 changes: 3 additions & 2 deletions pallets/randomness/src/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,11 @@ benchmarks! {
mod tests {
use crate::mock::Test;
use sp_io::TestExternalities;
use sp_runtime::BuildStorage;

pub fn new_test_ext() -> TestExternalities {
let t = frame_system::GenesisConfig::default()
.build_storage::<Test>()
let t = frame_system::GenesisConfig::<Test>::default()
.build_storage()
.unwrap();
TestExternalities::new(t)
}
Expand Down
5 changes: 2 additions & 3 deletions template/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -790,9 +790,8 @@ impl_runtime_apis! {
fn dispatch_benchmark(
config: frame_benchmarking::BenchmarkConfig
) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, sp_runtime::RuntimeString> {
use frame_benchmarking::{Benchmarking, BenchmarkBatch, add_benchmark, TrackedStorageKey};

impl frame_system_benchmarking::Config for Runtime {}
use frame_benchmarking::{Benchmarking, BenchmarkBatch, add_benchmark};
use frame_support::traits::TrackedStorageKey;

let whitelist: Vec<TrackedStorageKey> = vec![
// Block Number
Expand Down

0 comments on commit 03f4c34

Please sign in to comment.