Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ermalkaleci committed Jul 11, 2024
1 parent 8f2e8dc commit 69a30f2
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 26 deletions.
51 changes: 38 additions & 13 deletions runtime/astar/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,10 +344,10 @@ parameter_types! {
}

#[cfg(feature = "runtime-benchmarks")]
pub struct BenchmarkHelper<SC, ACC>(sp_std::marker::PhantomData<(SC, ACC)>);
pub struct DAppStakingBenchmarkHelper<SC, ACC>(sp_std::marker::PhantomData<(SC, ACC)>);
#[cfg(feature = "runtime-benchmarks")]
impl pallet_dapp_staking_v3::BenchmarkHelper<SmartContract<AccountId>, AccountId>
for BenchmarkHelper<SmartContract<AccountId>, AccountId>
for DAppStakingBenchmarkHelper<SmartContract<AccountId>, AccountId>
{
fn get_smart_contract(id: u32) -> SmartContract<AccountId> {
let id_bytes = id.to_le_bytes();
Expand All @@ -363,15 +363,6 @@ impl pallet_dapp_staking_v3::BenchmarkHelper<SmartContract<AccountId>, AccountId
.expect("Must succeed in test/benchmark environment.");
}
}
#[cfg(feature = "runtime-benchmarks")]
impl<SC, ACC> orml_oracle::BenchmarkHelper<CurrencyId, Price, ConstU32<2>>
for BenchmarkHelper<SC, ACC>
{
fn get_currency_id_value_pairs() -> sp_runtime::BoundedVec<(CurrencyId, Price), ConstU32<2>> {
sp_runtime::BoundedVec::try_from(vec![(CurrencyId::ASTR, Price::from_rational(15, 100))])
.expect("out of bounds")
}
}

pub struct AccountCheck;
impl DappStakingAccountCheck<AccountId> for AccountCheck {
Expand Down Expand Up @@ -407,7 +398,7 @@ impl pallet_dapp_staking_v3::Config for Runtime {
type RankingEnabled = ConstBool<true>;
type WeightInfo = weights::pallet_dapp_staking_v3::SubstrateWeight<Runtime>;
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = BenchmarkHelper<SmartContract<AccountId>, AccountId>;
type BenchmarkHelper = DAppStakingBenchmarkHelper<SmartContract<AccountId>, AccountId>;
}

pub struct InflationPayoutPerBlock;
Expand Down Expand Up @@ -1108,6 +1099,19 @@ impl pallet_price_aggregator::Config for Runtime {
type WeightInfo = pallet_price_aggregator::weights::SubstrateWeight<Runtime>;
}

#[cfg(feature = "runtime-benchmarks")]
pub struct OracleBenchmarkHelper;
#[cfg(feature = "runtime-benchmarks")]
impl orml_oracle::BenchmarkHelper<CurrencyId, Price, ConstU32<2>> for OracleBenchmarkHelper {
fn get_currency_id_value_pairs() -> sp_runtime::BoundedVec<(CurrencyId, Price), ConstU32<2>> {
sp_runtime::BoundedVec::try_from(vec![
(CurrencyId::ASTR, Price::from_rational(15, 100)),
(CurrencyId::ASTR, Price::from_rational(15, 100)),
])
.expect("out of bounds")
}
}

parameter_types! {
// Cannot specify `Root` so need to do it like this, unfortunately.
pub RootOperatorAccountId: AccountId = AccountId::from([0xffu8; 32]);
Expand All @@ -1121,6 +1125,9 @@ impl orml_oracle::Config for Runtime {
type OracleKey = CurrencyId;
type OracleValue = Price;
type RootOperatorAccountId = RootOperatorAccountId;
#[cfg(feature = "runtime-benchmarks")]
type Members = OracleMembershipWrapper;
#[cfg(not(feature = "runtime-benchmarks"))]
type Members = OracleMembership;
type MaxHasDispatchedSize = ConstU32<8>;
type WeightInfo = oracle_benchmarks::weights::SubstrateWeight<Runtime>;
Expand All @@ -1129,7 +1136,7 @@ impl orml_oracle::Config for Runtime {
#[cfg(not(feature = "runtime-benchmarks"))]
type MaxFeedValues = ConstU32<1>;
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = BenchmarkHelper<SmartContract<AccountId>, AccountId>;
type BenchmarkHelper = OracleBenchmarkHelper;
}

impl pallet_membership::Config<OracleMembershipInst> for Runtime {
Expand All @@ -1146,6 +1153,24 @@ impl pallet_membership::Config<OracleMembershipInst> for Runtime {
type WeightInfo = pallet_membership::weights::SubstrateWeight<Runtime>;
}

/// OracleMembership wrapper used by benchmarks
#[cfg(feature = "runtime-benchmarks")]
pub struct OracleMembershipWrapper;

#[cfg(feature = "runtime-benchmarks")]
impl frame_support::traits::SortedMembers<AccountId> for OracleMembershipWrapper {
fn sorted_members() -> Vec<AccountId> {
OracleMembership::sorted_members()
}

fn add(account: &AccountId) {
frame_support::assert_ok!(OracleMembership::add_member(
frame_system::RawOrigin::Root.into(),
account.to_owned().into()
));
}
}

construct_runtime!(
pub struct Runtime
{
Expand Down
51 changes: 38 additions & 13 deletions runtime/shiden/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,10 +369,10 @@ impl pallet_multisig::Config for Runtime {
}

#[cfg(feature = "runtime-benchmarks")]
pub struct BenchmarkHelper<SC, ACC>(sp_std::marker::PhantomData<(SC, ACC)>);
pub struct DAppStakingBenchmarkHelper<SC, ACC>(sp_std::marker::PhantomData<(SC, ACC)>);
#[cfg(feature = "runtime-benchmarks")]
impl pallet_dapp_staking_v3::BenchmarkHelper<SmartContract<AccountId>, AccountId>
for BenchmarkHelper<SmartContract<AccountId>, AccountId>
for DAppStakingBenchmarkHelper<SmartContract<AccountId>, AccountId>
{
fn get_smart_contract(id: u32) -> SmartContract<AccountId> {
let id_bytes = id.to_le_bytes();
Expand All @@ -388,15 +388,6 @@ impl pallet_dapp_staking_v3::BenchmarkHelper<SmartContract<AccountId>, AccountId
.expect("Must succeed in test/benchmark environment.");
}
}
#[cfg(feature = "runtime-benchmarks")]
impl<SC, ACC> orml_oracle::BenchmarkHelper<CurrencyId, Price, ConstU32<2>>
for BenchmarkHelper<SC, ACC>
{
fn get_currency_id_value_pairs() -> sp_runtime::BoundedVec<(CurrencyId, Price), ConstU32<2>> {
sp_runtime::BoundedVec::try_from(vec![(CurrencyId::ASTR, Price::from_rational(15, 100))])
.expect("out of bounds")
}
}

pub struct AccountCheck;
impl DappStakingAccountCheck<AccountId> for AccountCheck {
Expand Down Expand Up @@ -446,7 +437,7 @@ impl pallet_dapp_staking_v3::Config for Runtime {
type RankingEnabled = ConstBool<true>;
type WeightInfo = weights::pallet_dapp_staking_v3::SubstrateWeight<Runtime>;
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = BenchmarkHelper<SmartContract<AccountId>, AccountId>;
type BenchmarkHelper = DAppStakingBenchmarkHelper<SmartContract<AccountId>, AccountId>;
}

pub struct InflationPayoutPerBlock;
Expand Down Expand Up @@ -1109,6 +1100,19 @@ impl pallet_price_aggregator::Config for Runtime {
type WeightInfo = pallet_price_aggregator::weights::SubstrateWeight<Runtime>;
}

#[cfg(feature = "runtime-benchmarks")]
pub struct OracleBenchmarkHelper;
#[cfg(feature = "runtime-benchmarks")]
impl orml_oracle::BenchmarkHelper<CurrencyId, Price, ConstU32<2>> for OracleBenchmarkHelper {
fn get_currency_id_value_pairs() -> sp_runtime::BoundedVec<(CurrencyId, Price), ConstU32<2>> {
sp_runtime::BoundedVec::try_from(vec![
(CurrencyId::ASTR, Price::from_rational(15, 100)),
(CurrencyId::ASTR, Price::from_rational(15, 100)),
])
.expect("out of bounds")
}
}

parameter_types! {
// Cannot specify `Root` so need to do it like this, unfortunately.
pub RootOperatorAccountId: AccountId = AccountId::from([0xffu8; 32]);
Expand All @@ -1122,6 +1126,9 @@ impl orml_oracle::Config for Runtime {
type OracleKey = CurrencyId;
type OracleValue = Price;
type RootOperatorAccountId = RootOperatorAccountId;
#[cfg(feature = "runtime-benchmarks")]
type Members = OracleMembershipWrapper;
#[cfg(not(feature = "runtime-benchmarks"))]
type Members = OracleMembership;
type MaxHasDispatchedSize = ConstU32<8>;
type WeightInfo = oracle_benchmarks::weights::SubstrateWeight<Runtime>;
Expand All @@ -1130,7 +1137,7 @@ impl orml_oracle::Config for Runtime {
#[cfg(not(feature = "runtime-benchmarks"))]
type MaxFeedValues = ConstU32<1>;
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = BenchmarkHelper<SmartContract<AccountId>, AccountId>;
type BenchmarkHelper = OracleBenchmarkHelper;
}

impl pallet_membership::Config<OracleMembershipInst> for Runtime {
Expand All @@ -1147,6 +1154,24 @@ impl pallet_membership::Config<OracleMembershipInst> for Runtime {
type WeightInfo = pallet_membership::weights::SubstrateWeight<Runtime>;
}

/// OracleMembership wrapper used by benchmarks
#[cfg(feature = "runtime-benchmarks")]
pub struct OracleMembershipWrapper;

#[cfg(feature = "runtime-benchmarks")]
impl frame_support::traits::SortedMembers<AccountId> for OracleMembershipWrapper {
fn sorted_members() -> Vec<AccountId> {
OracleMembership::sorted_members()
}

fn add(account: &AccountId) {
frame_support::assert_ok!(OracleMembership::add_member(
frame_system::RawOrigin::Root.into(),
account.to_owned().into()
));
}
}

construct_runtime!(
pub struct Runtime
{
Expand Down

0 comments on commit 69a30f2

Please sign in to comment.