github.com/evdatsion/aphelion-dpos-bft@v0.32.1/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 "github.com/evdatsion/aphelion-dpos-bft/crypto" 9 "github.com/evdatsion/aphelion-dpos-bft/crypto/ed25519" 10 ) 11 12 func TestSignAndValidateEd25519(t *testing.T) { 13 14 privKey := ed25519.GenPrivKey() 15 pubKey := privKey.PubKey() 16 17 msg := crypto.CRandBytes(128) 18 sig, err := privKey.Sign(msg) 19 require.Nil(t, err) 20 21 // Test the signature 22 assert.True(t, pubKey.VerifyBytes(msg, sig)) 23 24 // Mutate the signature, just one bit. 25 // TODO: Replace this with a much better fuzzer, tendermint/ed25519/issues/10 26 sig[7] ^= byte(0x01) 27 28 assert.False(t, pubKey.VerifyBytes(msg, sig)) 29 }