Skip to content

Commit

Permalink
Fee Adjustment Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriele-0201 authored and rphmeier committed Dec 28, 2023
1 parent 796f883 commit 6cd1350
Show file tree
Hide file tree
Showing 4 changed files with 588 additions and 56 deletions.
41 changes: 3 additions & 38 deletions sugondat-chain/runtimes/sugondat-kusama/src/fee_adjustment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,9 @@ where
let max_multiplier = MaximumMultiplierBlockSize::get();
let previous_len_multiplier = previous_len_multiplier.max(min_multiplier);

// Pick the limiting dimension. (from TargetedFeeAdjustment::convert)
//
// In this case it is the length of all extrinsic, always
// The limiting dimension is the length of all extrinsic
let (normal_limiting_dimension, max_limiting_dimension) = (
<frame_system::Pallet<T>>::all_extrinsics_len(),
<frame_system::Pallet<T>>::all_extrinsics_len().min(MAXIMUM_BLOCK_LENGTH),
MAXIMUM_BLOCK_LENGTH as u64,
);

Expand Down Expand Up @@ -197,7 +195,7 @@ impl<T: frame_system::Config> sp_weights::WeightToFee for BlobsLengthToFee<T> {
#[cfg(test)]
mod tests {
use super::*;
use crate::{MaxBlobSize, Runtime};
use crate::Runtime;
use sp_runtime::BuildStorage;

fn new_test_ext() -> sp_io::TestExternalities {
Expand Down Expand Up @@ -225,37 +223,4 @@ mod tests {
);
});
}

#[test]
fn test_blobs_fee_adjustment_convert() {
use codec::Encode;
use sp_core::twox_128;

for len in (0..MaxBlobSize::get()).into_iter().step_by(100) {
new_test_ext().execute_with(|| {
// AllExtrinsicsLen is a private storage value of the system pallet
// so the key must be manually constructed
sp_io::storage::set(
&[twox_128(b"System"), twox_128(b"AllExtrinsicsLen")].concat(),
&len.encode(),
);

let fee_multiplier = Multiplier::saturating_from_rational(7, 8);

let new_fee_multiplier = BlobsFeeAdjustment::<Runtime>::convert(fee_multiplier);

// fee_multiplier should follow the standard behavior
let expected_fee_multiplier = TargetedFeeAdjustment::<
Runtime,
TargetBlockFullness,
AdjustmentVariableBlockFullness,
MinimumMultiplierBlockFullness,
MaximumMultiplierBlockFullness,
>::convert(fee_multiplier);
assert_eq!(new_fee_multiplier, expected_fee_multiplier);

// TODO: Ensure length multiplier is update properly
});
}
}
}
Loading

0 comments on commit 6cd1350

Please sign in to comment.