Skip to content

Commit

Permalink
add benchmarks for treasuries
Browse files Browse the repository at this point in the history
  • Loading branch information
brenzi committed Jan 13, 2025
1 parent df995b3 commit e68dc32
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion treasuries/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pallet-encointer-treasuries"
version = "14.4.0"
version = "14.4.1"
authors = ["Encointer Association <[email protected]>"]
edition = "2021"
description = "Treasuries pallet for the Encointer blockchain runtime"
Expand Down
37 changes: 37 additions & 0 deletions treasuries/src/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use crate::*;
use encointer_primitives::treasuries::SwapNativeOption;
use frame_benchmarking::{account, benchmarks, impl_benchmark_test_suite};
use frame_system::RawOrigin;
use sp_runtime::SaturatedConversion;

benchmarks! {
where_clause {
where
H256: From<<T as frame_system::Config>::Hash>,
}
swap_native {
let cid = CommunityIdentifier::default();
let alice: T::AccountId = account("alice", 1, 1);
let treasury = Pallet::<T>::get_community_treasury_account_unchecked(Some(cid));
<T as Config>::Currency::make_free_balance_be(&treasury, 200_000_000u64.saturated_into());
pallet_encointer_balances::Pallet::<T>::issue(cid, &alice, BalanceType::from_num(12i32)).unwrap();
let swap_option: SwapNativeOption<BalanceOf<T>, T::Moment> = SwapNativeOption {
cid,
native_allowance: 100_000_000u64.saturated_into(),
rate: Some(BalanceType::from_num(0.000_000_2)),
do_burn: false,
valid_from: None,
valid_until: None,
};
Pallet::<T>::do_issue_swap_native_option(
cid,
&alice,
swap_option
).unwrap();
} : _(RawOrigin::Signed(alice.clone()), cid, 50_000_000u64.saturated_into())
verify {
assert_eq!(<T as Config>::Currency::free_balance(&alice), 50_000_000u64.saturated_into());
}
}

impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ext(), crate::mock::TestRuntime);
2 changes: 2 additions & 0 deletions treasuries/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ const LOG: &str = "encointer";
pub use crate::weights::WeightInfo;
pub use pallet::*;

#[cfg(feature = "runtime-benchmarks")]
mod benchmarking;
#[cfg(test)]
mod mock;
#[cfg(test)]
Expand Down

0 comments on commit e68dc32

Please sign in to comment.