|
| 1 | +package altmempools_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "math/big" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "github.com/stackup-wallet/stackup-bundler/internal/testutils" |
| 8 | + "github.com/stackup-wallet/stackup-bundler/pkg/altmempools" |
| 9 | +) |
| 10 | + |
| 11 | +func TestDirectoryHasSingleInvalidStorageAccessException(t *testing.T) { |
| 12 | + id := "1" |
| 13 | + alts := []*altmempools.Config{ |
| 14 | + {Id: id, Data: testutils.AltMempoolMock()}, |
| 15 | + } |
| 16 | + dir, err := altmempools.New(testutils.ChainID, alts) |
| 17 | + if err != nil { |
| 18 | + t.Fatal("error initializing directory") |
| 19 | + } |
| 20 | + |
| 21 | + mempools := dir.HasInvalidStorageAccessException( |
| 22 | + "account", |
| 23 | + "0x0000000000000000000000000000000000000000", |
| 24 | + "0x0000000000000000000000000000000000000000", |
| 25 | + ) |
| 26 | + if len(mempools) != 1 || mempools[0] != id { |
| 27 | + t.Fatalf("got %v, want [1]", mempools) |
| 28 | + } |
| 29 | +} |
| 30 | + |
| 31 | +func TestDirectoryHasManyInvalidStorageAccessExceptions(t *testing.T) { |
| 32 | + id1 := "1" |
| 33 | + id2 := "2" |
| 34 | + alts := []*altmempools.Config{ |
| 35 | + {Id: id1, Data: testutils.AltMempoolMock()}, |
| 36 | + {Id: id2, Data: testutils.AltMempoolMock()}, |
| 37 | + } |
| 38 | + dir, err := altmempools.New(testutils.ChainID, alts) |
| 39 | + if err != nil { |
| 40 | + t.Fatal("error initializing directory") |
| 41 | + } |
| 42 | + |
| 43 | + mempools := dir.HasInvalidStorageAccessException( |
| 44 | + "account", |
| 45 | + "0x0000000000000000000000000000000000000000", |
| 46 | + "0x0000000000000000000000000000000000000000", |
| 47 | + ) |
| 48 | + if len(mempools) != 2 || mempools[0] != id1 && mempools[1] != id2 { |
| 49 | + t.Fatalf("got %v, want [1 2]", mempools) |
| 50 | + } |
| 51 | +} |
| 52 | + |
| 53 | +func TestDirectoryHasNoInvalidStorageAccessExceptions(t *testing.T) { |
| 54 | + id := "1" |
| 55 | + alts := []*altmempools.Config{ |
| 56 | + {Id: id, Data: testutils.AltMempoolMock()}, |
| 57 | + } |
| 58 | + dir, err := altmempools.New(testutils.ChainID, alts) |
| 59 | + if err != nil { |
| 60 | + t.Fatal("error initializing directory") |
| 61 | + } |
| 62 | + |
| 63 | + mempools := dir.HasInvalidStorageAccessException( |
| 64 | + "paymaster", |
| 65 | + "0x0000000000000000000000000000000000000000", |
| 66 | + "0x0000000000000000000000000000000000000000", |
| 67 | + ) |
| 68 | + if len(mempools) != 0 { |
| 69 | + t.Fatalf("got %v, want []", mempools) |
| 70 | + } |
| 71 | +} |
| 72 | + |
| 73 | +func TestDirectoryIncompatibleChain(t *testing.T) { |
| 74 | + alts := []*altmempools.Config{ |
| 75 | + {Id: "1", Data: testutils.AltMempoolMock()}, |
| 76 | + } |
| 77 | + dir, err := altmempools.New(big.NewInt(2), alts) |
| 78 | + if err != nil { |
| 79 | + t.Fatal("error initializing directory") |
| 80 | + } |
| 81 | + |
| 82 | + mempools := dir.HasInvalidStorageAccessException( |
| 83 | + "account", |
| 84 | + "0x0000000000000000000000000000000000000000", |
| 85 | + "0x0000000000000000000000000000000000000000", |
| 86 | + ) |
| 87 | + if len(mempools) != 0 { |
| 88 | + t.Fatalf("got %v, want []", mempools) |
| 89 | + } |
| 90 | +} |
0 commit comments