diff --git a/model/flow/identity.go b/model/flow/identity.go index f05188988e6..eb86279641b 100644 --- a/model/flow/identity.go +++ b/model/flow/identity.go @@ -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) { diff --git a/model/flow/identity_test.go b/model/flow/identity_test.go index 9c1a137d8ab..0f3b2c2145a 100644 --- a/model/flow/identity_test.go +++ b/model/flow/identity_test.go @@ -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) { @@ -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) { @@ -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)) }) } @@ -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) {