Commit 769fe00f authored by Jason Yellick's avatar Jason Yellick

op-e2e: Fix bug in TestWithdrawals

The existing TestWithdrawals test attempts to assert that the total fees
of the prove and finalize transactions are accounted for in the L1
balance.  But, it re-uses the `calcGasFees` function and passes in the
`GasTipCap` and the `GasFeeCap` from the L2 transaction, not from the
actual L1 transactions.  In the event that the gas fee differs on the L2
from the L1, then the test will fail.

To keep the diff small, this change simply multiplies the GasUsed and
`EffectiveGasPrice` from the receipts.  This could be moved into a
helper function like `calcGasFees`.  Using the `EffectiveGasPrice` seems
just as good or better than relying on the parameters of the original
transaction, and could be similarly utilized higher in the test for the
L2 fees.  If we really want to get the parameters from the tx, then
`ProveAndFinalizeWithdrawal` would need to be modified to return the
txes.
parent f63e3231
...@@ -1084,11 +1084,6 @@ func TestWithdrawals(t *testing.T) { ...@@ -1084,11 +1084,6 @@ func TestWithdrawals(t *testing.T) {
proveReceipt, finalizeReceipt := ProveAndFinalizeWithdrawal(t, cfg, l1Client, sys.Nodes["verifier"], ethPrivKey, receipt) proveReceipt, finalizeReceipt := ProveAndFinalizeWithdrawal(t, cfg, l1Client, sys.Nodes["verifier"], ethPrivKey, receipt)
// Verify balance after withdrawal // Verify balance after withdrawal
ctx, cancel = context.WithTimeout(context.Background(), 1*time.Second)
defer cancel()
header, err = l1Client.HeaderByNumber(ctx, finalizeReceipt.BlockNumber)
require.Nil(t, err)
ctx, cancel = context.WithTimeout(context.Background(), 1*time.Second) ctx, cancel = context.WithTimeout(context.Background(), 1*time.Second)
defer cancel() defer cancel()
endBalance, err = l1Client.BalanceAt(ctx, fromAddr, nil) endBalance, err = l1Client.BalanceAt(ctx, fromAddr, nil)
...@@ -1098,7 +1093,9 @@ func TestWithdrawals(t *testing.T) { ...@@ -1098,7 +1093,9 @@ func TestWithdrawals(t *testing.T) {
// Fun fact, the fee is greater than the withdrawal amount // Fun fact, the fee is greater than the withdrawal amount
// NOTE: The gas fees include *both* the ProveWithdrawalTransaction and FinalizeWithdrawalTransaction transactions. // NOTE: The gas fees include *both* the ProveWithdrawalTransaction and FinalizeWithdrawalTransaction transactions.
diff = new(big.Int).Sub(endBalance, startBalance) diff = new(big.Int).Sub(endBalance, startBalance)
fees = calcGasFees(proveReceipt.GasUsed+finalizeReceipt.GasUsed, tx.GasTipCap(), tx.GasFeeCap(), header.BaseFee) proveFee := new(big.Int).Mul(new(big.Int).SetUint64(proveReceipt.GasUsed), proveReceipt.EffectiveGasPrice)
finalizeFee := new(big.Int).Mul(new(big.Int).SetUint64(finalizeReceipt.GasUsed), finalizeReceipt.EffectiveGasPrice)
fees = new(big.Int).Add(proveFee, finalizeFee)
withdrawAmount = withdrawAmount.Sub(withdrawAmount, fees) withdrawAmount = withdrawAmount.Sub(withdrawAmount, fees)
require.Equal(t, withdrawAmount, diff) require.Equal(t, withdrawAmount, diff)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment