Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
robert-zaremba committed Dec 14, 2023
1 parent 6bcc310 commit bc16977
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 8 deletions.
2 changes: 1 addition & 1 deletion tests/tsdk/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
// typically a RegisterInterfaces function in Cosmos SDK modules)
func NewCodec(registrars ...func(types.InterfaceRegistry)) codec.Codec {
interfaceRegistry := types.NewInterfaceRegistry()
std.RegisterInterfaces(interfaceRegistry)
std.RegisterInterfaces(interfaceRegistry) // register SDK interfaces
for _, f := range registrars {
f(interfaceRegistry)
}
Expand Down
5 changes: 2 additions & 3 deletions x/uibc/uics20/ibc_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/tx"
gogoproto "github.com/cosmos/gogoproto/proto"

"github.com/umee-network/umee/v6/x/uibc"
"github.com/umee-network/umee/v6/x/uibc/quota"
Expand Down Expand Up @@ -50,7 +49,7 @@ func (im ICS20Module) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet,
}

if ftData.Memo != "" {
msgs, err := deserializeMemoMsgs(im.cdc, []byte(ftData.Memo))
msgs, err := DeserializeMemoMsgs(im.cdc, []byte(ftData.Memo))
if err != nil {
// TODO: need to verify if we want to stop the handle the error or revert the ibc transerf
ctx.Logger().Error("can't JSON deserialize ftData Memo, expecting list of Msg", "err", err)
Expand Down Expand Up @@ -120,7 +119,7 @@ func deserializeFTData(cdc codec.JSONCodec, packet channeltypes.Packet,
return
}

func deserializeMemoMsgs(cdc codec.JSONCodec, data []byte) ([]sdk.Msg, error) {
func DeserializeMemoMsgs(cdc codec.JSONCodec, data []byte) ([]sdk.Msg, error) {
var m uibc.ICS20Memo
if err := cdc.UnmarshalJSON(data, &m); err != nil {
return nil, err
Expand Down
36 changes: 34 additions & 2 deletions x/uibc/uics20/ics4_module_int_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,37 @@
package main
package uics20_test

import (
"fmt"
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/tx"
"github.com/stretchr/testify/assert"

"github.com/umee-network/umee/v6/tests/accs"
"github.com/umee-network/umee/v6/tests/tsdk"
ltypes "github.com/umee-network/umee/v6/x/leverage/types"
"github.com/umee-network/umee/v6/x/uibc"
"github.com/umee-network/umee/v6/x/uibc/uics20"
)

func TestMsgMarshalling(t *testing.T) {
assert := assert.New(t)
cdc := tsdk.NewCodec(uibc.RegisterInterfaces, ltypes.RegisterInterfaces)
msgs := []sdk.Msg{
&uibc.MsgGovSetIBCStatus{Authority: "auth1", Description: "d1",
IbcStatus: uibc.IBCTransferStatus_IBC_TRANSFER_STATUS_QUOTA_OUT_DISABLED},
ltypes.NewMsgCollateralize(accs.Alice, sdk.NewCoin("ATOM", sdk.NewInt(1020))),
}
anyMsg, err := tx.SetMsgs(msgs)
assert.NoError(err)
var memo = uibc.ICS20Memo{Messages: anyMsg}

bz, err := cdc.MarshalJSON(&memo)
assert.NoError(err)

msgs2, err := uics20.DeserializeMemoMsgs(cdc, bz)
assert.NoError(err)
for i := range msgs2 {
assert.Equal(msgs[i], msgs2[i], "idx=%d", i)
}
}
3 changes: 1 addition & 2 deletions x/uibc/uics20/ics4_wrapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package uics20_test
import (
"testing"

"gotest.tools/v3/assert"

"github.com/cosmos/cosmos-sdk/codec"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -14,6 +12,7 @@ import (
clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
porttypes "github.com/cosmos/ibc-go/v7/modules/core/05-port/types"
"github.com/golang/mock/gomock"
"gotest.tools/v3/assert"

"github.com/umee-network/umee/v6/tests/tsdk"
lfixtures "github.com/umee-network/umee/v6/x/leverage/fixtures"
Expand Down

0 comments on commit bc16977

Please sign in to comment.