2021-11-08 08:41:39 +00:00
|
|
|
package reputationtest
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2021-12-10 13:56:04 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
2021-11-08 08:41:39 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/reputation"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2021-11-12 11:19:16 +00:00
|
|
|
func PeerID() *reputation.PeerID {
|
2021-11-08 08:41:39 +00:00
|
|
|
v := reputation.NewPeerID()
|
|
|
|
|
2021-12-10 13:56:04 +00:00
|
|
|
p, err := keys.NewPrivateKey()
|
2021-11-08 08:41:39 +00:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2022-04-05 11:13:34 +00:00
|
|
|
key := [33]byte{}
|
2021-12-10 13:56:04 +00:00
|
|
|
copy(key[:], p.Bytes())
|
2021-11-08 08:41:39 +00:00
|
|
|
v.SetPublicKey(key)
|
|
|
|
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
2021-11-12 11:19:16 +00:00
|
|
|
func Trust() *reputation.Trust {
|
2021-11-08 08:41:39 +00:00
|
|
|
v := reputation.NewTrust()
|
2021-11-12 11:19:16 +00:00
|
|
|
v.SetPeer(PeerID())
|
2021-11-08 08:41:39 +00:00
|
|
|
v.SetValue(1.5)
|
|
|
|
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
2021-11-12 11:19:16 +00:00
|
|
|
func PeerToPeerTrust() *reputation.PeerToPeerTrust {
|
2021-11-08 08:41:39 +00:00
|
|
|
v := reputation.NewPeerToPeerTrust()
|
2021-11-12 11:19:16 +00:00
|
|
|
v.SetTrustingPeer(PeerID())
|
|
|
|
v.SetTrust(Trust())
|
2021-11-08 08:41:39 +00:00
|
|
|
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
2021-11-12 11:19:16 +00:00
|
|
|
func GlobalTrust() *reputation.GlobalTrust {
|
2021-11-08 08:41:39 +00:00
|
|
|
v := reputation.NewGlobalTrust()
|
2021-11-12 11:19:16 +00:00
|
|
|
v.SetManager(PeerID())
|
|
|
|
v.SetTrust(Trust())
|
2021-11-08 08:41:39 +00:00
|
|
|
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
2021-11-12 11:19:16 +00:00
|
|
|
func SignedGlobalTrust(t testing.TB) *reputation.GlobalTrust {
|
|
|
|
gt := GlobalTrust()
|
2021-11-08 08:41:39 +00:00
|
|
|
|
2021-12-10 13:56:04 +00:00
|
|
|
p, err := keys.NewPrivateKey()
|
2021-11-08 08:41:39 +00:00
|
|
|
require.NoError(t, err)
|
2021-12-10 13:56:04 +00:00
|
|
|
require.NoError(t, gt.Sign(&p.PrivateKey))
|
2021-11-08 08:41:39 +00:00
|
|
|
|
|
|
|
return gt
|
|
|
|
}
|