|
| 1 | +package checks |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/stackup-wallet/stackup-bundler/internal/testutils" |
| 7 | +) |
| 8 | + |
| 9 | +// TestNilPaymasterAndData calls checks.ValidatePaymasterAndData with no paymaster set. Expects nil. |
| 10 | +func TestNilPaymasterAndData(t *testing.T) { |
| 11 | + op := testutils.MockValidInitUserOp() |
| 12 | + op.PaymasterAndData = []byte{} |
| 13 | + err := ValidatePaymasterAndData(op, testutils.MockGetCodeZero, testutils.MockGetNotStakeZeroDeposit) |
| 14 | + |
| 15 | + if err != nil { |
| 16 | + t.Fatalf("got err %v, want nil", err) |
| 17 | + } |
| 18 | +} |
| 19 | + |
| 20 | +// TestBadPaymasterAndData calls checks.ValidatePaymasterAndData with invalid paymaster set. Expects error. |
| 21 | +func TestBadPaymasterAndData(t *testing.T) { |
| 22 | + op := testutils.MockValidInitUserOp() |
| 23 | + op.PaymasterAndData = []byte("1234") |
| 24 | + err := ValidatePaymasterAndData(op, testutils.MockGetCodeZero, testutils.MockGetNotStakeZeroDeposit) |
| 25 | + |
| 26 | + if err == nil { |
| 27 | + t.Fatal("got nil, want err") |
| 28 | + } |
| 29 | +} |
| 30 | + |
| 31 | +// TestZeroByteCodePaymasterAndData calls checks.ValidatePaymasterAndData with paymaster contract not |
| 32 | +// deployed. Expects error. |
| 33 | +func TestZeroByteCodePaymasterAndData(t *testing.T) { |
| 34 | + op := testutils.MockValidInitUserOp() |
| 35 | + op.PaymasterAndData = op.Sender.Bytes() |
| 36 | + err := ValidatePaymasterAndData(op, testutils.MockGetCodeZero, testutils.MockGetNotStakeZeroDeposit) |
| 37 | + |
| 38 | + if err == nil { |
| 39 | + t.Fatal("got nil, want err") |
| 40 | + } |
| 41 | +} |
| 42 | + |
| 43 | +// TestNonStakedZeroDepositPaymasterAndData calls checks.ValidatePaymasterAndData with paymaster that is not |
| 44 | +// staked with zero deposit. Expects error. |
| 45 | +func TestNonStakedZeroDepositPaymasterAndData(t *testing.T) { |
| 46 | + op := testutils.MockValidInitUserOp() |
| 47 | + op.PaymasterAndData = op.Sender.Bytes() |
| 48 | + err := ValidatePaymasterAndData(op, testutils.MockGetCode, testutils.MockGetNotStakeZeroDeposit) |
| 49 | + |
| 50 | + if err == nil { |
| 51 | + t.Fatal("got nil, want err") |
| 52 | + } |
| 53 | +} |
| 54 | + |
| 55 | +// TestZeroDepositPaymasterAndData calls checks.ValidatePaymasterAndData with paymaster that is staked but |
| 56 | +// with zero deposit. Expects error. |
| 57 | +func TestZeroDepositPaymasterAndData(t *testing.T) { |
| 58 | + op := testutils.MockValidInitUserOp() |
| 59 | + op.PaymasterAndData = op.Sender.Bytes() |
| 60 | + err := ValidatePaymasterAndData(op, testutils.MockGetCode, testutils.MockGetStakeZeroDeposit) |
| 61 | + |
| 62 | + if err == nil { |
| 63 | + t.Fatal("got nil, want err") |
| 64 | + } |
| 65 | +} |
| 66 | + |
| 67 | +// TestNotStakedPaymasterAndData calls checks.ValidatePaymasterAndData with paymaster that is not staked and |
| 68 | +// has sufficient deposit. Expects nil. |
| 69 | +func TestNotStakedPaymasterAndData(t *testing.T) { |
| 70 | + op := testutils.MockValidInitUserOp() |
| 71 | + op.PaymasterAndData = op.Sender.Bytes() |
| 72 | + err := ValidatePaymasterAndData(op, testutils.MockGetCode, testutils.MockGetNotStake) |
| 73 | + |
| 74 | + if err != nil { |
| 75 | + t.Fatalf("got %v, want nil", err) |
| 76 | + } |
| 77 | +} |
| 78 | + |
| 79 | +// TestPaymasterAndData calls checks.ValidatePaymasterAndData with paymaster that is staked and has sufficient |
| 80 | +// deposit. Expects nil. |
| 81 | +func TestPaymasterAndData(t *testing.T) { |
| 82 | + op := testutils.MockValidInitUserOp() |
| 83 | + op.PaymasterAndData = op.Sender.Bytes() |
| 84 | + err := ValidatePaymasterAndData(op, testutils.MockGetCode, testutils.MockGetStake) |
| 85 | + |
| 86 | + if err != nil { |
| 87 | + t.Fatalf("got err %v, want nil", err) |
| 88 | + } |
| 89 | +} |
0 commit comments