|
| 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 | + "github.com/stackup-wallet/stackup-bundler/pkg/gas" |
| 10 | +) |
| 11 | + |
| 12 | +// TestOpVGlessThanMaxVG calls checks.ValidateVerificationGas where verificationGas < MAX_VERIFICATION_GAS. |
| 13 | +// Expects nil. |
| 14 | +func TestOpVGlessThanMaxVG(t *testing.T) { |
| 15 | + op := testutils.MockValidInitUserOp() |
| 16 | + mvg := big.NewInt(0).Add(op.VerificationGasLimit, common.Big1) |
| 17 | + |
| 18 | + if err := ValidateVerificationGas(op, mvg); err != nil { |
| 19 | + t.Fatalf("got %v, want nil", err) |
| 20 | + } |
| 21 | +} |
| 22 | + |
| 23 | +// TestOpVGEqualMaxVG calls checks.ValidateVerificationGas where verificationGas == MAX_VERIFICATION_GAS. |
| 24 | +// Expects nil. |
| 25 | +func TestOpVGEqualMaxVG(t *testing.T) { |
| 26 | + op := testutils.MockValidInitUserOp() |
| 27 | + mvg := big.NewInt(0).Add(op.VerificationGasLimit, common.Big0) |
| 28 | + |
| 29 | + if err := ValidateVerificationGas(op, mvg); err != nil { |
| 30 | + t.Fatalf("got %v, want nil", err) |
| 31 | + } |
| 32 | +} |
| 33 | + |
| 34 | +// TestOpVGMoreThanMaxVG calls checks.ValidateVerificationGas where verificationGas > MAX_VERIFICATION_GAS. |
| 35 | +// Expects error. |
| 36 | +func TestOpVGMoreThanMaxVG(t *testing.T) { |
| 37 | + op := testutils.MockValidInitUserOp() |
| 38 | + mvg := big.NewInt(0).Sub(op.VerificationGasLimit, common.Big1) |
| 39 | + |
| 40 | + if err := ValidateVerificationGas(op, mvg); err == nil { |
| 41 | + t.Fatal("got nil, want err") |
| 42 | + } |
| 43 | +} |
| 44 | + |
| 45 | +// TestOpPVGMoreThanOH calls checks.ValidateVerificationGas where the preVerificationGas > overhead gas. |
| 46 | +// Expect nil. |
| 47 | +func TestOpPVGMoreThanOH(t *testing.T) { |
| 48 | + op := testutils.MockValidInitUserOp() |
| 49 | + pvg := gas.NewDefaultOverhead().CalcPreVerificationGas(op) |
| 50 | + op.PreVerificationGas = big.NewInt(0).Add(pvg, common.Big1) |
| 51 | + |
| 52 | + if err := ValidateVerificationGas(op, op.VerificationGasLimit); err != nil { |
| 53 | + t.Fatalf("got %v, want nil", err) |
| 54 | + } |
| 55 | +} |
| 56 | + |
| 57 | +// TestOpPVGEqualOH calls checks.ValidateVerificationGas where the preVerificationGas == overhead gas. Expect |
| 58 | +// nil. |
| 59 | +func TestOpPVGEqualOH(t *testing.T) { |
| 60 | + op := testutils.MockValidInitUserOp() |
| 61 | + pvg := gas.NewDefaultOverhead().CalcPreVerificationGas(op) |
| 62 | + op.PreVerificationGas = big.NewInt(0).Add(pvg, common.Big0) |
| 63 | + |
| 64 | + if err := ValidateVerificationGas(op, op.VerificationGasLimit); err != nil { |
| 65 | + t.Fatalf("got %v, want nil", err) |
| 66 | + } |
| 67 | +} |
| 68 | + |
| 69 | +// TestOpPVGLessThanOH calls checks.ValidateVerificationGas where the preVerificationGas < overhead gas. |
| 70 | +// Expect error. |
| 71 | +func TestOpPVGLessThanOH(t *testing.T) { |
| 72 | + op := testutils.MockValidInitUserOp() |
| 73 | + pvg := gas.NewDefaultOverhead().CalcPreVerificationGas(op) |
| 74 | + op.PreVerificationGas = big.NewInt(0).Sub(pvg, common.Big1) |
| 75 | + |
| 76 | + if err := ValidateVerificationGas(op, op.VerificationGasLimit); err == nil { |
| 77 | + t.Fatal("got nil, want err") |
| 78 | + } |
| 79 | +} |
0 commit comments