Skip to content

Commit

Permalink
fix: handle nil values
Browse files Browse the repository at this point in the history
  • Loading branch information
Alok committed Aug 8, 2024
1 parent 1e243a4 commit ddf8f79
Showing 1 changed file with 30 additions and 13 deletions.
43 changes: 30 additions & 13 deletions testing/pkg/tests/connectivity/connectivity.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

debugapiv1 "github.com/primev/mev-commit/p2p/gen/go/debugapi/v1"
"github.com/primev/mev-commit/testing/pkg/orchestrator"
"google.golang.org/protobuf/types/known/structpb"
)

const (
Expand All @@ -33,21 +34,17 @@ func Run(ctx context.Context, cluster orchestrator.Orchestrator, _ any) error {
return fmt.Errorf("failed to get topology: %s", err)
}

connectedBidders := topo.Topology.GetFields()["connected_bidders"].GetListValue()
if len(connectedBidders.Values) != len(bidders) {
connectedBidders := getBidders(topo)
if len(connectedBidders) != len(bidders) {
break
}

if topo.Topology.GetFields()["connected_providers"] == nil {
connectedProviders := getProviders(topo)
if len(connectedProviders) != len(providers) {
break
}

connectedProviders := topo.Topology.GetFields()["connected_providers"].GetListValue()
if len(connectedProviders.Values) != len(providers) {
break
}

for _, p := range connectedProviders.Values {
for _, p := range connectedProviders {
if !slices.ContainsFunc(providers, func(p1 orchestrator.Provider) bool {
return p1.EthAddress() == p.GetStringValue()
}) {
Expand All @@ -56,7 +53,7 @@ func Run(ctx context.Context, cluster orchestrator.Orchestrator, _ any) error {
}
}

for _, b := range connectedBidders.Values {
for _, b := range connectedBidders {
if !slices.ContainsFunc(bidders, func(b1 orchestrator.Bidder) bool {
return b1.EthAddress() == b.GetStringValue()
}) {
Expand Down Expand Up @@ -89,13 +86,13 @@ func Run(ctx context.Context, cluster orchestrator.Orchestrator, _ any) error {
return fmt.Errorf("failed to get topology: %s", err)
}

connectedProviders := topo.Topology.GetFields()["connected_providers"].GetListValue()
if len(connectedProviders.Values) != len(providers) {
connectedProviders := getProviders(topo)
if len(connectedProviders) != len(providers) {
l.Error("bidder not connected to all providers")
return fmt.Errorf("bidder not connected to all providers: %s", b.EthAddress())
}

for _, p := range connectedProviders.Values {
for _, p := range connectedProviders {
if !slices.ContainsFunc(providers, func(p1 orchestrator.Provider) bool {
return p1.EthAddress() == p.GetStringValue()
}) {
Expand All @@ -111,3 +108,23 @@ func Run(ctx context.Context, cluster orchestrator.Orchestrator, _ any) error {

return nil
}

func getProviders(topo *debugapiv1.TopologyResponse) []*structpb.Value {
providerList := topo.Topology.GetFields()["connected_providers"]
if providerList == nil {
return nil
}

connectedProviders := providerList.GetListValue()
return connectedProviders.Values
}

func getBidders(topo *debugapiv1.TopologyResponse) []*structpb.Value {
bidderList := topo.Topology.GetFields()["connected_bidders"]
if bidderList == nil {
return nil
}

connectedBidders := bidderList.GetListValue()
return connectedBidders.Values
}

0 comments on commit ddf8f79

Please sign in to comment.