From c8e16a407ccf85103567e74f5e4b533b75eff976 Mon Sep 17 00:00:00 2001 From: blade Date: Wed, 22 May 2024 09:43:36 -0500 Subject: [PATCH] different chains --- internal/apps_registry/cached_app_registry.go | 9 +- .../apps_registry/cached_app_registry_test.go | 101 ++++++++++++++++++ 2 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 internal/apps_registry/cached_app_registry_test.go diff --git a/internal/apps_registry/cached_app_registry.go b/internal/apps_registry/cached_app_registry.go index 8548c69..ef806fc 100644 --- a/internal/apps_registry/cached_app_registry.go +++ b/internal/apps_registry/cached_app_registry.go @@ -174,9 +174,16 @@ func arePoktApplicationSignersEqual(slice1, slice2 []*models.PoktApplicationSign // Now that slices are sorted, check if address keys are same. for i := range slice1 { // Check if any field is different - if !strings.EqualFold(sortedSlice1[i].NetworkApp.Address, sortedSlice2[i].NetworkApp.Address) { + networkApp1 := sortedSlice1[i].NetworkApp + networkApp2 := sortedSlice2[i].NetworkApp + if !strings.EqualFold(networkApp1.Address, networkApp2.Address) { return false } + + if !strings.EqualFold(strings.Join(networkApp1.Chains, ","), strings.Join(networkApp2.Chains, ",")) { + return false + } + } // Slices are equal diff --git a/internal/apps_registry/cached_app_registry_test.go b/internal/apps_registry/cached_app_registry_test.go new file mode 100644 index 0000000..343ce5e --- /dev/null +++ b/internal/apps_registry/cached_app_registry_test.go @@ -0,0 +1,101 @@ +package apps_registry + +import ( + "github.com/pokt-network/gateway-server/internal/apps_registry/models" + pokt_models "github.com/pokt-network/gateway-server/pkg/pokt/pokt_v0/models" + "testing" +) + +func Test_arePoktApplicationSignersEqual(t *testing.T) { + type args struct { + slice1 []*models.PoktApplicationSigner + slice2 []*models.PoktApplicationSigner + } + tests := []struct { + name string + args args + want bool + }{ + { + name: "different length", + args: args{ + slice1: []*models.PoktApplicationSigner{}, + slice2: []*models.PoktApplicationSigner{{NetworkApp: &pokt_models.PoktApplication{ + Address: "123", + Chains: []string{"123", "123"}, + PublicKey: "", + Status: 0, + MaxRelays: 0, + }}}, + }, + want: false, + }, + { + name: "different address", + args: args{ + slice1: []*models.PoktApplicationSigner{{NetworkApp: &pokt_models.PoktApplication{ + Address: "1234", + Chains: []string{"123", "123"}, + PublicKey: "", + Status: 0, + MaxRelays: 0, + }}}, + slice2: []*models.PoktApplicationSigner{{NetworkApp: &pokt_models.PoktApplication{ + Address: "123", + Chains: []string{"123", "123"}, + PublicKey: "", + Status: 0, + MaxRelays: 0, + }}}, + }, + want: false, + }, + { + name: "different chains", + args: args{ + slice1: []*models.PoktApplicationSigner{{NetworkApp: &pokt_models.PoktApplication{ + Address: "1234", + Chains: []string{"123", "123"}, + PublicKey: "", + Status: 0, + MaxRelays: 0, + }}}, + slice2: []*models.PoktApplicationSigner{{NetworkApp: &pokt_models.PoktApplication{ + Address: "123", + Chains: []string{"123"}, + PublicKey: "", + Status: 0, + MaxRelays: 0, + }}}, + }, + want: false, + }, + { + name: "same apps", + args: args{ + slice1: []*models.PoktApplicationSigner{{NetworkApp: &pokt_models.PoktApplication{ + Address: "123", + Chains: []string{"123", "123"}, + PublicKey: "", + Status: 0, + MaxRelays: 0, + }}}, + slice2: []*models.PoktApplicationSigner{{NetworkApp: &pokt_models.PoktApplication{ + Address: "123", + Chains: []string{"123", "123"}, + PublicKey: "", + Status: 0, + MaxRelays: 0, + }}}, + }, + want: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := arePoktApplicationSignersEqual(tt.args.slice1, tt.args.slice2); got != tt.want { + t.Errorf("arePoktApplicationSignersEqual() = %v, want %v", got, tt.want) + } + }) + } +}