|
| 1 | +package server |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/flashbots/mev-boost/config" |
| 7 | + "github.com/flashbots/mev-boost/server/types" |
| 8 | + "github.com/sirupsen/logrus" |
| 9 | + "github.com/stretchr/testify/require" |
| 10 | +) |
| 11 | + |
| 12 | +func TestGetRelaysForValidator(t *testing.T) { |
| 13 | + relay1, err := types.NewRelayEntry("0x9000009807ed12c1f08bf4e81c6da3ba8e3fc3d953898ce0102433094e5f22f21102ec057841fcb81978ed1ea0fa8246@relay1.example.com") |
| 14 | + require.NoError(t, err) |
| 15 | + relay2, err := types.NewRelayEntry("0x9000009807ed12c1f08bf4e81c6da3ba8e3fc3d953898ce0102433094e5f22f21102ec057841fcb81978ed1ea0fa8246@relay2.example.com") |
| 16 | + require.NoError(t, err) |
| 17 | + relay3, err := types.NewRelayEntry("0x9000009807ed12c1f08bf4e81c6da3ba8e3fc3d953898ce0102433094e5f22f21102ec057841fcb81978ed1ea0fa8246@relay3.example.com") |
| 18 | + require.NoError(t, err) |
| 19 | + |
| 20 | + defaultRelays := []types.RelayEntry{relay1, relay2, relay3} |
| 21 | + |
| 22 | + muxConfig := &config.MuxConfig{ |
| 23 | + Policies: []config.Policy{ |
| 24 | + { |
| 25 | + Name: "lido-policy", |
| 26 | + Relayers: []config.Relayer{ |
| 27 | + { |
| 28 | + Name: "relay1", |
| 29 | + URL: "0x9000009807ed12c1f08bf4e81c6da3ba8e3fc3d953898ce0102433094e5f22f21102ec057841fcb81978ed1ea0fa8246@relay1.example.com", |
| 30 | + }, |
| 31 | + }, |
| 32 | + }, |
| 33 | + { |
| 34 | + Name: "rocket-policy", |
| 35 | + Relayers: []config.Relayer{ |
| 36 | + { |
| 37 | + Name: "relay2", |
| 38 | + URL: "0x9000009807ed12c1f08bf4e81c6da3ba8e3fc3d953898ce0102433094e5f22f21102ec057841fcb81978ed1ea0fa8246@relay2.example.com", |
| 39 | + }, |
| 40 | + }, |
| 41 | + }, |
| 42 | + }, |
| 43 | + Mappings: []config.Mapping{ |
| 44 | + { |
| 45 | + Name: "lido-keys", |
| 46 | + Policy: "lido-policy", |
| 47 | + Filters: config.Filters{ |
| 48 | + PublicKeys: []string{ |
| 49 | + "0x8a1d7b8dd64e0aafe7ea7b6c95065c9364cf99d38470c12ee807d55f7de1529ad29ce2c422e0b65e3d5a05c02caca249", |
| 50 | + }, |
| 51 | + }, |
| 52 | + }, |
| 53 | + { |
| 54 | + Name: "rocket-keys", |
| 55 | + Policy: "rocket-policy", |
| 56 | + Filters: config.Filters{ |
| 57 | + PublicKeys: []string{ |
| 58 | + "0x8b1d7b8dd64e0aafe7ea7b6c95065c9364cf99d38470c12ee807d55f7de1529ad29ce2c422e0b65e3d5a05c02caca249", |
| 59 | + }, |
| 60 | + }, |
| 61 | + }, |
| 62 | + }, |
| 63 | + } |
| 64 | + service := &BoostService{ |
| 65 | + relays: defaultRelays, |
| 66 | + muxConfig: muxConfig, |
| 67 | + log: logrus.NewEntry(logrus.New()), |
| 68 | + } |
| 69 | + |
| 70 | + t.Run("Validator with policy", func(t *testing.T) { |
| 71 | + lidoValidator := "0x8a1d7b8dd64e0aafe7ea7b6c95065c9364cf99d38470c12ee807d55f7de1529ad29ce2c422e0b65e3d5a05c02caca249" |
| 72 | + relays := service.getRelaysForValidator(lidoValidator) |
| 73 | + require.Len(t, relays, 1) |
| 74 | + require.Equal(t, relay1.URL.String(), relays[0].URL.String()) |
| 75 | + |
| 76 | + rocketValidator := "0x8b1d7b8dd64e0aafe7ea7b6c95065c9364cf99d38470c12ee807d55f7de1529ad29ce2c422e0b65e3d5a05c02caca249" |
| 77 | + relays = service.getRelaysForValidator(rocketValidator) |
| 78 | + require.Len(t, relays, 1) |
| 79 | + require.Equal(t, relay2.URL.String(), relays[0].URL.String()) |
| 80 | + }) |
| 81 | + |
| 82 | + t.Run("Validator without policy", func(t *testing.T) { |
| 83 | + unknownValidator := "0x8c1d7b8dd64e0aafe7ea7b6c95065c9364cf99d38470c12ee807d55f7de1529ad29ce2c422e0b65e3d5a05c02caca249" |
| 84 | + relays := service.getRelaysForValidator(unknownValidator) |
| 85 | + // should return default relays |
| 86 | + require.Len(t, relays, 3) |
| 87 | + require.Equal(t, defaultRelays, relays) |
| 88 | + }) |
| 89 | + |
| 90 | + t.Run("No mux config", func(t *testing.T) { |
| 91 | + serviceNoMux := &BoostService{ |
| 92 | + relays: defaultRelays, |
| 93 | + muxConfig: nil, |
| 94 | + log: logrus.NewEntry(logrus.New()), |
| 95 | + } |
| 96 | + |
| 97 | + lidoValidator := "0x8a1d7b8dd64e0aafe7ea7b6c95065c9364cf99d38470c12ee807d55f7de1529ad29ce2c422e0b65e3d5a05c02caca249" |
| 98 | + relays := serviceNoMux.getRelaysForValidator(lidoValidator) |
| 99 | + // should return default relays |
| 100 | + require.Len(t, relays, 3) |
| 101 | + require.Equal(t, defaultRelays, relays) |
| 102 | + }) |
| 103 | + |
| 104 | + t.Run("Invalid policy", func(t *testing.T) { |
| 105 | + invalidMuxConfig := &config.MuxConfig{ |
| 106 | + Policies: []config.Policy{ |
| 107 | + { |
| 108 | + Name: "lido-policy", |
| 109 | + Relayers: []config.Relayer{ |
| 110 | + { |
| 111 | + Name: "relay1", |
| 112 | + URL: "0x9000009807ed12c1f08bf4e81c6da3ba8e3fc3d953898ce0102433094e5f22f21102ec057841fcb81978ed1ea0fa8246@relay1.example.com", |
| 113 | + }, |
| 114 | + }, |
| 115 | + }, |
| 116 | + }, |
| 117 | + Mappings: []config.Mapping{ |
| 118 | + { |
| 119 | + Name: "rocket-keys", |
| 120 | + Policy: "rocket-policy", |
| 121 | + Filters: config.Filters{ |
| 122 | + PublicKeys: []string{ |
| 123 | + "0x8b1d7b8dd64e0aafe7ea7b6c95065c9364cf99d38470c12ee807d55f7de1529ad29ce2c422e0b65e3d5a05c02caca249", |
| 124 | + }, |
| 125 | + }, |
| 126 | + }, |
| 127 | + }, |
| 128 | + } |
| 129 | + |
| 130 | + serviceInvalid := &BoostService{ |
| 131 | + relays: defaultRelays, |
| 132 | + muxConfig: invalidMuxConfig, |
| 133 | + log: logrus.NewEntry(logrus.New()), |
| 134 | + } |
| 135 | + |
| 136 | + invalidValidator := "0x8d1d7b8dd64e0aafe7ea7b6c95065c9364cf99d38470c12ee807d55f7de1529ad29ce2c422e0b65e3d5a05c02caca249" |
| 137 | + relays := serviceInvalid.getRelaysForValidator(invalidValidator) |
| 138 | + // should return default relays |
| 139 | + require.Len(t, relays, 3) |
| 140 | + require.Equal(t, defaultRelays, relays) |
| 141 | + }) |
| 142 | +} |
0 commit comments