Skip to content

Commit

Permalink
fix node info comparison bug in test
Browse files Browse the repository at this point in the history
  • Loading branch information
Tarak Ben Youssef committed May 16, 2023
1 parent 29f7489 commit c47c321
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
12 changes: 12 additions & 0 deletions model/bootstrap/node_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,18 @@ type decodableNodeInfoPub struct {
Stake uint64
}

func (info *NodeInfoPub) Equals(other *NodeInfoPub) bool {
if other == nil {
return false
}
return info.Address == other.Address &&
info.NodeID == other.NodeID &&
info.Role == other.Role &&
info.Weight == other.Weight &&
info.NetworkPubKey.PublicKey.Equals(other.NetworkPubKey.PublicKey) &&
info.StakingPubKey.PublicKey.Equals(other.StakingPubKey.PublicKey)
}

func (info *NodeInfoPub) UnmarshalJSON(b []byte) error {
var decodable decodableNodeInfoPub
err := json.Unmarshal(b, &decodable)
Expand Down
4 changes: 2 additions & 2 deletions model/bootstrap/node_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestNodeInfoPubEncodingJSON(t *testing.T) {
var dec bootstrap.NodeInfoPub
err = json.Unmarshal(enc, &dec)
require.NoError(t, err)
assert.Equal(t, conf, dec)
assert.True(t, dec.Equals(&conf))
})
t.Run("compat: should accept old files using Stake field", func(t *testing.T) {
conf := unittest.NodeInfoFixture().Public()
Expand All @@ -61,6 +61,6 @@ func TestNodeInfoPubEncodingJSON(t *testing.T) {
var dec bootstrap.NodeInfoPub
err = json.Unmarshal(enc, &dec)
require.NoError(t, err)
assert.Equal(t, conf, dec)
assert.True(t, dec.Equals(&conf))
})
}

0 comments on commit c47c321

Please sign in to comment.