-
Notifications
You must be signed in to change notification settings - Fork 381
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
152 additions
and
17 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// 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 frame_benchmarking::v2::*; | ||
use frame_support::traits::Hooks; | ||
use frame_system::RawOrigin; | ||
|
||
#[benchmarks] | ||
mod benchmarks { | ||
use super::*; | ||
|
||
#[benchmark] | ||
fn base_fee_per_gas_adjustment() { | ||
let (first_block, second_block) = (T::BlockNumber::from(1u32), T::BlockNumber::from(2u32)); | ||
let init_bfpg = BaseFeePerGas::<T>::get(); | ||
|
||
// Setup actions, should ensure default value is written to storage. | ||
Pallet::<T>::on_initialize(first_block); | ||
Pallet::<T>::on_finalize(first_block); | ||
Pallet::<T>::on_initialize(second_block); | ||
|
||
#[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); | ||
} | ||
|
||
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::default().build() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters