Skip to content

Commit

Permalink
Update Lib1559Math.t.sol
Browse files Browse the repository at this point in the history
  • Loading branch information
dantaik committed Mar 28, 2024
1 parent b94d685 commit 944db01
Showing 1 changed file with 10 additions and 21 deletions.
31 changes: 10 additions & 21 deletions packages/protocol/test/L2/Lib1559Math.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,19 @@ contract TestLib1559Math is TaikoTest {
using LibMath for uint256;

function test_eip1559_math() external {
uint256 gasTarget = 15 * 1e6 * 10;
uint256 gasTarget = 60_000_000;
uint256 adjustmentQuotient = 8;
uint256 adjustmentFactor = gasTarget * adjustmentQuotient;
// The expected values are calculated in eip1559_util.py
_assertAmostEq(
999_999_916,
Lib1559Math.basefee({ _gasExcess: 49_954_623_777, _adjustmentFactor: adjustmentFactor })
);

_assertAmostEq(
48_246_703_821_869_050_543_408_253_349_256_099_602_613_005_189_120,
Lib1559Math.basefee({
_gasExcess: LibFixedPointMath.MAX_EXP_INPUT * adjustmentFactor
/ LibFixedPointMath.SCALING_FACTOR,
_adjustmentFactor: adjustmentFactor
})
);
}
uint256 baseFee;
uint256 i;
for (; baseFee < 1 gwei; ++i) {
baseFee = Lib1559Math.basefee(gasTarget * i, adjustmentFactor);
console2.log("baseFee:", i, baseFee);
}

// Assert the different between two number is smaller than 1/1000000
function _assertAmostEq(uint256 _a, uint256 _b) private {
uint256 min = _a.min(_b);
uint256 max = _a.max(_b);
assertTrue(max > 0 && ((max - min) * 1_000_000) / max <= 1);
console2.log(_a, " <> ", _b);
// basefee will reach 1 gwei if gasExcess > 19620000000
console2.log("basefee will reach 1 gwei if gasExcess >", gasTarget * i);
assertEq(i, 327);
}
}

0 comments on commit 944db01

Please sign in to comment.