-
Notifications
You must be signed in to change notification settings - Fork 416
/
Copy pathbenchmarking.rs
103 lines (82 loc) · 2.83 KB
/
benchmarking.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// This file is part of Astar.
// Copyright (C) 2019-2023 Stake Technologies Pte.Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later
// Astar is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Astar 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 General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Astar. If not, see <http://www.gnu.org/licenses/>.
use super::*;
use fp_evm::FeeCalculator;
use frame_benchmarking::v2::*;
use frame_support::traits::Hooks;
use frame_system::{pallet_prelude::*, RawOrigin};
use sp_std::prelude::*;
#[benchmarks(
where
BlockNumberFor<T>: From<u32>
)]
mod benchmarks {
use super::*;
#[benchmark]
fn base_fee_per_gas_adjustment() {
let (first_block, second_block) = (1u32.into(), 2u32.into());
// Setup actions, should ensure some value is written to storage.
Pallet::<T>::on_initialize(first_block);
Pallet::<T>::on_finalize(first_block);
assert!(
BaseFeePerGas::<T>::exists(),
"Value should exist in storage after first on_finalize call"
);
Pallet::<T>::on_initialize(second_block);
let init_bfpg = BaseFeePerGas::<T>::get();
#[block]
{
Pallet::<T>::on_finalize(second_block);
}
// Ensure that the value has changed.
assert!(BaseFeePerGas::<T>::get() != init_bfpg);
}
#[benchmark]
fn set_base_fee_per_gas() {
let old_bfpg = BaseFeePerGas::<T>::get();
let new_bfpg = old_bfpg + 1;
#[extrinsic_call]
_(RawOrigin::Root, new_bfpg);
// Ensure that the value has changed.
assert_eq!(BaseFeePerGas::<T>::get(), new_bfpg);
}
#[benchmark]
fn min_gas_price() {
let first_block = 1u32.into();
// Setup actions, should ensure some value is written to storage.
Pallet::<T>::on_initialize(first_block);
Pallet::<T>::on_finalize(first_block);
assert!(
BaseFeePerGas::<T>::exists(),
"Value should exist in storage after first on_finalize call"
);
#[block]
{
let _ = Pallet::<T>::min_gas_price();
}
}
impl_benchmark_test_suite!(
Pallet,
crate::benchmarking::tests::new_test_ext(),
crate::mock::TestRuntime,
);
}
#[cfg(test)]
mod tests {
use crate::mock;
use sp_io::TestExternalities;
pub fn new_test_ext() -> TestExternalities {
mock::ExtBuilder::build()
}
}