frostfs-api-go/refs/types_test.go
alexvanin 1958ff8c37 Use NEO3 based address generation
With neo-go v0.90.0 there are new event subscription component
and new verification script routines based on NEO3. These features
allow to avoid using low-level neo-vm code in NeoFS and corresponding
projects.

This commit removes unused function:
- FetchPublicKeys (used in neofs indexer),
- VerificationScript (used in KeysToAddress),
- Address (used in KeysToAddress),
- ReversedScriptHashToAddress (used in neofs indexer),
- IsAddress (used in neofs indexer),
- ReverseBytes (used in neofs indexer),
- DecodeScriptHash (used in neofs indexer).

KeysToAddress changed into KeyToAddress because NeoFS won't work with
multisignature owners for now and it is not supported in neo-go library.
2020-07-20 16:43:31 +03:00

112 lines
2.4 KiB
Go

package refs
import (
"strings"
"testing"
"github.com/gogo/protobuf/proto"
"github.com/google/uuid"
"github.com/nspcc-dev/neofs-crypto/test"
"github.com/stretchr/testify/require"
)
func TestSGID(t *testing.T) {
t.Run("check that marshal/unmarshal works like expected", func(t *testing.T) {
var sgid1, sgid2 UUID
sgid1, err := NewSGID()
require.NoError(t, err)
data, err := proto.Marshal(&sgid1)
require.NoError(t, err)
require.NoError(t, sgid2.Unmarshal(data))
require.Equal(t, sgid1, sgid2)
})
}
func TestUUID(t *testing.T) {
t.Run("parse should work like expected", func(t *testing.T) {
var u UUID
id, err := uuid.NewRandom()
require.NoError(t, err)
require.NoError(t, u.Parse(id.String()))
require.Equal(t, id.String(), u.String())
})
t.Run("check that marshal/unmarshal works like expected", func(t *testing.T) {
var u1, u2 UUID
u1 = UUID{0x8f, 0xe4, 0xeb, 0xa0, 0xb8, 0xfb, 0x49, 0x3b, 0xbb, 0x1d, 0x1d, 0x13, 0x6e, 0x69, 0xfc, 0xf7}
data, err := proto.Marshal(&u1)
require.NoError(t, err)
require.NoError(t, u2.Unmarshal(data))
require.Equal(t, u1, u2)
})
t.Run("check that marshal/unmarshal works like expected even for msg id", func(t *testing.T) {
var u2 MessageID
u1, err := NewMessageID()
require.NoError(t, err)
data, err := proto.Marshal(&u1)
require.NoError(t, err)
require.NoError(t, u2.Unmarshal(data))
require.Equal(t, u1, u2)
})
}
func TestOwnerID(t *testing.T) {
t.Run("check that marshal/unmarshal works like expected", func(t *testing.T) {
var u1, u2 OwnerID
owner, err := NewOwnerID(nil)
require.NoError(t, err)
require.True(t, owner.Empty())
key := test.DecodeKey(0)
u1, err = NewOwnerID(&key.PublicKey)
require.NoError(t, err)
data, err := proto.Marshal(&u1)
require.NoError(t, err)
require.NoError(t, u2.Unmarshal(data))
require.Equal(t, u1, u2)
})
}
func TestAddress(t *testing.T) {
cid := CIDForBytes([]byte("test"))
id, err := NewObjectID()
require.NoError(t, err)
expect := strings.Join([]string{
cid.String(),
id.String(),
}, joinSeparator)
require.NotPanics(t, func() {
actual := (Address{
ObjectID: id,
CID: cid,
}).String()
require.Equal(t, expect, actual)
})
var temp Address
require.NoError(t, temp.Parse(expect))
require.Equal(t, expect, temp.String())
actual, err := ParseAddress(expect)
require.NoError(t, err)
require.Equal(t, expect, actual.String())
}