2021-11-08 08:41:39 +00:00
|
|
|
package reputation_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2022-06-30 16:08:34 +00:00
|
|
|
v2reputation "github.com/nspcc-dev/neofs-api-go/v2/reputation"
|
2021-11-08 08:41:39 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/reputation"
|
|
|
|
reputationtest "github.com/nspcc-dev/neofs-sdk-go/reputation/test"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2022-06-30 16:08:34 +00:00
|
|
|
func TestPeerID_PublicKey(t *testing.T) {
|
|
|
|
var val reputation.PeerID
|
2021-11-08 08:41:39 +00:00
|
|
|
|
2022-06-30 16:08:34 +00:00
|
|
|
require.Zero(t, val.PublicKey())
|
2021-11-08 08:41:39 +00:00
|
|
|
|
2022-06-30 16:08:34 +00:00
|
|
|
key := []byte{3, 2, 1}
|
2021-11-08 08:41:39 +00:00
|
|
|
|
2022-06-30 16:08:34 +00:00
|
|
|
val.SetPublicKey(key)
|
2021-11-08 08:41:39 +00:00
|
|
|
|
2022-06-30 16:08:34 +00:00
|
|
|
var m v2reputation.PeerID
|
|
|
|
val.WriteToV2(&m)
|
2021-11-08 08:41:39 +00:00
|
|
|
|
2022-06-30 16:08:34 +00:00
|
|
|
require.Equal(t, key, m.GetPublicKey())
|
2021-11-08 08:41:39 +00:00
|
|
|
|
2022-06-30 16:08:34 +00:00
|
|
|
var val2 reputation.PeerID
|
|
|
|
require.NoError(t, val2.ReadFromV2(m))
|
2021-11-08 08:41:39 +00:00
|
|
|
|
2022-06-30 16:08:34 +00:00
|
|
|
require.Equal(t, key, val.PublicKey())
|
2021-11-08 08:41:39 +00:00
|
|
|
|
2022-06-30 16:08:34 +00:00
|
|
|
require.True(t, reputation.ComparePeerKey(val, key))
|
2021-11-08 08:41:39 +00:00
|
|
|
}
|
|
|
|
|
2022-06-30 16:08:34 +00:00
|
|
|
func TestPeerID_EncodeToString(t *testing.T) {
|
|
|
|
val := reputationtest.PeerID()
|
|
|
|
var val2 reputation.PeerID
|
2021-11-08 08:41:39 +00:00
|
|
|
|
2022-06-30 16:08:34 +00:00
|
|
|
require.NoError(t, val2.DecodeString(val.EncodeToString()))
|
|
|
|
require.Equal(t, val, val2)
|
2021-11-08 08:41:39 +00:00
|
|
|
}
|