Skip to content
Snippets Groups Projects

Distance pallet benchmark

All threads resolved!
5 files
+ 94
6
Compare changes
  • Side-by-side
  • Inline
Files
5
+ 74
0
// Copyright 2021-2023 Axiom-Team
//
// This file is part of Duniter-v2S.
//
// Duniter-v2S is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, version 3 of the License.
//
// Duniter-v2S is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>.
#![cfg(feature = "runtime-benchmarks")]
use super::*;
//use codec::Encode;
use codec::Encode;
use frame_benchmarking::{account, benchmarks, Vec};
use frame_support::pallet_prelude::IsType;
use frame_support::traits::Currency;
use frame_support::traits::OnInitialize;
use frame_support::ConsensusEngineId;
use frame_system::RawOrigin;
use pallet_balances::Pallet as Balances;
use pallet_identity::Identities;
use sp_runtime::traits::{Bounded, One};
use sp_runtime::DigestItem;
use sp_runtime::Perbill;
use crate::Pallet;
/*fn assert_has_event<T: Config>(generic_event: <T as Config>::RuntimeEvent) {
frame_system::Pallet::<T>::assert_has_event(generic_event.into());
}*/
benchmarks! {
where_clause {
where
T: pallet_balances::Config, T::Balance: From<u64>,
T::BlockNumber: From<u32>,
}
request_distance_evaluation {
let idty = T::IdtyIndex::one();
let caller: T::AccountId = pallet_identity::Identities::<T>::get(idty).unwrap().owner_key;
let caller_origin: <T as frame_system::Config>::RuntimeOrigin = RawOrigin::Signed(caller.clone()).into();
let _ = <Balances<T> as Currency<_>>::make_free_balance_be(&caller, T::Balance::max_value());
}: _<T::RuntimeOrigin>(caller_origin.clone())
verify {
assert!(IdentityDistanceStatus::<T>::get(&idty) == Some((caller, DistanceStatus::Pending)), "Request not added");
}
update_evaluation {
let idty = T::IdtyIndex::one();
let caller: T::AccountId = pallet_identity::Identities::<T>::get(idty).unwrap().owner_key;
let caller_origin: <T as frame_system::Config>::RuntimeOrigin = RawOrigin::Signed(caller.clone()).into();
//let _ = <Balances<T> as Currency<_>>::make_free_balance_be(&caller, T::Balance::max_value());
let computation_result = ComputationResult{distances: Vec::<Perbill>::default()};
/// TODO: set the author of the block.
/*let author = 1;
let mut digest:<frame_system::Pallet<T>>::digest = <frame_system::Pallet<T>>::digest();
const TEST_ID: ConsensusEngineId = [1, 2, 3, 4];
digest.logs.push(DigestItem::PreRuntime(TEST_ID, author.encode()));
//digest.logs.push(DigestItem::Seal(TEST_ID, author.encode()));
//digest.pop();
frame_system::Pallet::<T>::reset_events();
frame_system::Pallet::<T>::initialize(&0.into(), &Default::default(), &digest);
pallet_authorship::Pallet::<T>::author().unwrap();*/
}: _<T::RuntimeOrigin>(RawOrigin::None.into(), computation_result)
}
Loading