mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 02:12:23 +00:00
crypto: add test for UnmarshalPubkey
This commit is contained in:
parent
7e2f6e8a64
commit
9295467f99
1 changed files with 29 additions and 0 deletions
|
|
@ -23,9 +23,11 @@ import (
|
|||
"io/ioutil"
|
||||
"math/big"
|
||||
"os"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
)
|
||||
|
||||
var testAddrHex = "970e8128ab834e8eac17ab8e3812f010678cf791"
|
||||
|
|
@ -56,6 +58,33 @@ func BenchmarkSha3(b *testing.B) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestUnmarshalPubkey(t *testing.T) {
|
||||
key, err := UnmarshalPubkey(nil)
|
||||
if err != errInvalidPubkey || key != nil {
|
||||
t.Fatalf("expected error, got %v, %v", err, key)
|
||||
}
|
||||
key, err = UnmarshalPubkey([]byte{1, 2, 3})
|
||||
if err != errInvalidPubkey || key != nil {
|
||||
t.Fatalf("expected error, got %v, %v", err, key)
|
||||
}
|
||||
|
||||
var (
|
||||
enc, _ = hex.DecodeString("04760c4460e5336ac9bbd87952a3c7ec4363fc0a97bd31c86430806e287b437fd1b01abc6e1db640cf3106b520344af1d58b00b57823db3e1407cbc433e1b6d04d")
|
||||
dec = &ecdsa.PublicKey{
|
||||
Curve: S256(),
|
||||
X: hexutil.MustDecodeBig("0x760c4460e5336ac9bbd87952a3c7ec4363fc0a97bd31c86430806e287b437fd1"),
|
||||
Y: hexutil.MustDecodeBig("0xb01abc6e1db640cf3106b520344af1d58b00b57823db3e1407cbc433e1b6d04d"),
|
||||
}
|
||||
)
|
||||
key, err = UnmarshalPubkey(enc)
|
||||
if err != nil {
|
||||
t.Fatalf("expected no error, got %v", err)
|
||||
}
|
||||
if !reflect.DeepEqual(key, dec) {
|
||||
t.Fatal("wrong result")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSign(t *testing.T) {
|
||||
key, _ := HexToECDSA(testPrivHex)
|
||||
addr := common.HexToAddress(testAddrHex)
|
||||
|
|
|
|||
Loading…
Reference in a new issue