Skip to content

Commit

Permalink
fix benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriele-0201 committed Dec 15, 2023
1 parent 4ec3546 commit 17d61ff
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 31 deletions.
27 changes: 10 additions & 17 deletions sugondat-chain/pallets/blobs/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use codec::Encode;
use frame_benchmarking::__private::traits::Hooks;
#[allow(unused)]
use frame_benchmarking::v2::{benchmarks, impl_benchmark_test_suite, whitelisted_caller};
use frame_support::{traits::Get, BoundedVec};
use frame_support::traits::Get;
use frame_system::RawOrigin;
use sp_std::vec;

Expand All @@ -30,12 +30,8 @@ mod benchmarks {
sp_io::storage::set(b":extrinsic_index", &(ext_index).encode());
Blobs::<T>::submit_blob(
RawOrigin::Signed(caller.clone()).into(),
ext_index,
ext_index
.to_le_bytes()
.to_vec()
.try_into()
.expect("Impossible convert blob into BoundedVec"),
(ext_index as u128).into(),
ext_index.to_le_bytes().to_vec(),
)
.expect("Preparation Extrinsic failed");
}
Expand All @@ -56,20 +52,16 @@ mod benchmarks {
sp_io::storage::set(b":extrinsic_index", &(x).encode());

// Create a random blob that needs to be hashed on chain
let blob: BoundedVec<u8, T::MaxBlobSize> = vec![23u8]
.repeat(y as usize)
.try_into()
.expect("Impossible convert blob into BoundedVec");

let blob = vec![23u8; y as usize];
#[extrinsic_call]
_(RawOrigin::Signed(caller), 0, blob);
_(RawOrigin::Signed(caller), 0.into(), blob);

// Check that an item is inserted in the BlobList and
// the new value stored in TotalBlobs are correct
assert_eq!(BlobList::<T>::get().len(), x as usize + 1);
assert_eq!(TotalBlobs::<T>::get(), x as u32 + 1);
// the blob size of all the previus sumbitted blob si 4 bytes (u32.to_le_bytes())
assert_eq!(TotalBlobsSize::<T>::get(), (x * 4) + y);
assert_eq!(TotalBlobSize::<T>::get(), (x * 4) + y);
}

#[benchmark]
Expand All @@ -84,9 +76,10 @@ mod benchmarks {
Blobs::<T>::on_finalize(15u32.into());
}

assert_eq!(BlobList::<T>::get().len(), x as usize);
assert_eq!(TotalBlobs::<T>::get(), x as u32);
assert_eq!(TotalBlobsSize::<T>::get(), x * 4);
// Every storage Item should be killed
assert_eq!(BlobList::<T>::get().len(), 0);
assert_eq!(TotalBlobs::<T>::get(), 0);
assert_eq!(TotalBlobSize::<T>::get(), 0);
}

impl_benchmark_test_suite!(Blobs, crate::mock::new_test_ext(), crate::mock::Test);
Expand Down
7 changes: 0 additions & 7 deletions sugondat-chain/runtimes/sugondat-kusama/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,6 @@ pub type TrustedTeleporters = ();
/// The parent relay chain is the accepted reserve for the native asset.
pub type TrustedReserve = ParentRelayChainAndAsset;

#[cfg(feature = "runtime-benchmarks")]
parameter_types! {
pub ReachableDest: Option<MultiLocation> = Some(Parent.into());
}

impl pallet_xcm::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type SendXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
Expand All @@ -219,8 +214,6 @@ impl pallet_xcm::Config for Runtime {
type MaxLockers = ConstU32<8>;
// TODO: needs benchmarked weights
type WeightInfo = pallet_xcm::TestWeightInfo;
#[cfg(feature = "runtime-benchmarks")]
type ReachableDest = ReachableDest;
type AdminOrigin = EnsureRoot<AccountId>;
type MaxRemoteLockConsumers = ConstU32<0>;
type RemoteLockConsumerIdentifier = ();
Expand Down
7 changes: 0 additions & 7 deletions sugondat-chain/runtimes/test/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,6 @@ pub type XcmRouter = WithUniqueTopic<(
XcmpQueue,
)>;

#[cfg(feature = "runtime-benchmarks")]
parameter_types! {
pub ReachableDest: Option<MultiLocation> = Some(Parent.into());
}

impl pallet_xcm::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type SendXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
Expand All @@ -180,8 +175,6 @@ impl pallet_xcm::Config for Runtime {
type SovereignAccountOf = LocationToAccountId;
type MaxLockers = ConstU32<8>;
type WeightInfo = pallet_xcm::TestWeightInfo;
#[cfg(feature = "runtime-benchmarks")]
type ReachableDest = ReachableDest;
type AdminOrigin = EnsureRoot<AccountId>;
type MaxRemoteLockConsumers = ConstU32<0>;
type RemoteLockConsumerIdentifier = ();
Expand Down

0 comments on commit 17d61ff

Please sign in to comment.