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