github.com/gnolang/gno@v0.0.0-20240520182011-228e9d0192ce/tm2/pkg/crypto/mock/mock_test.go (about)

     1  package mock_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/gnolang/gno/tm2/pkg/crypto"
     7  	"github.com/gnolang/gno/tm2/pkg/crypto/mock"
     8  	"github.com/stretchr/testify/assert"
     9  	"github.com/stretchr/testify/require"
    10  )
    11  
    12  func TestSignAndValidateMock(t *testing.T) {
    13  	t.Parallel()
    14  
    15  	privKey := mock.PrivKeyMock([]byte{0x01})
    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.VerifyBytes(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.VerifyBytes(msg, sig))
    30  }