diff --git a/chains/tendermint/codec.go b/chains/tendermint/codec.go index 34ca72b9..f9db614e 100644 --- a/chains/tendermint/codec.go +++ b/chains/tendermint/codec.go @@ -16,4 +16,8 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) { (*core.ProverConfig)(nil), &ProverConfig{}, ) + registry.RegisterImplementations( + (*core.MsgID)(nil), + &MsgID{}, + ) } diff --git a/chains/tendermint/codec_test.go b/chains/tendermint/codec_test.go new file mode 100644 index 00000000..4c87c50a --- /dev/null +++ b/chains/tendermint/codec_test.go @@ -0,0 +1,39 @@ +package tendermint_test + +import ( + "testing" + + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/hyperledger-labs/yui-relayer/chains/tendermint" + "github.com/hyperledger-labs/yui-relayer/core" +) + +func TestCodec(t *testing.T) { + codec := codec.NewProtoCodec(types.NewInterfaceRegistry()) + tendermint.RegisterInterfaces(codec.InterfaceRegistry()) + + orig := tendermint.MsgID{ + TxHash: "hoge", + MsgIndex: 123, + } + + bz, err := codec.MarshalInterface(core.MsgID(&orig)) + if err != nil { + t.Fatalf("failed to marshal from tendermint.MsgID to Any: %v", err) + } + + var msgID core.MsgID + if err := codec.UnmarshalInterface(bz, &msgID); err != nil { + t.Fatalf("failed to unmarshal from Any to core.MsgID: %v", err) + } + + tmMsgID, ok := msgID.(*tendermint.MsgID) + if !ok { + t.Fatalf("unexpected MsgID instance type: %T", msgID) + } + + if orig != *tmMsgID { + t.Fatalf("unmatched MsgID values: %v != %v", orig, *tmMsgID) + } +}