diff --git a/bootloader/tests/bootloader/bootloader_test.yul b/bootloader/tests/bootloader/bootloader_test.yul index cd41c45d..114f5e04 100644 --- a/bootloader/tests/bootloader/bootloader_test.yul +++ b/bootloader/tests/bootloader/bootloader_test.yul @@ -50,3 +50,51 @@ function TEST_simple_transaction() { let innerTxDataOffset := add(txDataOffset, 0x20) testing_assertEq(getGasPerPubdataByteLimit(innerTxDataOffset), 0xc350, "Invalid pubdata limit") } + +function TEST_getTransactionUpfrontOverhead() { + // For very large transactions it should be proportional to the memory, + // but for small ones, the transaction slots are more important + + let smallTxOverhead := getTransactionUpfrontOverhead(32) + let largeTxOverhead := getTransactionUpfrontOverhead(1000000) + + testing_assertEq(smallTxOverhead, TX_SLOT_OVERHEAD_GAS(), "Invalid small tx overhead") + testing_assertEq(largeTxOverhead, mul(1000000, MEMORY_OVERHEAD_GAS()), "Invalid small tx overhead") +} + +function TEST_getFeeParams_HighPubdataPrice() { + // Under very large L1 gas price, the L2 base fee will start rising to ensure the + // boundary on the gasLimit + + // 15k gwei L1 pubdata price + let veryHighL1PubdataPrice := 15000000000000 + // 0.1 gwei L2 base fee + let l2GasPrice := 100000000 + + let baseFee, gasPricePerPubdata := getFeeParams( + veryHighL1PubdataPrice, + // 0.1 gwei L2 base fee + l2GasPrice + ) + + testing_assertEq(baseFee, div(veryHighL1PubdataPrice, MAX_L2_GAS_PER_PUBDATA()), "Invalid base fee") + testing_assertEq(gasPricePerPubdata, MAX_L2_GAS_PER_PUBDATA(), "Invalid gasPricePerPubdata") +} + +function TEST_getFeeParams_LowPubdataPrice() { + // Under low to medium pubdata price, the baseFee is equal to the fair gas price, + // while the gas per pubdata pubdata is derived by strict division + + // 0.2 gwei L1 pubdata price + let veryLowL1GasPrice := 200000000 + // 0.1 gwei L2 base fee + let l2GasPrice := 100000000 + + let baseFee, gasPricePerPubdata := getFeeParams( + veryLowL1GasPrice, + l2GasPrice + ) + + testing_assertEq(baseFee, l2GasPrice, "Invalid base fee") + testing_assertEq(gasPricePerPubdata, div(veryLowL1GasPrice, l2GasPrice), "Invalid gasPricePerPubdata") +}