@@ -191,3 +191,69 @@ impl<T: frame_system::Config> sp_weights::WeightToFee for BlobsLengthToFee<T> {
191
191
multiplier. saturating_mul_int ( length_fee)
192
192
}
193
193
}
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
+ }
0 commit comments