Skip to content

Commit

Permalink
test: add unmarshaling test
Browse files Browse the repository at this point in the history
  • Loading branch information
colin-axner committed Mar 22, 2023
1 parent be5a766 commit 767c5af
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions modules/apps/27-interchain-accounts/types/codec_test.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,41 @@
package types_test

import (
"fmt"

"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
"github.com/cosmos/gogoproto/proto"

"github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types"
"github.com/cosmos/ibc-go/v7/modules/core/exported"
"github.com/cosmos/ibc-go/v7/testing/simapp"
)

func (suite *TypesTestSuite) TestUnmarshalCallbackPacketData() {
sourceCallbackAddress := "sourceCallbackAddress"

packetData := types.InterchainAccountPacketData{
Type: types.EXECUTE_TX,
Data: []byte("data"),
Memo: fmt.Sprintf("{\"callbacks\": {\"src_callback_address\": \"%s\"}}", sourceCallbackAddress),
}

types.RegisterInterfaces(types.ModuleCdc.InterfaceRegistry())
data, err := types.ModuleCdc.MarshalInterfaceJSON(&packetData)
suite.Require().NoError(err)

var callbackPacketData exported.CallbackPacketData
err = suite.chainA.App.AppCodec().UnmarshalInterfaceJSON(data, &callbackPacketData)
suite.Require().NoError(err, "failed to unmarshal into callback packet data interface")

suite.Require().Equal(sourceCallbackAddress, callbackPacketData.GetSourceCallbackAddress())
suite.Require().Equal("", callbackPacketData.GetDestCallbackAddress())
suite.Require().Equal(uint64(0), callbackPacketData.UserDefinedGasLimit())
}

// mockSdkMsg defines a mock struct, used for testing codec error scenarios
type mockSdkMsg struct{}

Expand Down

0 comments on commit 767c5af

Please sign in to comment.