mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-17 01:13:45 +00:00
crypto: add random test for pubkey compression
This commit is contained in:
parent
1dbfc87b00
commit
4565c6e1e2
1 changed files with 19 additions and 0 deletions
|
|
@ -19,6 +19,7 @@ package crypto
|
|||
import (
|
||||
"bytes"
|
||||
"crypto/ecdsa"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
|
|
@ -100,6 +101,24 @@ func TestCompressPubkey(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestPubkeyRandom(t *testing.T) {
|
||||
const runs = 200
|
||||
|
||||
for i := 0; i < runs; i++ {
|
||||
key, err := GenerateKey()
|
||||
if err != nil {
|
||||
t.Fatalf("iteration %d: %v", i, err)
|
||||
}
|
||||
pubkey2, err := DecompressPubkey(CompressPubkey(&key.PublicKey))
|
||||
if err != nil {
|
||||
t.Fatalf("iteration %d: %v", i, err)
|
||||
}
|
||||
if !reflect.DeepEqual(key.PublicKey, *pubkey2) {
|
||||
t.Fatalf("iteration %d: keys not equal", i)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkEcrecoverSignature(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
if _, err := Ecrecover(testmsg, testsig); err != nil {
|
||||
|
|
|
|||
Loading…
Reference in a new issue