Skip to content
This repository was archived by the owner on Mar 13, 2023. It is now read-only.

Commit 7f0417c

Browse files
Fix test
1 parent e85c3cb commit 7f0417c

File tree

1 file changed

+57
-61
lines changed
  • frame/dvm-dynamic-fee/src

1 file changed

+57
-61
lines changed

frame/dvm-dynamic-fee/src/lib.rs

+57-61
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,26 @@
1717

1818
#![cfg_attr(not(feature = "std"), no_std)]
1919

20-
// #[cfg(test)]
21-
// mod mock;
22-
// #[cfg(test)]
23-
// mod tests;
20+
// --- substrate ---
21+
use sp_core::U256;
22+
#[cfg(feature = "std")]
23+
use sp_inherents::InherentDataProvider as InherentDataProviderT;
24+
use sp_inherents::{Error, InherentData, InherentIdentifier, IsFatalError};
25+
use sp_runtime::RuntimeDebug;
26+
// --- darwinia ---
27+
use darwinia_evm::FeeCalculator;
28+
// --- core ---
29+
use codec::{Decode, Encode};
30+
use core::cmp;
31+
32+
pub use pallet::*;
33+
pub const INHERENT_IDENTIFIER: InherentIdentifier = *b"dynfee0_";
2434

2535
#[frame_support::pallet]
2636
pub mod pallet {
27-
// --- core ---
28-
use core::cmp;
29-
// --- substrate ---
37+
use super::*;
3038
use frame_support::pallet_prelude::*;
3139
use frame_system::pallet_prelude::*;
32-
use sp_core::U256;
33-
#[cfg(feature = "std")]
34-
use sp_inherents::InherentDataProvider as InherentDataProviderT;
35-
use sp_inherents::{Error, IsFatalError};
36-
// --- darwinia ---
37-
use darwinia_evm::FeeCalculator;
38-
39-
pub type InherentType = U256;
40-
41-
pub const INHERENT_IDENTIFIER: InherentIdentifier = *b"dynfee0_";
4240

4341
#[pallet::config]
4442
pub trait Config: frame_system::Config {
@@ -56,16 +54,12 @@ pub mod pallet {
5654
#[pallet::storage]
5755
pub type TargetMinGasPrice<T> = StorageValue<_, U256, OptionQuery>;
5856

59-
#[cfg_attr(feature = "std", derive(Default))]
6057
#[pallet::genesis_config]
61-
pub struct GenesisConfig {
62-
pub min_gas_price: U256,
63-
}
58+
#[derive(Default)]
59+
pub struct GenesisConfig;
6460
#[pallet::genesis_build]
6561
impl<T: Config> GenesisBuild<T> for GenesisConfig {
66-
fn build(&self) {
67-
<MinGasPrice<T>>::put(self.min_gas_price);
68-
}
62+
fn build(&self) {}
6963
}
7064

7165
#[pallet::pallet]
@@ -99,15 +93,11 @@ pub mod pallet {
9993
ensure_none(origin)?;
10094

10195
<TargetMinGasPrice<T>>::set(Some(target));
102-
10396
Ok(().into())
10497
}
10598
}
106-
impl<T: Config> FeeCalculator for Pallet<T> {
107-
fn min_gas_price() -> U256 {
108-
<MinGasPrice<T>>::get()
109-
}
110-
}
99+
100+
#[pallet::inherent]
111101
impl<T: Config> ProvideInherent for Pallet<T> {
112102
type Call = Call<T>;
113103
type Error = InherentError;
@@ -116,7 +106,6 @@ pub mod pallet {
116106

117107
fn create_inherent(data: &InherentData) -> Option<Self::Call> {
118108
let target = data.get_data::<InherentType>(&INHERENT_IDENTIFIER).ok()??;
119-
120109
Some(Call::note_min_gas_price_target(target))
121110
}
122111

@@ -128,42 +117,49 @@ pub mod pallet {
128117
true
129118
}
130119
}
120+
}
121+
122+
impl<T: Config> FeeCalculator for Pallet<T> {
123+
fn min_gas_price() -> U256 {
124+
<MinGasPrice<T>>::get()
125+
}
126+
}
131127

132-
#[derive(Encode, Decode, RuntimeDebug)]
133-
pub enum InherentError {}
134-
impl IsFatalError for InherentError {
135-
fn is_fatal_error(&self) -> bool {
136-
match *self {}
137-
}
128+
#[derive(Encode, Decode, RuntimeDebug)]
129+
pub enum InherentError {}
130+
impl IsFatalError for InherentError {
131+
fn is_fatal_error(&self) -> bool {
132+
match *self {}
138133
}
134+
}
139135

140-
#[cfg(feature = "std")]
141-
pub struct InherentDataProvider(pub InherentType);
142-
#[cfg(feature = "std")]
143-
impl InherentDataProvider {
144-
pub fn from_target_gas_price(price: InherentType) -> Self {
145-
Self(price)
146-
}
136+
pub type InherentType = U256;
137+
#[cfg(feature = "std")]
138+
pub struct InherentDataProvider(pub InherentType);
139+
#[cfg(feature = "std")]
140+
impl InherentDataProvider {
141+
pub fn from_target_gas_price(price: InherentType) -> Self {
142+
Self(price)
147143
}
148-
#[cfg(feature = "std")]
149-
#[async_trait::async_trait]
150-
impl InherentDataProviderT for InherentDataProvider {
151-
fn provide_inherent_data(&self, inherent_data: &mut InherentData) -> Result<(), Error> {
152-
inherent_data.put_data(INHERENT_IDENTIFIER, &self.0)
153-
}
144+
}
154145

155-
async fn try_handle_error(
156-
&self,
157-
identifier: &InherentIdentifier,
158-
error: &[u8],
159-
) -> Option<Result<(), Error>> {
160-
if *identifier != INHERENT_IDENTIFIER {
161-
return None;
162-
}
146+
#[cfg(feature = "std")]
147+
#[async_trait::async_trait]
148+
impl InherentDataProviderT for InherentDataProvider {
149+
fn provide_inherent_data(&self, inherent_data: &mut InherentData) -> Result<(), Error> {
150+
inherent_data.put_data(INHERENT_IDENTIFIER, &self.0)
151+
}
163152

164-
let error = InherentError::decode(&mut &error[..]).ok()?;
165-
Some(Err(Error::Application(Box::from(format!("{:?}", error)))))
153+
async fn try_handle_error(
154+
&self,
155+
identifier: &InherentIdentifier,
156+
error: &[u8],
157+
) -> Option<Result<(), Error>> {
158+
if *identifier != INHERENT_IDENTIFIER {
159+
return None;
166160
}
161+
162+
let error = InherentError::decode(&mut &error[..]).ok()?;
163+
Some(Err(Error::Application(Box::from(format!("{:?}", error)))))
167164
}
168165
}
169-
pub use pallet::*;

0 commit comments

Comments
 (0)