2021-11-08 08:41:39 +00:00
|
|
|
package reputation_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2022-12-13 14:36:35 +00:00
|
|
|
v2reputation "github.com/TrueCloudLab/frostfs-api-go/v2/reputation"
|
|
|
|
"github.com/TrueCloudLab/frostfs-sdk-go/reputation"
|
|
|
|
reputationtest "github.com/TrueCloudLab/frostfs-sdk-go/reputation/test"
|
2021-11-08 08:41:39 +00:00
|
|
|
"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
|
|
|
}
|