Use new go-wire; PubKey etc are interfaces; Keybase refactor

This commit is contained in:
Jae Kwon
2018-01-14 00:31:39 -08:00
parent 67a47e6a0b
commit 788cc0a792
25 changed files with 491 additions and 874 deletions

View File

@ -1,42 +1,26 @@
package crypto
/*
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
wire "github.com/tendermint/go-wire"
)
type BadKey struct {
PrivKeyEd25519
}
// Wrap fulfils interface for PrivKey struct
func (pk BadKey) Wrap() PrivKey {
return PrivKey{pk}
}
func (pk BadKey) Bytes() []byte {
return wire.BinaryBytes(pk.Wrap())
}
func (pk BadKey) ValidateKey() error {
return fmt.Errorf("fuggly key")
}
func init() {
PrivKeyMapper.
RegisterImplementation(BadKey{}, "bad", 0x66)
}
func TestReadPrivKey(t *testing.T) {
assert, require := assert.New(t), require.New(t)
// garbage in, garbage out
garbage := []byte("hjgewugfbiewgofwgewr")
XXX This test wants to register BadKey globally to go-crypto,
but we don't want to support that.
_, err := PrivKeyFromBytes(garbage)
require.Error(err)
@ -47,13 +31,15 @@ func TestReadPrivKey(t *testing.T) {
key PrivKey
valid bool
}{
{edKey.Wrap(), true},
{badKey.Wrap(), false},
{edKey, true},
{badKey, false},
}
for i, tc := range cases {
data := tc.key.Bytes()
fmt.Println(">>>", data)
key, err := PrivKeyFromBytes(data)
fmt.Printf("!!! %#v\n", key, err)
if tc.valid {
assert.NoError(err, "%d", i)
assert.Equal(tc.key, key, "%d", i)
@ -61,5 +47,5 @@ func TestReadPrivKey(t *testing.T) {
assert.Error(err, "%d: %#v", i, key)
}
}
}
*/