Exchange pallet benchmarks (#158)

* exchange benchmarks: framework

* updated comment about tx size

Co-authored-by: Tomasz Drwięga <tomasz@parity.io>
This commit is contained in:
Svyatoslav Nikolsky
2020-07-16 12:58:46 +03:00
committed by Bastian Köcher
parent ebdfffc4b1
commit 00bd13f8cd
10 changed files with 281 additions and 45 deletions
+22 -7
View File
@@ -27,7 +27,7 @@
use crate::finality::FinalityVotes;
use crate::validators::CHANGE_EVENT_HASH;
use crate::verification::calculate_score;
use crate::{HeaderToImport, Storage};
use crate::{HeaderToImport, Storage, Trait};
use primitives::{
rlp_encode,
@@ -60,25 +60,34 @@ impl HeaderBuilder {
}
}
/// Creates default header on top of parent with given hash.
/// Creates default header on top of test parent with given hash.
#[cfg(test)]
pub fn with_parent_hash(parent_hash: H256) -> Self {
use crate::mock::TestRuntime;
Self::with_parent_hash_on_runtime::<crate::mock::TestRuntime>(parent_hash)
}
/// Creates default header on top of test parent with given number. First parent is selected.
#[cfg(test)]
pub fn with_parent_number(parent_number: u64) -> Self {
Self::with_parent_number_on_runtime::<crate::mock::TestRuntime>(parent_number)
}
/// Creates default header on top of parent with given hash.
pub fn with_parent_hash_on_runtime<T: Trait>(parent_hash: H256) -> Self {
use crate::Headers;
use frame_support::StorageMap;
let parent_header = Headers::<TestRuntime>::get(&parent_hash).unwrap().header;
let parent_header = Headers::<T>::get(&parent_hash).unwrap().header;
Self::with_parent(&parent_header)
}
/// Creates default header on top of parent with given number. First parent is selected.
#[cfg(test)]
pub fn with_parent_number(parent_number: u64) -> Self {
pub fn with_parent_number_on_runtime<T: Trait>(parent_number: u64) -> Self {
use crate::HeadersByNumber;
use frame_support::StorageMap;
let parent_hash = HeadersByNumber::get(parent_number).unwrap()[0].clone();
Self::with_parent_hash(parent_hash)
Self::with_parent_hash_on_runtime::<T>(parent_hash)
}
/// Creates default header on top of non-existent parent.
@@ -185,6 +194,12 @@ impl HeaderBuilder {
self
}
/// Update transactions root field of this header.
pub fn with_transactions_root(mut self, transactions_root: H256) -> Self {
self.header.transactions_root = transactions_root;
self
}
/// Signs header by given author.
pub fn sign_by(self, author: &SecretKey) -> Header {
self.header.sign_by(author)