|
| 1 | +package checks |
| 2 | + |
| 3 | +import ( |
| 4 | + "math/big" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "github.com/ethereum/go-ethereum/common" |
| 8 | + "github.com/stackup-wallet/stackup-bundler/internal/testutils" |
| 9 | +) |
| 10 | + |
| 11 | +// TestMPFLessThanGasTip calls checks.ValidateFeePerGas with a maxPriorityFeePerGas < gas tip. Expect error. |
| 12 | +func TestMPFLessThanGasTip(t *testing.T) { |
| 13 | + op := testutils.MockValidInitUserOp() |
| 14 | + gt := testutils.GetMockGasTipFunc(big.NewInt(0).Add(op.MaxPriorityFeePerGas, common.Big1)) |
| 15 | + err := ValidateFeePerGas(op, gt) |
| 16 | + |
| 17 | + if err == nil { |
| 18 | + t.Fatal("got nil, want err") |
| 19 | + } |
| 20 | +} |
| 21 | + |
| 22 | +// TestMPFEqualGasTip calls checks.ValidateFeePerGas with a maxPriorityFeePerGas == gas tip. Expect nil. |
| 23 | +func TestMPFEqualGasTip(t *testing.T) { |
| 24 | + op := testutils.MockValidInitUserOp() |
| 25 | + gt := testutils.GetMockGasTipFunc(big.NewInt(0).Add(op.MaxPriorityFeePerGas, common.Big0)) |
| 26 | + err := ValidateFeePerGas(op, gt) |
| 27 | + |
| 28 | + if err != nil { |
| 29 | + t.Fatalf("got %v, want nil", err) |
| 30 | + } |
| 31 | +} |
| 32 | + |
| 33 | +// TestMPFMoreThanGasTip calls checks.ValidateFeePerGas with a maxPriorityFeePerGas > gas tip. Expect nil. |
| 34 | +func TestMPFMoreThanGasTip(t *testing.T) { |
| 35 | + op := testutils.MockValidInitUserOp() |
| 36 | + gt := testutils.GetMockGasTipFunc(big.NewInt(0).Sub(op.MaxPriorityFeePerGas, common.Big1)) |
| 37 | + err := ValidateFeePerGas(op, gt) |
| 38 | + |
| 39 | + if err != nil { |
| 40 | + t.Fatalf("got %v, want nil", err) |
| 41 | + } |
| 42 | +} |
| 43 | + |
| 44 | +// TestMFLessThanMPF calls checks.ValidateFeePerGas with a MaxFeePerGas < maxPriorityFeePerGas. Expect error. |
| 45 | +func TestMFLessThanMPF(t *testing.T) { |
| 46 | + op := testutils.MockValidInitUserOp() |
| 47 | + gt := testutils.GetMockGasTipFunc(big.NewInt(0).Add(op.MaxPriorityFeePerGas, common.Big0)) |
| 48 | + op.MaxFeePerGas = big.NewInt(0).Sub(op.MaxPriorityFeePerGas, common.Big1) |
| 49 | + err := ValidateFeePerGas(op, gt) |
| 50 | + |
| 51 | + if err == nil { |
| 52 | + t.Fatal("got nil, want err") |
| 53 | + } |
| 54 | +} |
| 55 | + |
| 56 | +// TestMFEqualMPF calls checks.ValidateFeePerGas with a MaxFeePerGas == maxPriorityFeePerGas. Expect nil. |
| 57 | +func TestMFEqualMPF(t *testing.T) { |
| 58 | + op := testutils.MockValidInitUserOp() |
| 59 | + gt := testutils.GetMockGasTipFunc(big.NewInt(0).Add(op.MaxPriorityFeePerGas, common.Big0)) |
| 60 | + op.MaxFeePerGas = big.NewInt(0).Add(op.MaxPriorityFeePerGas, common.Big0) |
| 61 | + err := ValidateFeePerGas(op, gt) |
| 62 | + |
| 63 | + if err != nil { |
| 64 | + t.Fatalf("got %v, want nil", err) |
| 65 | + } |
| 66 | +} |
| 67 | + |
| 68 | +// TestMFMoreThanMPF calls checks.ValidateFeePerGas with a MaxFeePerGas > maxPriorityFeePerGas. Expect nil. |
| 69 | +func TestMFMoreThanMPF(t *testing.T) { |
| 70 | + op := testutils.MockValidInitUserOp() |
| 71 | + gt := testutils.GetMockGasTipFunc(big.NewInt(0).Add(op.MaxPriorityFeePerGas, common.Big0)) |
| 72 | + op.MaxFeePerGas = big.NewInt(0).Add(op.MaxPriorityFeePerGas, common.Big1) |
| 73 | + err := ValidateFeePerGas(op, gt) |
| 74 | + |
| 75 | + if err != nil { |
| 76 | + t.Fatalf("got %v, want nil", err) |
| 77 | + } |
| 78 | +} |
0 commit comments