Skip to content

Commit 2e0a93f

Browse files
committed
Unit Testing Blobs Fees Adjustments
1 parent 4b7e1b3 commit 2e0a93f

File tree

2 files changed

+66
-19
lines changed

2 files changed

+66
-19
lines changed

sugondat-chain/runtimes/sugondat-kusama/src/fee_adjustment.rs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,3 +191,69 @@ impl<T: frame_system::Config> sp_weights::WeightToFee for BlobsLengthToFee<T> {
191191
multiplier.saturating_mul_int(length_fee)
192192
}
193193
}
194+
195+
#[cfg(test)]
196+
mod tests {
197+
use super::*;
198+
use crate::{MaxBlobSize, Runtime};
199+
use sp_runtime::BuildStorage;
200+
201+
fn new_test_ext() -> sp_io::TestExternalities {
202+
frame_system::GenesisConfig::<Runtime>::default()
203+
.build_storage()
204+
.unwrap()
205+
.into()
206+
}
207+
208+
#[test]
209+
fn test_length_to_fee() {
210+
// Test that inclusion fee is evaluated propertly
211+
// following what done in BlobsLengthToFee
212+
new_test_ext().execute_with(|| {
213+
let len = 123;
214+
let multiplier = Multiplier::saturating_from_integer(12);
215+
NextLengthMultiplier::set(&multiplier);
216+
217+
let length_fee = len * TransactionByteFee::get();
218+
let expected = multiplier.saturating_mul_int(length_fee);
219+
220+
assert_eq!(
221+
pallet_transaction_payment::Pallet::<Runtime>::length_to_fee(len as u32),
222+
expected
223+
);
224+
});
225+
}
226+
227+
#[test]
228+
fn test_blobs_fee_adjustment_convert() {
229+
use codec::Encode;
230+
use sp_core::twox_128;
231+
232+
for len in (0..MaxBlobSize::get()).into_iter().step_by(100) {
233+
new_test_ext().execute_with(|| {
234+
// AllExtrinsicsLen is a private storage value of the system pallet
235+
// so the key must be manually constructed
236+
sp_io::storage::set(
237+
&[twox_128(b"System"), twox_128(b"AllExtrinsicsLen")].concat(),
238+
&len.encode(),
239+
);
240+
241+
let fee_multiplier = Multiplier::saturating_from_rational(7, 8);
242+
243+
let new_fee_multiplier = BlobsFeeAdjustment::<Runtime>::convert(fee_multiplier);
244+
245+
// fee_multiplier should follow the standard behavior
246+
let expected_fee_multiplier = TargetedFeeAdjustment::<
247+
Runtime,
248+
TargetBlockFullness,
249+
AdjustmentVariableBlockFullness,
250+
MinimumMultiplierBlockFullness,
251+
MaximumMultiplierBlockFullness,
252+
>::convert(fee_multiplier);
253+
assert_eq!(new_fee_multiplier, expected_fee_multiplier);
254+
255+
// TODO: Ensure length multiplier is update properly
256+
});
257+
}
258+
}
259+
}

sugondat-chain/runtimes/sugondat-kusama/tests/integration_test.rs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -163,25 +163,6 @@ fn test_pre_dispatch_max_total_blob_size_exceeded() {
163163
});
164164
}
165165

166-
#[test]
167-
fn test_length_to_fee() {
168-
// Test that inclusion fee is evaluated propertly
169-
// following what done in BlobsLengthToFee
170-
new_test_ext().execute_with(|| {
171-
let len = 123;
172-
let multiplier = Multiplier::saturating_from_integer(12);
173-
NextLengthMultiplier::set(&multiplier);
174-
175-
let length_fee = len * TransactionByteFee::get();
176-
let expected = multiplier.saturating_mul_int(length_fee);
177-
178-
assert_eq!(
179-
pallet_transaction_payment::Pallet::<Runtime>::length_to_fee(len as u32),
180-
expected
181-
);
182-
});
183-
}
184-
185166
#[test]
186167
fn test_inclusion_fee() {
187168
// Test that inclusion fee is evaluated propertly

0 commit comments

Comments
 (0)