-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
Copy pathpubkey_test.go
44 lines (33 loc) · 1.13 KB
/
pubkey_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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)
}