2021-11-23 18:20:12 +00:00
|
|
|
package subnet_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
subnetv2 "github.com/nspcc-dev/neofs-api-go/v2/subnet"
|
|
|
|
subnettest "github.com/nspcc-dev/neofs-api-go/v2/subnet/test"
|
2021-11-26 11:03:27 +00:00
|
|
|
. "github.com/nspcc-dev/neofs-sdk-go/subnet"
|
2021-11-23 18:20:12 +00:00
|
|
|
subnetid "github.com/nspcc-dev/neofs-sdk-go/subnet/id"
|
2022-04-11 06:30:22 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/user"
|
|
|
|
usertest "github.com/nspcc-dev/neofs-sdk-go/user/test"
|
2021-11-23 18:20:12 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestInfoZero(t *testing.T) {
|
2021-11-26 11:03:27 +00:00
|
|
|
var info Info
|
2021-11-23 18:20:12 +00:00
|
|
|
|
|
|
|
var id subnetid.ID
|
|
|
|
info.ReadID(&id)
|
|
|
|
|
|
|
|
require.True(t, subnetid.IsZero(id))
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestInfo_SetID(t *testing.T) {
|
|
|
|
var (
|
2021-11-26 11:03:27 +00:00
|
|
|
id subnetid.ID
|
|
|
|
info Info
|
2021-11-23 18:20:12 +00:00
|
|
|
)
|
|
|
|
|
2021-11-26 11:03:27 +00:00
|
|
|
id.SetNumber(222)
|
2021-11-23 18:20:12 +00:00
|
|
|
|
2021-11-26 11:03:27 +00:00
|
|
|
info.SetID(id)
|
2021-11-23 18:20:12 +00:00
|
|
|
|
2021-11-26 11:03:27 +00:00
|
|
|
require.True(t, IDEquals(info, id))
|
2021-11-23 18:20:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestInfo_SetOwner(t *testing.T) {
|
|
|
|
var (
|
2022-04-11 06:30:22 +00:00
|
|
|
id user.ID
|
2021-11-26 11:03:27 +00:00
|
|
|
info Info
|
2021-11-23 18:20:12 +00:00
|
|
|
)
|
|
|
|
|
2022-04-11 06:30:22 +00:00
|
|
|
id = *usertest.ID()
|
2021-11-23 18:20:12 +00:00
|
|
|
|
2021-11-26 11:03:27 +00:00
|
|
|
require.False(t, IsOwner(info, id))
|
2021-11-23 18:20:12 +00:00
|
|
|
|
2021-11-26 11:03:27 +00:00
|
|
|
info.SetOwner(id)
|
2021-11-23 18:20:12 +00:00
|
|
|
|
2021-11-26 11:03:27 +00:00
|
|
|
require.True(t, IsOwner(info, id))
|
2021-11-23 18:20:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestInfo_WriteToV2(t *testing.T) {
|
|
|
|
var (
|
2021-11-26 11:03:27 +00:00
|
|
|
infoTo, infoFrom Info
|
2021-11-23 18:20:12 +00:00
|
|
|
|
|
|
|
infoV2From, infoV2To subnetv2.Info
|
|
|
|
)
|
|
|
|
|
|
|
|
infoV2From = *subnettest.GenerateSubnetInfo(false)
|
|
|
|
|
|
|
|
infoFrom.FromV2(infoV2From)
|
|
|
|
|
|
|
|
infoFrom.WriteToV2(&infoV2To)
|
|
|
|
|
|
|
|
infoTo.FromV2(infoV2To)
|
|
|
|
|
|
|
|
require.Equal(t, infoV2From, infoV2To)
|
|
|
|
require.Equal(t, infoFrom, infoTo)
|
|
|
|
}
|