2021-11-08 08:41:39 +00:00
|
|
|
package reputationtest
|
|
|
|
|
|
|
|
import (
|
2021-11-22 12:38:15 +00:00
|
|
|
"crypto/ecdsa"
|
|
|
|
"crypto/elliptic"
|
|
|
|
"crypto/rand"
|
2021-11-08 08:41:39 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/reputation"
|
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/util/signature"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func GeneratePeerID() *reputation.PeerID {
|
|
|
|
v := reputation.NewPeerID()
|
|
|
|
|
2021-11-22 12:38:15 +00:00
|
|
|
p, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
|
2021-11-08 08:41:39 +00:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
key := [signature.PublicKeyCompressedSize]byte{}
|
2021-11-22 12:38:15 +00:00
|
|
|
copy(key[:], elliptic.MarshalCompressed(p.Curve, p.X, p.Y))
|
2021-11-08 08:41:39 +00:00
|
|
|
v.SetPublicKey(key)
|
|
|
|
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func GenerateTrust() *reputation.Trust {
|
|
|
|
v := reputation.NewTrust()
|
|
|
|
v.SetPeer(GeneratePeerID())
|
|
|
|
v.SetValue(1.5)
|
|
|
|
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func GeneratePeerToPeerTrust() *reputation.PeerToPeerTrust {
|
|
|
|
v := reputation.NewPeerToPeerTrust()
|
|
|
|
v.SetTrustingPeer(GeneratePeerID())
|
|
|
|
v.SetTrust(GenerateTrust())
|
|
|
|
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func GenerateGlobalTrust() *reputation.GlobalTrust {
|
|
|
|
v := reputation.NewGlobalTrust()
|
|
|
|
v.SetManager(GeneratePeerID())
|
|
|
|
v.SetTrust(GenerateTrust())
|
|
|
|
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func GenerateSignedGlobalTrust(t testing.TB) *reputation.GlobalTrust {
|
|
|
|
gt := GenerateGlobalTrust()
|
|
|
|
|
2021-11-22 12:38:15 +00:00
|
|
|
p, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
|
2021-11-08 08:41:39 +00:00
|
|
|
require.NoError(t, err)
|
2021-11-22 12:38:15 +00:00
|
|
|
require.NoError(t, gt.Sign(p))
|
2021-11-08 08:41:39 +00:00
|
|
|
|
|
|
|
return gt
|
|
|
|
}
|