Skip to content

Commit

Permalink
benchmarks: account existential deposit in author mapping benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
RomarQ committed May 10, 2024
1 parent 83b6067 commit 3e06d6a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
4 changes: 3 additions & 1 deletion pallets/author-mapping/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ serde = { workspace = true, optional = true }
frame-benchmarking = { workspace = true, optional = true }
frame-support = { workspace = true }
frame-system = { workspace = true }
pallet-balances = { workspace = true, optional = true }
parity-scale-codec = { workspace = true, features = [ "derive" ] }
scale-info = { workspace = true, features = [ "derive" ] }
sp-runtime = { workspace = true }
Expand All @@ -27,7 +28,6 @@ sp-std = { workspace = true }
session-keys-primitives = { workspace = true }

[dev-dependencies]
pallet-balances = { workspace = true, features = ["std"] }
sp-core = { workspace = true }
sp-io = { workspace = true }

Expand All @@ -45,9 +45,11 @@ std = [
"session-keys-primitives/std",
"sp-runtime/std",
"sp-std/std",
"pallet-balances/std"
]
runtime-benchmarks = [
"frame-benchmarking",
"pallet-balances",
"session-keys-primitives/runtime-benchmarks",
]
try-runtime = [ "frame-support/try-runtime" ]
15 changes: 9 additions & 6 deletions pallets/author-mapping/src/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ use nimbus_primitives::NimbusId;
use parity_scale_codec::Decode;

/// Create a funded user.
fn create_funded_user<T: Config>() -> T::AccountId {
fn create_funded_user<T: Config + pallet_balances::Config<Balance = BalanceOf<T>>>() -> T::AccountId
{
let user = account("account id", 0u32, 0u32);
T::DepositCurrency::make_free_balance_be(
&user,
<<T as Config>::DepositAmount as Get<BalanceOf<T>>>::get(),
);
T::DepositCurrency::issue(<<T as Config>::DepositAmount as Get<BalanceOf<T>>>::get());
let existential_deposit = <T as pallet_balances::Config>::ExistentialDeposit::get();
let amount = existential_deposit + <<T as Config>::DepositAmount as Get<BalanceOf<T>>>::get();

T::DepositCurrency::make_free_balance_be(&user, amount);
T::DepositCurrency::issue(amount);
user
}

Expand All @@ -45,6 +46,8 @@ pub fn nimbus_id(seed: u8) -> NimbusId {
}

benchmarks! {
where_clause { where T: pallet_balances::Config<Balance = BalanceOf<T>> }

add_association {
let caller = create_funded_user::<T>();
let id = nimbus_id(1u8);
Expand Down

0 comments on commit 3e06d6a

Please sign in to comment.