From e748885165b780476ad36968f576c416ca1a5c27 Mon Sep 17 00:00:00 2001 From: Alain Brenzikofer Date: Tue, 17 Sep 2024 11:37:57 +0200 Subject: [PATCH] fix democracy benchmarks --- Cargo.lock | 2 +- democracy/Cargo.toml | 2 +- democracy/src/benchmarking.rs | 28 +++++++++++++--------------- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4a0c0c8e..bac97c80 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4697,7 +4697,7 @@ dependencies = [ [[package]] name = "pallet-encointer-democracy" -version = "13.3.1" +version = "13.3.2" dependencies = [ "approx", "encointer-primitives", diff --git a/democracy/Cargo.toml b/democracy/Cargo.toml index 58adcf26..a16d6af9 100644 --- a/democracy/Cargo.toml +++ b/democracy/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pallet-encointer-democracy" -version = "13.3.1" +version = "13.3.2" authors = ["Encointer Association "] edition = "2021" description = "Democracy pallet for the Encointer blockchain runtime" diff --git a/democracy/src/benchmarking.rs b/democracy/src/benchmarking.rs index a9091125..feed0bed 100644 --- a/democracy/src/benchmarking.rs +++ b/democracy/src/benchmarking.rs @@ -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(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::::get() + offset; - let _ = pallet_timestamp::Pallet::::set(T::RuntimeOrigin::none(), new_time); - pallet_timestamp::Pallet::::on_finalize(frame_system::Pallet::::block_number()); +fn advance_timestamp_by(dt: T::Moment) { + let new_time: T::Moment = pallet_timestamp::Pallet::::get() + dt; + let _ = pallet_timestamp::Pallet::::set(T::RuntimeOrigin::none(), new_time); + pallet_timestamp::Pallet::::on_finalize(frame_system::Pallet::::block_number()); } benchmarks! { @@ -98,7 +95,8 @@ benchmarks! { assert_eq!(EncointerDemocracy::::proposals(1).unwrap().state, ProposalState::Ongoing); EncointerDemocracy::::update_proposal_state(RawOrigin::Signed(zoran.clone()).into(), 1).ok(); assert!(>::iter().next().is_none()); - advance_timestamp_equivalent_to_n_blocks::(21); + let confirmation_time = ::ConfirmationPeriod::get(); + advance_timestamp_by::(confirmation_time + 1u32.into()); }: _(RawOrigin::Signed(zoran), 1) verify {