OSDN Git Service

new repo
[bytom/vapor.git] / vendor / github.com / tendermint / go-crypto / pub_key_test.go
1 package crypto
2
3 import (
4         "encoding/hex"
5         "testing"
6
7         "github.com/btcsuite/btcutil/base58"
8         "github.com/stretchr/testify/assert"
9 )
10
11 type keyData struct {
12         priv string
13         pub  string
14         addr string
15 }
16
17 var secpDataTable = []keyData{
18         {
19                 priv: "a96e62ed3955e65be32703f12d87b6b5cf26039ecfa948dc5107a495418e5330",
20                 pub:  "02950e1cdfcb133d6024109fd489f734eeb4502418e538c28481f22bce276f248c",
21                 addr: "1CKZ9Nx4zgds8tU7nJHotKSDr4a9bYJCa3",
22         },
23 }
24
25 func TestPubKeySecp256k1Address(t *testing.T) {
26         for _, d := range secpDataTable {
27                 privB, _ := hex.DecodeString(d.priv)
28                 pubB, _ := hex.DecodeString(d.pub)
29                 addrB, _, _ := base58.CheckDecode(d.addr)
30
31                 var priv PrivKeySecp256k1
32                 copy(priv[:], privB)
33
34                 pubT := priv.PubKey().Unwrap().(PubKeySecp256k1)
35                 pub := pubT[:]
36                 addr := priv.PubKey().Address()
37
38                 assert.Equal(t, pub, pubB, "Expected pub keys to match")
39                 assert.Equal(t, addr, addrB, "Expected addresses to match")
40         }
41 }