* Update pubkey references * Update ledger_mock * Migrate encoding from tm * Update pubkey prefix * revert ed25519 to tendermint key * random account revert * Revert ed25519 references * revert secp key name * test revert * remove ed25519 * Update x/staking/types/validator.go Co-authored-by: Amaury Martiny <amaury.martiny@protonmail.com> * Revert "remove ed25519" This reverts commit 66d2e1d061aeae81c4c0a3daf718536b09dda19e. * remove ed25519 & sr25519 * Apply suggestions from code review * remove codec Co-authored-by: Marko Baricevic <marbar3778@yahoo.com> Co-authored-by: Amaury Martiny <amaury.martiny@protonmail.com>
45 lines
1.1 KiB
Go
45 lines
1.1 KiB
Go
package std_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
"github.com/tendermint/tendermint/crypto"
|
|
"github.com/tendermint/tendermint/crypto/ed25519"
|
|
"github.com/tendermint/tendermint/crypto/sr25519"
|
|
|
|
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
|
|
"github.com/cosmos/cosmos-sdk/crypto/types/multisig"
|
|
"github.com/cosmos/cosmos-sdk/std"
|
|
)
|
|
|
|
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) {
|
|
roundTripTest(t, nil)
|
|
|
|
roundTripTest(t, crypto.PubKey(nil))
|
|
|
|
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)
|
|
}
|