forked from strangelove-ventures/poa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
codec_test.go
45 lines (36 loc) · 1.22 KB
/
codec_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
45
package poa
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
const prefix = "/strangelove_ventures.poa.v1."
func TestCodecRegisterInterfaces(t *testing.T) {
registry := codectypes.NewInterfaceRegistry()
registry.RegisterInterface(sdk.MsgInterfaceProtoName, (*sdk.Msg)(nil))
RegisterInterfaces(registry)
impls := registry.ListImplementations(sdk.MsgInterfaceProtoName)
require.Len(t, impls, 6)
require.ElementsMatch(t, []string{
prefix + "MsgSetPower",
prefix + "MsgCreateValidator",
prefix + "MsgUpdateParams",
prefix + "MsgRemoveValidator",
prefix + "MsgRemovePending",
prefix + "MsgUpdateStakingParams",
}, impls)
}
func TestRegisterLegacyAminoCodec(t *testing.T) {
cdc := codec.NewLegacyAmino()
RegisterLegacyAminoCodec(cdc)
bz, err := cdc.MarshalJSON(MsgSetPower{
Sender: "sender",
ValidatorAddress: "validator",
Power: 1_234_567,
Unsafe: true,
})
require.NoError(t, err)
require.Equal(t, `{"type":"poa/MsgSetPower","value":{"sender":"sender","validator_address":"validator","power":"1234567","unsafe":true}}`, string(bz))
}