2020-08-17 12:05:32 +00:00
|
|
|
package storagegroup_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/refs"
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/storagegroup"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestStorageGroup_StableMarshal(t *testing.T) {
|
2020-11-13 14:20:24 +00:00
|
|
|
storageGroupFrom := generateSG()
|
2020-08-17 12:05:32 +00:00
|
|
|
|
|
|
|
t.Run("non empty", func(t *testing.T) {
|
|
|
|
wire, err := storageGroupFrom.StableMarshal(nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2020-11-13 14:20:24 +00:00
|
|
|
storageGroupTo := new(storagegroup.StorageGroup)
|
|
|
|
require.NoError(t, storageGroupTo.Unmarshal(wire))
|
2020-08-17 12:05:32 +00:00
|
|
|
|
|
|
|
require.Equal(t, storageGroupFrom, storageGroupTo)
|
|
|
|
})
|
|
|
|
}
|
2020-08-20 08:04:16 +00:00
|
|
|
|
|
|
|
func generateChecksum(data string) *refs.Checksum {
|
|
|
|
checksum := new(refs.Checksum)
|
|
|
|
checksum.SetType(refs.TillichZemor)
|
|
|
|
checksum.SetSum([]byte(data))
|
|
|
|
|
|
|
|
return checksum
|
|
|
|
}
|
2020-11-13 14:20:24 +00:00
|
|
|
|
|
|
|
func generateSG() *storagegroup.StorageGroup {
|
|
|
|
sg := new(storagegroup.StorageGroup)
|
|
|
|
|
|
|
|
oid1 := new(refs.ObjectID)
|
|
|
|
oid1.SetValue([]byte("Object ID 1"))
|
|
|
|
|
|
|
|
oid2 := new(refs.ObjectID)
|
|
|
|
oid2.SetValue([]byte("Object ID 2"))
|
|
|
|
|
|
|
|
sg.SetValidationDataSize(300)
|
|
|
|
sg.SetValidationHash(generateChecksum("Homomorphic hash"))
|
|
|
|
sg.SetExpirationEpoch(100)
|
|
|
|
sg.SetMembers([]*refs.ObjectID{oid1, oid2})
|
|
|
|
|
|
|
|
return sg
|
|
|
|
}
|