2021-11-08 08:41:39 +00:00
|
|
|
package reputationtest
|
|
|
|
|
|
|
|
import (
|
2023-04-25 09:11:42 +00:00
|
|
|
"testing"
|
2021-11-08 08:41:39 +00:00
|
|
|
|
2021-12-10 13:56:04 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
2023-04-25 09:11:42 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/crypto/test"
|
2021-11-08 08:41:39 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/reputation"
|
|
|
|
)
|
|
|
|
|
2022-06-30 16:08:34 +00:00
|
|
|
func PeerID() (v reputation.PeerID) {
|
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-06-30 16:08:34 +00:00
|
|
|
v.SetPublicKey(p.PublicKey().Bytes())
|
2021-11-08 08:41:39 +00:00
|
|
|
|
2022-06-30 16:08:34 +00:00
|
|
|
return
|
2021-11-08 08:41:39 +00:00
|
|
|
}
|
|
|
|
|
2022-06-30 16:08:34 +00:00
|
|
|
func Trust() (v reputation.Trust) {
|
2021-11-12 11:19:16 +00:00
|
|
|
v.SetPeer(PeerID())
|
2022-06-30 16:08:34 +00:00
|
|
|
v.SetValue(0.5)
|
2021-11-08 08:41:39 +00:00
|
|
|
|
2022-06-30 16:08:34 +00:00
|
|
|
return
|
2021-11-08 08:41:39 +00:00
|
|
|
}
|
|
|
|
|
2022-06-30 16:08:34 +00:00
|
|
|
func PeerToPeerTrust() (v reputation.PeerToPeerTrust) {
|
2021-11-12 11:19:16 +00:00
|
|
|
v.SetTrustingPeer(PeerID())
|
|
|
|
v.SetTrust(Trust())
|
2021-11-08 08:41:39 +00:00
|
|
|
|
2022-06-30 16:08:34 +00:00
|
|
|
return
|
2021-11-08 08:41:39 +00:00
|
|
|
}
|
|
|
|
|
2022-06-30 16:08:34 +00:00
|
|
|
func GlobalTrust() (v reputation.GlobalTrust) {
|
|
|
|
v.Init()
|
2021-11-12 11:19:16 +00:00
|
|
|
v.SetManager(PeerID())
|
|
|
|
v.SetTrust(Trust())
|
2021-11-08 08:41:39 +00:00
|
|
|
|
2022-06-30 16:08:34 +00:00
|
|
|
return
|
2021-11-08 08:41:39 +00:00
|
|
|
}
|
|
|
|
|
2023-04-25 09:11:42 +00:00
|
|
|
func SignedGlobalTrust(t *testing.T) reputation.GlobalTrust {
|
2021-11-12 11:19:16 +00:00
|
|
|
gt := GlobalTrust()
|
2021-11-08 08:41:39 +00:00
|
|
|
|
2023-04-25 09:11:42 +00:00
|
|
|
if err := gt.Sign(test.RandomSigner(t)); err != nil {
|
|
|
|
t.Fatalf("unexpected error from GlobalTrust.Sign: %v", err)
|
2022-06-30 16:08:34 +00:00
|
|
|
}
|
2021-11-08 08:41:39 +00:00
|
|
|
|
|
|
|
return gt
|
|
|
|
}
|