crypto: Add a way to go from pubkey to route (#2574)

This is intended for use in a future PR for #2414
This commit is contained in:
Dev Ojha
2018-10-09 05:41:33 -07:00
committed by Alexander Simmerl
parent e7708850c0
commit 8761b27489
2 changed files with 44 additions and 1 deletions

View File

@@ -8,6 +8,7 @@ import (
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/ed25519"
"github.com/tendermint/tendermint/crypto/multisig"
"github.com/tendermint/tendermint/crypto/secp256k1"
)
@@ -127,3 +128,24 @@ func TestPubKeyInvalidDataProperReturnsEmpty(t *testing.T) {
require.NotNil(t, err, "expecting a non-nil error")
require.Nil(t, pk, "expecting an empty public key on error")
}
func TestPubkeyAminoRoute(t *testing.T) {
tests := []struct {
key crypto.PubKey
want string
wantErr bool
}{
{ed25519.PubKeyEd25519{}, ed25519.PubKeyAminoRoute, false},
{secp256k1.PubKeySecp256k1{}, secp256k1.PubKeyAminoRoute, false},
{&multisig.PubKeyMultisigThreshold{}, multisig.PubKeyMultisigThresholdAminoRoute, false},
}
for i, tc := range tests {
got, err := PubkeyAminoRoute(cdc, tc.key)
if tc.wantErr {
require.Error(t, err, "tc %d", i)
} else {
require.NoError(t, err, "tc %d", i)
require.Equal(t, tc.want, got, "tc %d", i)
}
}
}