git.delta.rocks / unique-network / refs/commits / e8c8f78361e7

difftreelog

source

pallets/evm-migration/src/benchmarking.rs2.5 KiBsourcehistory
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617#![allow(missing_docs)]1819use frame_benchmarking::v2::*;20use frame_system::RawOrigin;21use sp_core::{H160, H256};22use sp_std::{vec, vec::Vec};2324use super::{Call, Config, Pallet};2526#[benchmarks(27	where <T as Config>::RuntimeEvent: parity_scale_codec::Encode28)]29mod benchmarks {30	use super::*;3132	#[benchmark]33	fn begin() -> Result<(), BenchmarkError> {34		#[extrinsic_call]35		_(RawOrigin::Root, H160::default());3637		Ok(())38	}3940	#[benchmark]41	fn set_data(b: Linear<0, 80>) -> Result<(), BenchmarkError> {42		let address = H160::from_low_u64_be(b as u64);43		let mut data = Vec::new();44		for i in 0..b {45			data.push((46				H256::from_low_u64_be(i as u64),47				H256::from_low_u64_be(i as u64),48			));49		}50		<Pallet<T>>::begin(RawOrigin::Root.into(), address)?;5152		#[extrinsic_call]53		_(RawOrigin::Root, address, data);5455		Ok(())56	}5758	#[benchmark]59	fn finish(b: Linear<0, 80>) -> Result<(), BenchmarkError> {60		let address = H160::from_low_u64_be(b as u64);61		let data: Vec<u8> = (0..b as u8).collect();62		<Pallet<T>>::begin(RawOrigin::Root.into(), address)?;6364		#[extrinsic_call]65		_(RawOrigin::Root, address, data);6667		Ok(())68	}6970	#[benchmark]71	fn insert_eth_logs(b: Linear<0, 200>) -> Result<(), BenchmarkError> {72		let logs = (0..b)73			.map(|_| ethereum::Log {74				address: H160([b as u8; 20]),75				data: vec![b as u8; 128],76				topics: vec![H256([b as u8; 32]); 6],77			})78			.collect::<Vec<_>>();7980		#[extrinsic_call]81		_(RawOrigin::Root, logs);8283		Ok(())84	}8586	#[benchmark]87	fn insert_events(b: Linear<0, 200>) -> Result<(), BenchmarkError> {88		use parity_scale_codec::Encode;89		let logs = (0..b)90			.map(|_| <T as Config>::RuntimeEvent::from(crate::Event::<T>::TestEvent).encode())91			.collect::<Vec<_>>();9293		#[extrinsic_call]94		_(RawOrigin::Root, logs);9596		Ok(())97	}98}