Skip to content

Commit

Permalink
different chains
Browse files Browse the repository at this point in the history
  • Loading branch information
blade committed May 22, 2024
1 parent 214d195 commit c8e16a4
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 1 deletion.
9 changes: 8 additions & 1 deletion internal/apps_registry/cached_app_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
101 changes: 101 additions & 0 deletions internal/apps_registry/cached_app_registry_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
})
}
}

0 comments on commit c8e16a4

Please sign in to comment.