mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-03 15:47:24 +00:00
44d5aba80d
* Create a macro which automates creation of benchmark test suites. * bump impl_version * allow unused on test_bench_by_name * use proper doctest ignore attribute * Explicitly hand the Module to the test suite Much better practice than depending on it showing up implicitly in the namespace. * explicitly import what we need into `mod tests` * bench_module is `ident` not `tt` Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com> * allow end users to specify arguments for new_test_ext This turned out to be surprisingly easy. On reflection, it turns out that of course the compiler can't eagerly evaluate the function call, but needs to paste it in everywhere desired. * enable explicitly specifying the path to the benchmarks invocation also enable optional trailing commas * Revert "bump impl_version" This reverts commit 0209e4de33fd43873f8cfc6875815d0fd6151e63. * list failing benchmark tests and the errors which caused the failure * harden benchmark tests against internal panics * suppress warning about ignored profiles unfortunately, setting the profile here doesn't do anything; we'd need to set it in every leaf package anyway. However, as this was just making the default explicit anyway, I think it's safe enough to remove entirely. * impl_benchmark_test_suite for assets * impl_benchmark_test_suite for balances * impl_benchmark_test_suite for bounties * impl_benchmark_test_suite for Collective * impl_benchmark_test_suite for Contracts * impl_benchmark_test_suite for Democracy * don't impl_benchmark_test_suite for Elections-Phragmen * impl_benchmark_test_suite for Identity Note that Identity tests currently fail. They failed in an identical way before this change, so as far as I'm concerned, the status quo is good enough for now. * impl_benchmark_test_suite for ImOnline * impl_benchmark_test_suite for indices For this crate also, the test suite fails identically with and without this change, so we can say that this change is not the cause of the tests' failure to compile. * impl_benchmark_test_suite for lottery * impl_benchmark_test_suite for merkle-mountain-range * impl_benchmark_test_suite for Multisig These tests fail identically with and without the change, so the change seems unlikely to be the origin of the failures. * impl_benchmark_test_suite for offences * impl_benchmark_test_suite for Proxy Fails identically with and without this change. * impl_benchmark_test_suite for scheduler * impl_benchmark_test_suite for session It turns out to be important to be able to exclude items marked `#[extra]` sometimes. Who knew? * impl_benchmark_test_suite for staking * impl_benchmark_test_suite for system * impl_benchmark_test_suite for timestamp * impl_benchmark_test_suite for tips * impl_benchmark_test_suite for treasury * impl_benchmark_test_suite for utility Note that benchmark tests fail identically before and after this change. * impl_benchmark_test_suite for vesting * fix wrong module name in impl_benchmark_test_suite in Offences * address line length nits * enable optional keyword argument: exec_name Took a _lot_ of macro-wrangling to get the functionality that I want, but now you have the option to pass in ```rust impl_benchmark_test_suite!( Elections, crate::tests::ExtBuilder::default().desired_members(13).desired_runners_up(7), crate::tests::Test, exec_name = build_and_execute, ); ``` and have it expand out properly. A selected fragment of the expansion: ```rust fn test_benchmarks() { crate::tests::ExtBuilder::default() .desired_members(13) .desired_runners_up(7) .build_and_execute(|| { ``` * get rid of dead code Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>
146 lines
4.3 KiB
Rust
146 lines
4.3 KiB
Rust
// This file is part of Substrate.
|
|
|
|
// Copyright (C) 2019-2021 Parity Technologies (UK) Ltd.
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
// Benchmarks for Utility Pallet
|
|
|
|
#![cfg_attr(not(feature = "std"), no_std)]
|
|
|
|
use codec::Encode;
|
|
use sp_std::vec;
|
|
use sp_std::prelude::*;
|
|
use sp_core::{ChangesTrieConfiguration, storage::well_known_keys};
|
|
use sp_runtime::traits::Hash;
|
|
use frame_benchmarking::{benchmarks, whitelisted_caller, impl_benchmark_test_suite};
|
|
use frame_support::{
|
|
storage,
|
|
traits::Get,
|
|
weights::DispatchClass,
|
|
};
|
|
use frame_system::{Module as System, Call, RawOrigin, DigestItemOf};
|
|
|
|
mod mock;
|
|
|
|
pub struct Module<T: Config>(System<T>);
|
|
pub trait Config: frame_system::Config {}
|
|
|
|
benchmarks! {
|
|
remark {
|
|
let b in 0 .. *T::BlockLength::get().max.get(DispatchClass::Normal) as u32;
|
|
let remark_message = vec![1; b as usize];
|
|
let caller = whitelisted_caller();
|
|
}: _(RawOrigin::Signed(caller), remark_message)
|
|
|
|
set_heap_pages {
|
|
}: _(RawOrigin::Root, Default::default())
|
|
|
|
// `set_code` was not benchmarked because it is pretty hard to come up with a real
|
|
// Wasm runtime to test the upgrade with. But this is okay because we will make
|
|
// `set_code` take a full block anyway.
|
|
|
|
#[extra]
|
|
set_code_without_checks {
|
|
// Assume Wasm ~4MB
|
|
let code = vec![1; 4_000_000 as usize];
|
|
}: _(RawOrigin::Root, code)
|
|
verify {
|
|
let current_code = storage::unhashed::get_raw(well_known_keys::CODE).ok_or("Code not stored.")?;
|
|
assert_eq!(current_code.len(), 4_000_000 as usize);
|
|
}
|
|
|
|
set_changes_trie_config {
|
|
let d = 1000;
|
|
|
|
let digest_item = DigestItemOf::<T>::Other(vec![]);
|
|
|
|
for i in 0 .. d {
|
|
System::<T>::deposit_log(digest_item.clone());
|
|
}
|
|
let changes_trie_config = ChangesTrieConfiguration {
|
|
digest_interval: d,
|
|
digest_levels: d,
|
|
};
|
|
}: _(RawOrigin::Root, Some(changes_trie_config))
|
|
verify {
|
|
assert_eq!(System::<T>::digest().logs.len(), (d + 1) as usize)
|
|
}
|
|
|
|
set_storage {
|
|
let i in 1 .. 1000;
|
|
|
|
// Set up i items to add
|
|
let mut items = Vec::new();
|
|
for j in 0 .. i {
|
|
let hash = (i, j).using_encoded(T::Hashing::hash).as_ref().to_vec();
|
|
items.push((hash.clone(), hash.clone()));
|
|
}
|
|
}: _(RawOrigin::Root, items)
|
|
verify {
|
|
let last_hash = (i, i - 1).using_encoded(T::Hashing::hash);
|
|
let value = storage::unhashed::get_raw(last_hash.as_ref()).ok_or("No value stored")?;
|
|
assert_eq!(value, last_hash.as_ref().to_vec());
|
|
}
|
|
|
|
kill_storage {
|
|
let i in 1 .. 1000;
|
|
|
|
// Add i items to storage
|
|
let mut items = Vec::new();
|
|
for j in 0 .. i {
|
|
let hash = (i, j).using_encoded(T::Hashing::hash).as_ref().to_vec();
|
|
storage::unhashed::put_raw(&hash, &hash);
|
|
items.push(hash);
|
|
}
|
|
|
|
// We will verify this value is removed
|
|
let last_hash = (i, i - 1).using_encoded(T::Hashing::hash);
|
|
let value = storage::unhashed::get_raw(last_hash.as_ref()).ok_or("No value stored")?;
|
|
assert_eq!(value, last_hash.as_ref().to_vec());
|
|
|
|
}: _(RawOrigin::Root, items)
|
|
verify {
|
|
assert_eq!(storage::unhashed::get_raw(last_hash.as_ref()), None);
|
|
}
|
|
|
|
kill_prefix {
|
|
let p in 1 .. 1000;
|
|
|
|
let prefix = p.using_encoded(T::Hashing::hash).as_ref().to_vec();
|
|
// add p items that share a prefix
|
|
for i in 0 .. p {
|
|
let hash = (p, i).using_encoded(T::Hashing::hash).as_ref().to_vec();
|
|
let key = [&prefix[..], &hash[..]].concat();
|
|
storage::unhashed::put_raw(&key, &key);
|
|
}
|
|
|
|
// We will verify this value is removed
|
|
let last_hash = (p, p - 1).using_encoded(T::Hashing::hash).as_ref().to_vec();
|
|
let last_key = [&prefix[..], &last_hash[..]].concat();
|
|
let value = storage::unhashed::get_raw(&last_key).ok_or("No value stored")?;
|
|
assert_eq!(value, last_key);
|
|
|
|
}: _(RawOrigin::Root, prefix, p)
|
|
verify {
|
|
assert_eq!(storage::unhashed::get_raw(&last_key), None);
|
|
}
|
|
}
|
|
|
|
impl_benchmark_test_suite!(
|
|
Module,
|
|
crate::mock::new_test_ext(),
|
|
crate::mock::Test,
|
|
);
|