github.com/DFWallet/tendermint-cosmos@v0.0.2/crypto/ed25519/ed25519_test.go (about)

     1  package ed25519_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  	"github.com/stretchr/testify/require"
     8  
     9  	"github.com/DFWallet/tendermint-cosmos/crypto"
    10  	"github.com/DFWallet/tendermint-cosmos/crypto/ed25519"
    11  )
    12  
    13  func TestSignAndValidateEd25519(t *testing.T) {
    14  
    15  	privKey := ed25519.GenPrivKey()
    16  	pubKey := privKey.PubKey()
    17  
    18  	msg := crypto.CRandBytes(128)
    19  	sig, err := privKey.Sign(msg)
    20  	require.Nil(t, err)
    21  
    22  	// Test the signature
    23  	assert.True(t, pubKey.VerifySignature(msg, sig))
    24  
    25  	// Mutate the signature, just one bit.
    26  	// TODO: Replace this with a much better fuzzer, tendermint/ed25519/issues/10
    27  	sig[7] ^= byte(0x01)
    28  
    29  	assert.False(t, pubKey.VerifySignature(msg, sig))
    30  }