neo-go/pkg/consensus/crypto_test.go

29 lines
513 B
Go
Raw Normal View History

2019-11-15 10:32:40 +00:00
package consensus
import (
"crypto/sha256"
2019-11-15 10:32:40 +00:00
"testing"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
2019-11-15 10:32:40 +00:00
"github.com/stretchr/testify/require"
)
func TestCrypt(t *testing.T) {
key, err := keys.NewPrivateKey()
require.NoError(t, err)
priv := privateKey{key}
pub := key.PublicKey()
2019-11-15 10:32:40 +00:00
data := []byte{1, 2, 3, 4}
hash := sha256.Sum256(data)
2019-11-15 10:32:40 +00:00
sign, err := priv.Sign(data)
require.NoError(t, err)
require.True(t, pub.Verify(sign, hash[:]))
2019-11-15 10:32:40 +00:00
sign[0] = ^sign[0]
require.False(t, pub.Verify(sign, hash[:]))
2019-11-15 10:32:40 +00:00
}