mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-22 09:21:32 +00:00
Use new go-wire; PubKey etc are interfaces; Keybase refactor
This commit is contained in:
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
|
Reference in New Issue
Block a user