diff --git a/netmap/network_info_test.go b/netmap/network_info_test.go index c862077d..87db6fa2 100644 --- a/netmap/network_info_test.go +++ b/netmap/network_info_test.go @@ -5,14 +5,14 @@ import ( "math" "testing" - "github.com/nspcc-dev/neofs-api-go/v2/netmap" - . "github.com/nspcc-dev/neofs-sdk-go/netmap" + netmapv2 "github.com/nspcc-dev/neofs-api-go/v2/netmap" + "github.com/nspcc-dev/neofs-sdk-go/netmap" netmaptest "github.com/nspcc-dev/neofs-sdk-go/netmap/test" "github.com/stretchr/testify/require" ) func TestNetworkInfo_CurrentEpoch(t *testing.T) { - var x NetworkInfo + var x netmap.NetworkInfo require.Zero(t, x.CurrentEpoch()) @@ -22,14 +22,14 @@ func TestNetworkInfo_CurrentEpoch(t *testing.T) { require.EqualValues(t, e, x.CurrentEpoch()) - var m netmap.NetworkInfo + var m netmapv2.NetworkInfo x.WriteToV2(&m) require.EqualValues(t, e, m.GetCurrentEpoch()) } func TestNetworkInfo_MagicNumber(t *testing.T) { - var x NetworkInfo + var x netmap.NetworkInfo require.Zero(t, x.MagicNumber()) @@ -39,14 +39,14 @@ func TestNetworkInfo_MagicNumber(t *testing.T) { require.EqualValues(t, magic, x.MagicNumber()) - var m netmap.NetworkInfo + var m netmapv2.NetworkInfo x.WriteToV2(&m) require.EqualValues(t, magic, m.GetMagicNumber()) } func TestNetworkInfo_MsPerBlock(t *testing.T) { - var x NetworkInfo + var x netmap.NetworkInfo require.Zero(t, x.MsPerBlock()) @@ -56,31 +56,31 @@ func TestNetworkInfo_MsPerBlock(t *testing.T) { require.EqualValues(t, ms, x.MsPerBlock()) - var m netmap.NetworkInfo + var m netmapv2.NetworkInfo x.WriteToV2(&m) require.EqualValues(t, ms, m.GetMsPerBlock()) } func testConfigValue(t *testing.T, - getter func(x NetworkInfo) any, - setter func(x *NetworkInfo, val any), + getter func(x netmap.NetworkInfo) any, + setter func(x *netmap.NetworkInfo, val any), val1, val2 any, v2Key string, v2Val func(val any) []byte, ) { - var x NetworkInfo + var x netmap.NetworkInfo require.Zero(t, getter(x)) checkVal := func(exp any) { require.EqualValues(t, exp, getter(x)) - var m netmap.NetworkInfo + var m netmapv2.NetworkInfo x.WriteToV2(&m) require.EqualValues(t, 1, m.GetNetworkConfig().NumberOfParameters()) found := false - m.GetNetworkConfig().IterateParameters(func(prm *netmap.NetworkParameter) bool { + m.GetNetworkConfig().IterateParameters(func(prm *netmapv2.NetworkParameter) bool { require.False(t, found) require.Equal(t, []byte(v2Key), prm.GetKey()) require.Equal(t, v2Val(exp), prm.GetValue()) @@ -99,8 +99,8 @@ func testConfigValue(t *testing.T, func TestNetworkInfo_AuditFee(t *testing.T) { testConfigValue(t, - func(x NetworkInfo) any { return x.AuditFee() }, - func(info *NetworkInfo, val any) { info.SetAuditFee(val.(uint64)) }, + func(x netmap.NetworkInfo) any { return x.AuditFee() }, + func(info *netmap.NetworkInfo, val any) { info.SetAuditFee(val.(uint64)) }, uint64(1), uint64(2), "AuditFee", func(val any) []byte { data := make([]byte, 8) @@ -112,8 +112,8 @@ func TestNetworkInfo_AuditFee(t *testing.T) { func TestNetworkInfo_StoragePrice(t *testing.T) { testConfigValue(t, - func(x NetworkInfo) any { return x.StoragePrice() }, - func(info *NetworkInfo, val any) { info.SetStoragePrice(val.(uint64)) }, + func(x netmap.NetworkInfo) any { return x.StoragePrice() }, + func(info *netmap.NetworkInfo, val any) { info.SetStoragePrice(val.(uint64)) }, uint64(1), uint64(2), "BasicIncomeRate", func(val any) []byte { data := make([]byte, 8) @@ -125,8 +125,8 @@ func TestNetworkInfo_StoragePrice(t *testing.T) { func TestNetworkInfo_ContainerFee(t *testing.T) { testConfigValue(t, - func(x NetworkInfo) any { return x.ContainerFee() }, - func(info *NetworkInfo, val any) { info.SetContainerFee(val.(uint64)) }, + func(x netmap.NetworkInfo) any { return x.ContainerFee() }, + func(info *netmap.NetworkInfo, val any) { info.SetContainerFee(val.(uint64)) }, uint64(1), uint64(2), "ContainerFee", func(val any) []byte { data := make([]byte, 8) @@ -138,8 +138,8 @@ func TestNetworkInfo_ContainerFee(t *testing.T) { func TestNetworkInfo_NamedContainerFee(t *testing.T) { testConfigValue(t, - func(x NetworkInfo) any { return x.NamedContainerFee() }, - func(info *NetworkInfo, val any) { info.SetNamedContainerFee(val.(uint64)) }, + func(x netmap.NetworkInfo) any { return x.NamedContainerFee() }, + func(info *netmap.NetworkInfo, val any) { info.SetNamedContainerFee(val.(uint64)) }, uint64(1), uint64(2), "ContainerAliasFee", func(val any) []byte { data := make([]byte, 8) @@ -151,8 +151,8 @@ func TestNetworkInfo_NamedContainerFee(t *testing.T) { func TestNetworkInfo_EigenTrustAlpha(t *testing.T) { testConfigValue(t, - func(x NetworkInfo) any { return x.EigenTrustAlpha() }, - func(info *NetworkInfo, val any) { info.SetEigenTrustAlpha(val.(float64)) }, + func(x netmap.NetworkInfo) any { return x.EigenTrustAlpha() }, + func(info *netmap.NetworkInfo, val any) { info.SetEigenTrustAlpha(val.(float64)) }, 0.1, 0.2, "EigenTrustAlpha", func(val any) []byte { data := make([]byte, 8) @@ -164,8 +164,8 @@ func TestNetworkInfo_EigenTrustAlpha(t *testing.T) { func TestNetworkInfo_NumberOfEigenTrustIterations(t *testing.T) { testConfigValue(t, - func(x NetworkInfo) any { return x.NumberOfEigenTrustIterations() }, - func(info *NetworkInfo, val any) { info.SetNumberOfEigenTrustIterations(val.(uint64)) }, + func(x netmap.NetworkInfo) any { return x.NumberOfEigenTrustIterations() }, + func(info *netmap.NetworkInfo, val any) { info.SetNumberOfEigenTrustIterations(val.(uint64)) }, uint64(1), uint64(2), "EigenTrustIterations", func(val any) []byte { data := make([]byte, 8) @@ -177,8 +177,8 @@ func TestNetworkInfo_NumberOfEigenTrustIterations(t *testing.T) { func TestNetworkInfo_IRCandidateFee(t *testing.T) { testConfigValue(t, - func(x NetworkInfo) any { return x.IRCandidateFee() }, - func(info *NetworkInfo, val any) { info.SetIRCandidateFee(val.(uint64)) }, + func(x netmap.NetworkInfo) any { return x.IRCandidateFee() }, + func(info *netmap.NetworkInfo, val any) { info.SetIRCandidateFee(val.(uint64)) }, uint64(1), uint64(2), "InnerRingCandidateFee", func(val any) []byte { data := make([]byte, 8) @@ -190,8 +190,8 @@ func TestNetworkInfo_IRCandidateFee(t *testing.T) { func TestNetworkInfo_MaxObjectSize(t *testing.T) { testConfigValue(t, - func(x NetworkInfo) any { return x.MaxObjectSize() }, - func(info *NetworkInfo, val any) { info.SetMaxObjectSize(val.(uint64)) }, + func(x netmap.NetworkInfo) any { return x.MaxObjectSize() }, + func(info *netmap.NetworkInfo, val any) { info.SetMaxObjectSize(val.(uint64)) }, uint64(1), uint64(2), "MaxObjectSize", func(val any) []byte { data := make([]byte, 8) @@ -203,8 +203,8 @@ func TestNetworkInfo_MaxObjectSize(t *testing.T) { func TestNetworkInfo_WithdrawalFee(t *testing.T) { testConfigValue(t, - func(x NetworkInfo) any { return x.WithdrawalFee() }, - func(info *NetworkInfo, val any) { info.SetWithdrawalFee(val.(uint64)) }, + func(x netmap.NetworkInfo) any { return x.WithdrawalFee() }, + func(info *netmap.NetworkInfo, val any) { info.SetWithdrawalFee(val.(uint64)) }, uint64(1), uint64(2), "WithdrawFee", func(val any) []byte { data := make([]byte, 8) @@ -216,8 +216,8 @@ func TestNetworkInfo_WithdrawalFee(t *testing.T) { func TestNetworkInfo_HomomorphicHashingDisabled(t *testing.T) { testConfigValue(t, - func(x NetworkInfo) any { return x.HomomorphicHashingDisabled() }, - func(info *NetworkInfo, val any) { + func(x netmap.NetworkInfo) any { return x.HomomorphicHashingDisabled() }, + func(info *netmap.NetworkInfo, val any) { if val.(bool) { info.DisableHomomorphicHashing() } @@ -237,8 +237,8 @@ func TestNetworkInfo_HomomorphicHashingDisabled(t *testing.T) { func TestNetworkInfo_MaintenanceModeAllowed(t *testing.T) { testConfigValue(t, - func(x NetworkInfo) any { return x.MaintenanceModeAllowed() }, - func(info *NetworkInfo, val any) { + func(x netmap.NetworkInfo) any { return x.MaintenanceModeAllowed() }, + func(info *netmap.NetworkInfo, val any) { if val.(bool) { info.AllowMaintenanceMode() } @@ -256,7 +256,7 @@ func TestNetworkInfo_MaintenanceModeAllowed(t *testing.T) { func TestNetworkInfo_Marshal(t *testing.T) { v := netmaptest.NetworkInfo() - var v2 NetworkInfo + var v2 netmap.NetworkInfo require.NoError(t, v2.Unmarshal(v.Marshal())) require.Equal(t, v, v2) diff --git a/netmap/policy_test.go b/netmap/policy_test.go index 65f46c66..4efaa3dd 100644 --- a/netmap/policy_test.go +++ b/netmap/policy_test.go @@ -4,7 +4,7 @@ import ( "strings" "testing" - . "github.com/nspcc-dev/neofs-sdk-go/netmap" + "github.com/nspcc-dev/neofs-sdk-go/netmap" netmaptest "github.com/nspcc-dev/neofs-sdk-go/netmap/test" "github.com/stretchr/testify/require" ) @@ -25,7 +25,7 @@ SELECT 1 IN City FROM SPBSSD AS SPB FILTER City EQ SPB AND SSD EQ true OR City EQ SPB AND Rating GE 5 AS SPBSSD`, } - var p PlacementPolicy + var p netmap.PlacementPolicy for _, testCase := range testCases { require.NoError(t, p.DecodeString(testCase)) @@ -49,7 +49,7 @@ func TestPlacementPolicyEncoding(t *testing.T) { v := netmaptest.PlacementPolicy() t.Run("binary", func(t *testing.T) { - var v2 PlacementPolicy + var v2 netmap.PlacementPolicy require.NoError(t, v2.Unmarshal(v.Marshal())) require.Equal(t, v, v2) @@ -59,7 +59,7 @@ func TestPlacementPolicyEncoding(t *testing.T) { data, err := v.MarshalJSON() require.NoError(t, err) - var v2 PlacementPolicy + var v2 netmap.PlacementPolicy require.NoError(t, v2.UnmarshalJSON(data)) require.Equal(t, v, v2) diff --git a/object/attribute.go b/object/attribute.go index c414cb73..4b6b5e2e 100644 --- a/object/attribute.go +++ b/object/attribute.go @@ -30,15 +30,13 @@ func NewAttributeFromV2(aV2 *object.Attribute) *Attribute { return (*Attribute)(aV2) } -// NewAttribute creates and initializes blank [Attribute]. -// -// Works similar as NewAttributeFromV2(new(Attribute)). -// -// Defaults: -// - key: ""; -// - value: "". -func NewAttribute() *Attribute { - return NewAttributeFromV2(new(object.Attribute)) +// NewAttribute creates and initializes new [Attribute]. +func NewAttribute(key, value string) *Attribute { + attr := new(object.Attribute) + attr.SetKey(key) + attr.SetValue(value) + + return NewAttributeFromV2(attr) } // Key returns key to the object attribute. diff --git a/object/attribute_test.go b/object/attribute_test.go index d5f1b3f9..f87bc73f 100644 --- a/object/attribute_test.go +++ b/object/attribute_test.go @@ -10,9 +10,7 @@ import ( func TestAttribute(t *testing.T) { key, val := "some key", "some value" - a := NewAttribute() - a.SetKey(key) - a.SetValue(val) + a := NewAttribute(key, val) require.Equal(t, key, a.Key()) require.Equal(t, val, a.Value()) @@ -24,15 +22,13 @@ func TestAttribute(t *testing.T) { } func TestAttributeEncoding(t *testing.T) { - a := NewAttribute() - a.SetKey("key") - a.SetValue("value") + a := NewAttribute("key", "value") t.Run("binary", func(t *testing.T) { data, err := a.Marshal() require.NoError(t, err) - a2 := NewAttribute() + a2 := NewAttribute("", "") require.NoError(t, a2.Unmarshal(data)) require.Equal(t, a, a2) @@ -42,7 +38,7 @@ func TestAttributeEncoding(t *testing.T) { data, err := a.MarshalJSON() require.NoError(t, err) - a2 := NewAttribute() + a2 := NewAttribute("", "") require.NoError(t, a2.UnmarshalJSON(data)) require.Equal(t, a, a2) @@ -67,7 +63,7 @@ func TestAttribute_ToV2(t *testing.T) { func TestNewAttribute(t *testing.T) { t.Run("default values", func(t *testing.T) { - a := NewAttribute() + a := NewAttribute("", "") // check initial values require.Empty(t, a.Key()) @@ -79,4 +75,17 @@ func TestNewAttribute(t *testing.T) { require.Empty(t, aV2.GetKey()) require.Empty(t, aV2.GetValue()) }) + + t.Run("pre installed key and value", func(t *testing.T) { + a := NewAttribute("key", "value") + + require.NotEmpty(t, a.Key()) + require.NotEmpty(t, a.Value()) + + // convert to v2 message + aV2 := a.ToV2() + + require.NotEmpty(t, aV2.GetKey()) + require.NotEmpty(t, aV2.GetValue()) + }) } diff --git a/object/test/generate.go b/object/test/generate.go index f8e2f2bd..a4194bc2 100644 --- a/object/test/generate.go +++ b/object/test/generate.go @@ -26,10 +26,7 @@ func Range() object.Range { // Attribute returns random object.Attribute. func Attribute() object.Attribute { - x := object.NewAttribute() - - x.SetKey("key") - x.SetValue("value") + x := object.NewAttribute("key", "value") return *x } diff --git a/user/id_test.go b/user/id_test.go index df5fd5bd..525164df 100644 --- a/user/id_test.go +++ b/user/id_test.go @@ -8,7 +8,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/util/slice" "github.com/nspcc-dev/neofs-api-go/v2/refs" - . "github.com/nspcc-dev/neofs-sdk-go/user" + "github.com/nspcc-dev/neofs-sdk-go/user" usertest "github.com/nspcc-dev/neofs-sdk-go/user/test" "github.com/stretchr/testify/require" ) @@ -17,7 +17,7 @@ func TestID_WalletBytes(t *testing.T) { var scriptHash util.Uint160 rand.Read(scriptHash[:]) - var id ID + var id user.ID id.SetScriptHash(scriptHash) w := id.WalletBytes() @@ -33,13 +33,13 @@ func TestID_SetScriptHash(t *testing.T) { var scriptHash util.Uint160 rand.Read(scriptHash[:]) - var id ID + var id user.ID id.SetScriptHash(scriptHash) var m refs.OwnerID id.WriteToV2(&m) - var id2 ID + var id2 user.ID err := id2.ReadFromV2(m) require.NoError(t, err) @@ -50,7 +50,7 @@ func TestID_SetScriptHash(t *testing.T) { func TestV2_ID(t *testing.T) { id := usertest.ID(t) var m refs.OwnerID - var id2 ID + var id2 user.ID t.Run("OK", func(t *testing.T) { id.WriteToV2(&m) @@ -98,7 +98,7 @@ func TestID_EncodeToString(t *testing.T) { _, err := base58.Decode(s) require.NoError(t, err) - var id2 ID + var id2 user.ID err = id2.DecodeString(s) require.NoError(t, err)