2024-10-03 15:38:52 +03:00
|
|
|
#![cfg(feature = "runtime-benchmarks")]
|
|
|
|
|
|
|
|
|
|
use super::*;
|
|
|
|
|
use frame_benchmarking::v1::*;
|
|
|
|
|
|
|
|
|
|
use frame_system::RawOrigin;
|
2025-06-02 19:20:14 +03:00
|
|
|
use frame_support::traits::fungible::Inspect;
|
2024-10-03 15:38:52 +03:00
|
|
|
|
|
|
|
|
pub fn create_account<T: Config>() -> T::AccountId {
|
|
|
|
|
let account_bytes = Vec::from([1u8; 32]);
|
|
|
|
|
T::AccountId::decode(&mut &account_bytes[0..32])
|
|
|
|
|
.expect("32 bytes always construct an AccountId32")
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-02 19:20:14 +03:00
|
|
|
benchmarks! {
|
|
|
|
|
slow_clap {
|
2024-10-03 15:38:52 +03:00
|
|
|
let minimum_balance = <<T as pallet::Config>::Currency>::minimum_balance();
|
2025-06-02 19:20:14 +03:00
|
|
|
let receiver = create_account::<T>();
|
|
|
|
|
let amount = minimum_balance + minimum_balance;
|
|
|
|
|
let network_id = NetworkIdOf::<T>::default();
|
2024-10-03 15:38:52 +03:00
|
|
|
|
2025-06-02 19:20:14 +03:00
|
|
|
let authorities = vec![T::AuthorityId::generate_pair(None)];
|
|
|
|
|
let bounded_authorities =
|
|
|
|
|
WeakBoundedVec::<_, T::MaxAuthorities>::try_from(authorities.clone())
|
2024-10-03 15:38:52 +03:00
|
|
|
.map_err(|()| "more than the maximum number of keys provided")?;
|
2025-06-02 19:20:14 +03:00
|
|
|
Authorities::<T>::put(bounded_authorities);
|
2024-10-03 15:38:52 +03:00
|
|
|
|
2025-06-02 19:20:14 +03:00
|
|
|
let clap = Clap {
|
|
|
|
|
session_index: 0,
|
2024-10-03 15:38:52 +03:00
|
|
|
authority_index: 0,
|
|
|
|
|
transaction_hash: H256::repeat_byte(1u8),
|
|
|
|
|
block_number: 69,
|
2025-06-02 19:20:14 +03:00
|
|
|
removed: false,
|
|
|
|
|
network_id,
|
|
|
|
|
receiver: receiver.clone(),
|
|
|
|
|
amount,
|
2024-10-03 15:38:52 +03:00
|
|
|
};
|
|
|
|
|
|
2025-06-02 19:20:14 +03:00
|
|
|
let authority_id = authorities
|
|
|
|
|
.get(0usize)
|
|
|
|
|
.expect("first authority should exist");
|
|
|
|
|
let encoded_clap = clap.encode();
|
|
|
|
|
let signature = authority_id.sign(&encoded_clap)
|
|
|
|
|
.ok_or("couldn't make signature")?;
|
2024-10-03 15:38:52 +03:00
|
|
|
|
2025-06-02 19:20:14 +03:00
|
|
|
}: _(RawOrigin::None, clap, signature)
|
2024-10-03 15:38:52 +03:00
|
|
|
verify {
|
2025-06-02 19:20:14 +03:00
|
|
|
assert_eq!(<<T as pallet::Config>::Currency>::total_balance(&receiver), amount);
|
2024-10-03 15:38:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl_benchmark_test_suite!(
|
|
|
|
|
Pallet,
|
|
|
|
|
crate::mock::new_test_ext(),
|
|
|
|
|
crate::mock::Runtime,
|
|
|
|
|
);
|
|
|
|
|
}
|