2021-03-24 08:27:30 +00:00
|
|
|
package reputationtest
|
|
|
|
|
|
|
|
import (
|
2021-04-02 09:57:53 +00:00
|
|
|
"testing"
|
|
|
|
|
2021-03-24 08:27:30 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/reputation"
|
|
|
|
crypto "github.com/nspcc-dev/neofs-crypto"
|
|
|
|
"github.com/nspcc-dev/neofs-crypto/test"
|
2021-04-02 09:57:53 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2021-03-24 08:27:30 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func GeneratePeerID() *reputation.PeerID {
|
|
|
|
v := reputation.NewPeerID()
|
2021-04-02 09:20:09 +00:00
|
|
|
|
|
|
|
key := [crypto.PublicKeyCompressedSize]byte{}
|
|
|
|
copy(key[:], crypto.MarshalPublicKey(&test.DecodeKey(-1).PublicKey))
|
|
|
|
|
|
|
|
v.SetPublicKey(key)
|
2021-03-24 08:27:30 +00:00
|
|
|
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func GenerateTrust() *reputation.Trust {
|
|
|
|
v := reputation.NewTrust()
|
|
|
|
v.SetPeer(GeneratePeerID())
|
|
|
|
v.SetValue(1.5)
|
|
|
|
|
|
|
|
return v
|
|
|
|
}
|
2021-04-02 09:57:53 +00:00
|
|
|
|
2021-04-09 08:39:25 +00:00
|
|
|
func GeneratePeerToPeerTrust() *reputation.PeerToPeerTrust {
|
|
|
|
v := reputation.NewPeerToPeerTrust()
|
|
|
|
v.SetTrustingPeer(GeneratePeerID())
|
|
|
|
v.SetTrust(GenerateTrust())
|
|
|
|
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
2021-04-02 09:57:53 +00:00
|
|
|
func GenerateGlobalTrust() *reputation.GlobalTrust {
|
|
|
|
v := reputation.NewGlobalTrust()
|
|
|
|
v.SetManager(GeneratePeerID())
|
|
|
|
v.SetTrust(GenerateTrust())
|
|
|
|
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func GenerateSignedGlobalTrust(t testing.TB) *reputation.GlobalTrust {
|
|
|
|
gt := GenerateGlobalTrust()
|
|
|
|
|
|
|
|
require.NoError(t, gt.Sign(test.DecodeKey(0)))
|
|
|
|
|
|
|
|
return gt
|
|
|
|
}
|