Skip to content

Commit

Permalink
add core.MsgID to the tendermint module's InterfaceRegistry
Browse files Browse the repository at this point in the history
Signed-off-by: Masanori Yoshida <[email protected]>
  • Loading branch information
siburu committed Oct 16, 2023
1 parent 38e3889 commit 306bd6b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
4 changes: 4 additions & 0 deletions chains/tendermint/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
(*core.ProverConfig)(nil),
&ProverConfig{},
)
registry.RegisterImplementations(
(*core.MsgID)(nil),
&MsgID{},
)
}
39 changes: 39 additions & 0 deletions chains/tendermint/codec_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}

0 comments on commit 306bd6b

Please sign in to comment.