Skip to content

Commit

Permalink
fix democracy benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
brenzi committed Sep 17, 2024
1 parent 895052d commit e748885
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 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 democracy/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pallet-encointer-democracy"
version = "13.3.1"
version = "13.3.2"
authors = ["Encointer Association <[email protected]>"]
edition = "2021"
description = "Democracy pallet for the Encointer blockchain runtime"
Expand Down
28 changes: 13 additions & 15 deletions democracy/src/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
use crate::{Pallet as EncointerDemocracy, *};
use encointer_primitives::{
ceremonies::Reputation,
communities::CommunityIdentifier,
democracy::{ProposalState, Tally, Vote},
storage::{current_ceremony_index_key, global_reputation_count, participant_reputation},
ceremonies::Reputation,
communities::CommunityIdentifier,
democracy::{ProposalState, Tally, Vote},
storage::{current_ceremony_index_key, global_reputation_count, participant_reputation},
};
use frame_benchmarking::{account, benchmarks, impl_benchmark_test_suite};
use frame_support::{
assert_ok,
traits::{OnFinalize, OriginTrait},
BoundedVec,
assert_ok,
traits::{OnFinalize, OriginTrait},
BoundedVec,
};
use frame_system::RawOrigin;
use parity_scale_codec::Encode;
#[cfg(not(feature = "std"))]
use sp_std::vec;

fn advance_timestamp_equivalent_to_n_blocks<T: Config>(n: u64) {
let offset: T::Moment = (n * 6000u64)
.try_into()
.unwrap_or_else(|_| panic!("Something went horribly wrong!"));
let new_time: T::Moment = pallet_timestamp::Pallet::<T>::get() + offset;
let _ = pallet_timestamp::Pallet::<T>::set(T::RuntimeOrigin::none(), new_time);
pallet_timestamp::Pallet::<T>::on_finalize(frame_system::Pallet::<T>::block_number());
fn advance_timestamp_by<T: Config>(dt: T::Moment) {
let new_time: T::Moment = pallet_timestamp::Pallet::<T>::get() + dt;
let _ = pallet_timestamp::Pallet::<T>::set(T::RuntimeOrigin::none(), new_time);
pallet_timestamp::Pallet::<T>::on_finalize(frame_system::Pallet::<T>::block_number());
}

benchmarks! {
Expand Down Expand Up @@ -98,7 +95,8 @@ benchmarks! {
assert_eq!(EncointerDemocracy::<T>::proposals(1).unwrap().state, ProposalState::Ongoing);
EncointerDemocracy::<T>::update_proposal_state(RawOrigin::Signed(zoran.clone()).into(), 1).ok();
assert!(<EnactmentQueue<T>>::iter().next().is_none());
advance_timestamp_equivalent_to_n_blocks::<T>(21);
let confirmation_time = <T as Config>::ConfirmationPeriod::get();
advance_timestamp_by::<T>(confirmation_time + 1u32.into());

}: _(RawOrigin::Signed(zoran), 1)
verify {
Expand Down

0 comments on commit e748885

Please sign in to comment.