cosmos-sdk/std/pubkey_test.go
Aaron Craelius 6740d27b55
Add PublicKeyCodec (#6372)
* Add PublicKeyCodec

* Add tests

* Remove cache codec

* Remove cache codec

* Revert proto changes

* Revert proto changes

* refactor and move docs

* Lint

* Apply suggestions from code review

Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>

Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>
2020-06-09 19:41:28 +00:00

42 lines
1.1 KiB
Go

package std_test
import (
"testing"
"github.com/cosmos/cosmos-sdk/std"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/ed25519"
"github.com/tendermint/tendermint/crypto/secp256k1"
"github.com/tendermint/tendermint/crypto/sr25519"
"github.com/cosmos/cosmos-sdk/crypto/types/multisig"
)
func roundTripTest(t *testing.T, pubKey crypto.PubKey) {
cdc := std.DefaultPublicKeyCodec{}
pubKeyEnc, err := cdc.Encode(pubKey)
require.NoError(t, err)
pubKeyDec, err := cdc.Decode(pubKeyEnc)
require.NoError(t, err)
require.Equal(t, pubKey, pubKeyDec)
}
func TestDefaultPublicKeyCodec(t *testing.T) {
pubKeySecp256k1 := secp256k1.GenPrivKey().PubKey()
roundTripTest(t, pubKeySecp256k1)
pubKeyEd25519 := ed25519.GenPrivKey().PubKey()
roundTripTest(t, pubKeyEd25519)
pubKeySr25519 := sr25519.GenPrivKey().PubKey()
roundTripTest(t, pubKeySr25519)
pubKeyMultisig := multisig.NewPubKeyMultisigThreshold(2, []crypto.PubKey{
pubKeySecp256k1, pubKeyEd25519, pubKeySr25519,
})
roundTripTest(t, pubKeyMultisig)
}