Skip to content

Commit

Permalink
feat: improve test full block fee is correct #465 (#466)
Browse files Browse the repository at this point in the history
feat: improved test full_block_fee_is_correct to calculate the expected max block fee
  • Loading branch information
brandonpille authored Oct 3, 2022
1 parent 54934a5 commit 409e97a
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions substrate-node/runtime/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,17 @@ mod tests {
fn full_block_fee_is_correct() {
// A full block should cost 23.3112 DOLLARS
log::info!("MaxBlockWeight: {:?}", MaximumBlockWeight::get());
log::info!("BaseWeight: {:?}", ExtrinsicBaseWeight::get());
// we multiply by 100 to avoid loss of precision after division and devide by 100 at the end
let precision = 100;
let max_block_weight: u128 = (MaximumBlockWeight::get() as u128) * precision;
let ext_base_weight: u128 = ExtrinsicBaseWeight::get() as u128;
let x = WeightToFeeStruct::weight_to_fee(&MaximumBlockWeight::get());
let y = 2331120 * MILLICENTS;
assert!(x.max(y) - x.min(y) < MILLICENTS);
let cost_extrinsic:u128 = WeightToFeeStruct::weight_to_fee(&ExtrinsicBaseWeight::get());
let y:u128 = (cost_extrinsic * (max_block_weight/ext_base_weight)) / precision;
// Difference should be less then the cost of an extrinsic devided by 2 as we can execute Z amount of extrinsics and Z was calculated by deviding
// the max amount of weight per block by the weight of one extrinsic. That operation results in a loss of precision (from float to integer).
assert!(x.max(y) - x.min(y) < cost_extrinsic / 2);
}

#[test]
Expand Down

0 comments on commit 409e97a

Please sign in to comment.