mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 08:51:09 +00:00
Impl transaction-payment GenesisConfig with NextFeeMultplier support (#12177)
* Impl GenesisConfig with NextFeeMultplier support * Update lib.rs * Use documented const * Unit test multiplier genesis * fmt Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
This commit is contained in:
@@ -241,6 +241,10 @@ impl Default for Releases {
|
||||
}
|
||||
}
|
||||
|
||||
/// Default value for NextFeeMultiplier. This is used in genesis and is also used in
|
||||
/// NextFeeMultiplierOnEmpty() to provide a value when none exists in storage.
|
||||
const MULTIPLIER_DEFAULT_VALUE: Multiplier = Multiplier::from_u32(1);
|
||||
|
||||
#[frame_support::pallet]
|
||||
pub mod pallet {
|
||||
use super::*;
|
||||
@@ -300,7 +304,7 @@ pub mod pallet {
|
||||
|
||||
#[pallet::type_value]
|
||||
pub fn NextFeeMultiplierOnEmpty() -> Multiplier {
|
||||
Multiplier::saturating_from_integer(1)
|
||||
MULTIPLIER_DEFAULT_VALUE
|
||||
}
|
||||
|
||||
#[pallet::storage]
|
||||
@@ -312,12 +316,14 @@ pub mod pallet {
|
||||
pub(super) type StorageVersion<T: Config> = StorageValue<_, Releases, ValueQuery>;
|
||||
|
||||
#[pallet::genesis_config]
|
||||
pub struct GenesisConfig;
|
||||
pub struct GenesisConfig {
|
||||
pub multiplier: Multiplier,
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl Default for GenesisConfig {
|
||||
fn default() -> Self {
|
||||
Self
|
||||
Self { multiplier: MULTIPLIER_DEFAULT_VALUE }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -325,6 +331,7 @@ pub mod pallet {
|
||||
impl<T: Config> GenesisBuild<T> for GenesisConfig {
|
||||
fn build(&self) {
|
||||
StorageVersion::<T>::put(Releases::V2);
|
||||
NextFeeMultiplier::<T>::put(self.multiplier);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -816,7 +823,7 @@ mod tests {
|
||||
|
||||
use frame_support::{
|
||||
assert_noop, assert_ok, parameter_types,
|
||||
traits::{ConstU32, ConstU64, Currency, Imbalance, OnUnbalanced},
|
||||
traits::{ConstU32, ConstU64, Currency, GenesisBuild, Imbalance, OnUnbalanced},
|
||||
weights::{
|
||||
DispatchClass, DispatchInfo, GetDispatchInfo, PostDispatchInfo, Weight,
|
||||
WeightToFee as WeightToFeeT,
|
||||
@@ -958,11 +965,18 @@ mod tests {
|
||||
base_weight: Weight,
|
||||
byte_fee: u64,
|
||||
weight_to_fee: u64,
|
||||
initial_multiplier: Option<Multiplier>,
|
||||
}
|
||||
|
||||
impl Default for ExtBuilder {
|
||||
fn default() -> Self {
|
||||
Self { balance_factor: 1, base_weight: Weight::zero(), byte_fee: 1, weight_to_fee: 1 }
|
||||
Self {
|
||||
balance_factor: 1,
|
||||
base_weight: Weight::zero(),
|
||||
byte_fee: 1,
|
||||
weight_to_fee: 1,
|
||||
initial_multiplier: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -983,6 +997,10 @@ mod tests {
|
||||
self.balance_factor = factor;
|
||||
self
|
||||
}
|
||||
pub fn with_initial_multiplier(mut self, multiplier: Multiplier) -> Self {
|
||||
self.initial_multiplier = Some(multiplier);
|
||||
self
|
||||
}
|
||||
fn set_constants(&self) {
|
||||
EXTRINSIC_BASE_WEIGHT.with(|v| *v.borrow_mut() = self.base_weight);
|
||||
TRANSACTION_BYTE_FEE.with(|v| *v.borrow_mut() = self.byte_fee);
|
||||
@@ -1007,6 +1025,12 @@ mod tests {
|
||||
}
|
||||
.assimilate_storage(&mut t)
|
||||
.unwrap();
|
||||
|
||||
if let Some(multiplier) = self.initial_multiplier {
|
||||
let genesis = pallet::GenesisConfig { multiplier };
|
||||
GenesisBuild::<Runtime>::assimilate_storage(&genesis, &mut t).unwrap();
|
||||
}
|
||||
|
||||
t.into()
|
||||
}
|
||||
}
|
||||
@@ -1720,4 +1744,24 @@ mod tests {
|
||||
assert_eq!(refund_based_fee, actual_fee);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn genesis_config_works() {
|
||||
ExtBuilder::default()
|
||||
.with_initial_multiplier(Multiplier::from_u32(100))
|
||||
.build()
|
||||
.execute_with(|| {
|
||||
assert_eq!(
|
||||
<NextFeeMultiplier<Runtime>>::get(),
|
||||
Multiplier::saturating_from_integer(100)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn genesis_default_works() {
|
||||
ExtBuilder::default().build().execute_with(|| {
|
||||
assert_eq!(<NextFeeMultiplier<Runtime>>::get(), Multiplier::saturating_from_integer(1));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user