forked from TrueCloudLab/frostfs-sdk-go
[#64] object: move package from neofs-api-go
Also, remove deprecated method. Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
bdb99877f6
commit
39d3317ef6
28 changed files with 3268 additions and 0 deletions
81
object/fmt_test.go
Normal file
81
object/fmt_test.go
Normal file
|
@ -0,0 +1,81 @@
|
|||
package object
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"testing"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestVerificationFields(t *testing.T) {
|
||||
obj := NewRaw()
|
||||
|
||||
payload := make([]byte, 10)
|
||||
_, _ = rand.Read(payload)
|
||||
|
||||
obj.SetPayload(payload)
|
||||
obj.SetPayloadSize(uint64(len(payload)))
|
||||
|
||||
p, err := keys.NewPrivateKey()
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, SetVerificationFields(&p.PrivateKey, obj))
|
||||
|
||||
require.NoError(t, CheckVerificationFields(obj.Object()))
|
||||
|
||||
items := []struct {
|
||||
corrupt func()
|
||||
restore func()
|
||||
}{
|
||||
{
|
||||
corrupt: func() {
|
||||
payload[0]++
|
||||
},
|
||||
restore: func() {
|
||||
payload[0]--
|
||||
},
|
||||
},
|
||||
{
|
||||
corrupt: func() {
|
||||
obj.SetPayloadSize(obj.PayloadSize() + 1)
|
||||
},
|
||||
restore: func() {
|
||||
obj.SetPayloadSize(obj.PayloadSize() - 1)
|
||||
},
|
||||
},
|
||||
{
|
||||
corrupt: func() {
|
||||
obj.ID().ToV2().GetValue()[0]++
|
||||
},
|
||||
restore: func() {
|
||||
obj.ID().ToV2().GetValue()[0]--
|
||||
},
|
||||
},
|
||||
{
|
||||
corrupt: func() {
|
||||
obj.Signature().Key()[0]++
|
||||
},
|
||||
restore: func() {
|
||||
obj.Signature().Key()[0]--
|
||||
},
|
||||
},
|
||||
{
|
||||
corrupt: func() {
|
||||
obj.Signature().Sign()[0]++
|
||||
},
|
||||
restore: func() {
|
||||
obj.Signature().Sign()[0]--
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, item := range items {
|
||||
item.corrupt()
|
||||
|
||||
require.Error(t, CheckVerificationFields(obj.Object()))
|
||||
|
||||
item.restore()
|
||||
|
||||
require.NoError(t, CheckVerificationFields(obj.Object()))
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue