diff --git a/pkg/reputation/trust.go b/pkg/reputation/trust.go index c5847407..e3dd5e5f 100644 --- a/pkg/reputation/trust.go +++ b/pkg/reputation/trust.go @@ -14,6 +14,10 @@ import ( type Trust reputation.Trust // NewTrust creates and returns blank Trust. +// +// Defaults: +// - value: 0; +// - PeerID: nil. func NewTrust() *Trust { return TrustFromV2(new(reputation.Trust)) } @@ -109,6 +113,10 @@ func (x *Trust) UnmarshalJSON(data []byte) error { type PeerToPeerTrust reputation.PeerToPeerTrust // NewPeerToPeerTrust creates and returns blank PeerToPeerTrust. +// +// Defaults: +// - trusting: nil; +// - trust: nil. func NewPeerToPeerTrust() *PeerToPeerTrust { return PeerToPeerTrustFromV2(new(reputation.PeerToPeerTrust)) } @@ -193,7 +201,10 @@ type GlobalTrust reputation.GlobalTrust // NewGlobalTrust creates and returns blank GlobalTrust. // -// Version is initialized to current library version. +// Defaults: +// - version: pkg.SDKVersion(); +// - manager: nil; +// - trust: nil. func NewGlobalTrust() *GlobalTrust { gt := GlobalTrustFromV2(new(reputation.GlobalTrust)) gt.SetVersion(pkg.SDKVersion()) diff --git a/pkg/reputation/trust_test.go b/pkg/reputation/trust_test.go index 844997b0..41072e9f 100644 --- a/pkg/reputation/trust_test.go +++ b/pkg/reputation/trust_test.go @@ -199,3 +199,52 @@ func TestGlobalTrust_ToV2(t *testing.T) { require.Nil(t, x.ToV2()) }) } + +func TestNewTrust(t *testing.T) { + t.Run("default values", func(t *testing.T) { + trust := reputation.NewTrust() + + // check initial values + require.Zero(t, trust.Value()) + require.Nil(t, trust.Peer()) + + // convert to v2 message + trustV2 := trust.ToV2() + + require.Zero(t, trustV2.GetValue()) + require.Nil(t, trustV2.GetPeer()) + }) +} + +func TestNewPeerToPeerTrust(t *testing.T) { + t.Run("default values", func(t *testing.T) { + trust := reputation.NewPeerToPeerTrust() + + // check initial values + require.Nil(t, trust.Trust()) + require.Nil(t, trust.TrustingPeer()) + + // convert to v2 message + trustV2 := trust.ToV2() + + require.Nil(t, trustV2.GetTrust()) + require.Nil(t, trustV2.GetTrustingPeer()) + }) +} + +func TestNewGlobalTrust(t *testing.T) { + t.Run("default values", func(t *testing.T) { + trust := reputation.NewGlobalTrust() + + // check initial values + require.Nil(t, trust.Manager()) + require.Nil(t, trust.Trust()) + + require.Equal(t, pkg.SDKVersion().String(), trust.Version().String()) + + // convert to v2 message + trustV2 := trust.ToV2() + + require.Nil(t, trustV2.GetBody()) + }) +}