Skip to content

Commit

Permalink
yet another key comparison bug in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Tarak Ben Youssef committed May 16, 2023
1 parent 184a49d commit a4fb435
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
13 changes: 13 additions & 0 deletions model/flow/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ type Identity struct {
NetworkPubKey crypto.PublicKey
}

func (id *Identity) Equals(other *Identity) bool {
if other == nil {
return false
}
return id.NodeID == other.NodeID &&
id.Address == other.Address &&
id.Role == other.Role &&
id.Weight == other.Weight &&
id.Ejected == other.Ejected &&
id.StakingPubKey.Equals(other.StakingPubKey) &&
id.NetworkPubKey.Equals(other.NetworkPubKey)
}

// ParseIdentity parses a string representation of an identity.
func ParseIdentity(identity string) (*Identity, error) {

Expand Down
8 changes: 4 additions & 4 deletions model/flow/identity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func TestIdentityEncodingJSON(t *testing.T) {
var dec flow.Identity
err = json.Unmarshal(enc, &dec)
require.NoError(t, err)
require.Equal(t, identity, &dec)
require.True(t, identity.Equals(&dec))
})

t.Run("empty address should be omitted", func(t *testing.T) {
Expand All @@ -73,7 +73,7 @@ func TestIdentityEncodingJSON(t *testing.T) {
var dec flow.Identity
err = json.Unmarshal(enc, &dec)
require.NoError(t, err)
require.Equal(t, identity, &dec)
require.True(t, identity.Equals(&dec))
})

t.Run("compat: should accept old files using Stake field", func(t *testing.T) {
Expand All @@ -85,7 +85,7 @@ func TestIdentityEncodingJSON(t *testing.T) {
var dec flow.Identity
err = json.Unmarshal(enc, &dec)
require.NoError(t, err)
require.Equal(t, identity, &dec)
require.True(t, identity.Equals(&dec))
})
}

Expand All @@ -96,7 +96,7 @@ func TestIdentityEncodingMsgpack(t *testing.T) {
var dec flow.Identity
err = msgpack.Unmarshal(enc, &dec)
require.NoError(t, err)
require.Equal(t, identity, &dec)
require.True(t, identity.Equals(&dec))
}

func TestIdentityList_Exists(t *testing.T) {
Expand Down

0 comments on commit a4fb435

Please sign in to comment.