github.com/cosmos/cosmos-sdk@v0.50.1/crypto/ledger/encode_test.go (about) 1 package ledger 2 3 import ( 4 "os" 5 "testing" 6 7 "github.com/stretchr/testify/require" 8 9 cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" 10 ) 11 12 func checkAminoJSON(t *testing.T, src, dst interface{}, isNil bool) { 13 // Marshal to JSON bytes. 14 js, err := cdc.MarshalJSON(src) 15 require.Nil(t, err, "%+v", err) 16 if isNil { 17 require.Equal(t, string(js), `null`) 18 } else { 19 require.Contains(t, string(js), `"type":`) 20 require.Contains(t, string(js), `"value":`) 21 } 22 // Unmarshal. 23 err = cdc.UnmarshalJSON(js, dst) 24 require.Nil(t, err, "%+v", err) 25 } 26 27 func ExamplePrintRegisteredTypes() { //nolint:govet // ignore for examples 28 _ = cdc.PrintTypes(os.Stdout) 29 // | Type | Name | Prefix | Length | Notes | 30 // | ---- | ---- | ------ | ----- | ------ | 31 // | PrivKeyLedgerSecp256k1 | tendermint/PrivKeyLedgerSecp256k1 | 0x10CAB393 | variable | | 32 // | PubKey | tendermint/PubKeyEd25519 | 0x1624DE64 | variable | | 33 // | PubKey | tendermint/PubKeySr25519 | 0x0DFB1005 | variable | | 34 // | PubKey | tendermint/PubKeySecp256k1 | 0xEB5AE987 | variable | | 35 // | PubKeyMultisigThreshold | tendermint/PubKeyMultisigThreshold | 0x22C1F7E2 | variable | | 36 // | PrivKey | tendermint/PrivKeyEd25519 | 0xA3288910 | variable | | 37 // | PrivKey | tendermint/PrivKeySr25519 | 0x2F82D78B | variable | | 38 // | PrivKey | tendermint/PrivKeySecp256k1 | 0xE1B0F79B | variable | | 39 } 40 41 func TestNilEncodings(t *testing.T) { 42 // Check nil Signature. 43 var a, b []byte 44 checkAminoJSON(t, &a, &b, true) 45 require.EqualValues(t, a, b) 46 47 // Check nil PubKey. 48 var c, d cryptotypes.PubKey 49 checkAminoJSON(t, &c, &d, true) 50 require.EqualValues(t, c, d) 51 52 // Check nil PrivKey. 53 var e, f cryptotypes.PrivKey 54 checkAminoJSON(t, &e, &f, true) 55 require.EqualValues(t, e, f) 56 }