Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test: fix tests
  • Loading branch information
srdtrk committed Dec 17, 2025
commit 72b696369314e53f60864f0a5cfe4b1387405b46
151 changes: 132 additions & 19 deletions modules/apps/27-interchain-accounts/host/keeper/relay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ func (s *KeeperTestSuite) TestJSONOnRecvPacket() {
expErr error
}{
{
"interchain account successfully executes an arbitrary message type using the * (allow all message types) param",
"success: interchain account successfully executes an arbitrary message type using the * (allow all message types) param",
func(icaAddress string) {
proposal, err := govtypesv1.NewProposal([]sdk.Msg{getTestProposalMessage()}, govtypesv1.DefaultStartingProposalID, s.chainA.GetContext().BlockTime(), s.chainA.GetContext().BlockTime(), "test proposal", "title", "Description", sdk.AccAddress(interchainAccountAddr), false)
s.Require().NoError(err)
Expand All @@ -581,8 +581,9 @@ func (s *KeeperTestSuite) TestJSONOnRecvPacket() {
{
"@type": "/cosmos.gov.v1.MsgVote",
"voter": "` + icaAddress + `",
"proposal_id": 1,
"option": 1
"proposal_id": "1",
"option": "VOTE_OPTION_YES",
"metadata": ""
}
]
}`)
Expand All @@ -601,7 +602,7 @@ func (s *KeeperTestSuite) TestJSONOnRecvPacket() {
nil,
},
{
"interchain account successfully executes banktypes.MsgSend",
"success: interchain account successfully executes banktypes.MsgSend",
func(icaAddress string) {
msgBytes := []byte(`{
"messages": [
Expand All @@ -626,7 +627,7 @@ func (s *KeeperTestSuite) TestJSONOnRecvPacket() {
nil,
},
{
"interchain account successfully executes govtypesv1.MsgSubmitProposal",
"success: interchain account successfully executes govtypesv1.MsgSubmitProposal",
func(icaAddress string) {
msgBytes := []byte(`{
"messages": [
Expand Down Expand Up @@ -655,7 +656,7 @@ func (s *KeeperTestSuite) TestJSONOnRecvPacket() {
nil,
},
{
"interchain account successfully executes govtypesv1.MsgVote",
"success: interchain account successfully executes govtypesv1.MsgVote",
func(icaAddress string) {
proposal, err := govtypesv1.NewProposal([]sdk.Msg{getTestProposalMessage()}, govtypesv1.DefaultStartingProposalID, s.chainA.GetContext().BlockTime(), s.chainA.GetContext().BlockTime(), "test proposal", "title", "Description", sdk.AccAddress(interchainAccountAddr), false)
s.Require().NoError(err)
Expand All @@ -670,8 +671,9 @@ func (s *KeeperTestSuite) TestJSONOnRecvPacket() {
{
"@type": "/cosmos.gov.v1.MsgVote",
"voter": "` + icaAddress + `",
"proposal_id": 1,
"option": 1
"proposal_id": "1",
"option": "VOTE_OPTION_YES",
"metadata": ""
}
]
}`)
Expand All @@ -688,7 +690,7 @@ func (s *KeeperTestSuite) TestJSONOnRecvPacket() {
nil,
},
{
"interchain account successfully executes govtypesv1.MsgSubmitProposal, govtypesv1.MsgDeposit, and then govtypesv1.MsgVote sequentially",
"success: interchain account successfully executes govtypesv1.MsgSubmitProposal, govtypesv1.MsgDeposit, and then govtypesv1.MsgVote sequentially",
func(icaAddress string) {
msgBytes := []byte(`{
"messages": [
Expand All @@ -704,15 +706,16 @@ func (s *KeeperTestSuite) TestJSONOnRecvPacket() {
},
{
"@type": "/cosmos.gov.v1.MsgDeposit",
"proposal_id": 1,
"proposal_id": "1",
"depositor": "` + icaAddress + `",
"amount": [{ "denom": "stake", "amount": "10000000" }]
},
{
"@type": "/cosmos.gov.v1.MsgVote",
"voter": "` + icaAddress + `",
"proposal_id": 1,
"option": 1
"proposal_id": "1",
"option": "VOTE_OPTION_YES",
"metadata": ""
}
]
}`)
Expand All @@ -729,7 +732,7 @@ func (s *KeeperTestSuite) TestJSONOnRecvPacket() {
nil,
},
{
"interchain account successfully executes transfertypes.MsgTransfer",
"success: interchain account successfully executes transfertypes.MsgTransfer",
func(icaAddress string) {
transferPath := ibctesting.NewTransferPath(s.chainB, s.chainC)

Expand All @@ -744,9 +747,12 @@ func (s *KeeperTestSuite) TestJSONOnRecvPacket() {
"token": { "denom": "stake", "amount": "100" },
"sender": "` + icaAddress + `",
"receiver": "cosmos15ulrf36d4wdtrtqzkgaan9ylwuhs7k7qz753uk",
"timeout_height": { "revision_number": 1, "revision_height": 100 },
"timeout_timestamp": 0,
"memo": ""
"timeout_height": { "revision_number": "1", "revision_height": "100" },
"timeout_timestamp": "0",
"memo": "",
"encoding": "",
"use_aliasing": false

}
]
}`)
Expand All @@ -763,7 +769,7 @@ func (s *KeeperTestSuite) TestJSONOnRecvPacket() {
nil,
},
{
"unregistered sdk.Msg",
"failure: unregistered sdk.Msg",
func(icaAddress string) {
msgBytes := []byte(`{"messages":[{}]}`)
byteArrayString := strings.Join(strings.Fields(fmt.Sprint(msgBytes)), ",") //nolint:staticcheck
Expand All @@ -779,7 +785,7 @@ func (s *KeeperTestSuite) TestJSONOnRecvPacket() {
ibcerrors.ErrInvalidType,
},
{
"message type not allowed banktypes.MsgSend",
"failure: message type not allowed banktypes.MsgSend",
func(icaAddress string) {
msgBytes := []byte(`{
"messages": [
Expand All @@ -804,7 +810,7 @@ func (s *KeeperTestSuite) TestJSONOnRecvPacket() {
ibcerrors.ErrUnauthorized,
},
{
"unauthorised: signer address is not the interchain account associated with the controller portID",
"failure: signer address is not the interchain account associated with the controller portID",
func(icaAddress string) {
msgBytes := []byte(`{
"messages": [
Expand All @@ -828,6 +834,113 @@ func (s *KeeperTestSuite) TestJSONOnRecvPacket() {
},
ibcerrors.ErrInvalidType,
},
{
"failure: missing optional metadata field",
func(icaAddress string) {
proposal, err := govtypesv1.NewProposal([]sdk.Msg{getTestProposalMessage()}, govtypesv1.DefaultStartingProposalID, s.chainA.GetContext().BlockTime(), s.chainA.GetContext().BlockTime(), "test proposal", "title", "Description", sdk.AccAddress(interchainAccountAddr), false)
s.Require().NoError(err)

err = s.chainB.GetSimApp().GovKeeper.SetProposal(s.chainB.GetContext(), proposal)
s.Require().NoError(err)
err = s.chainB.GetSimApp().GovKeeper.ActivateVotingPeriod(s.chainB.GetContext(), proposal)
s.Require().NoError(err)

msgBytes := []byte(`{
"messages": [
{
"@type": "/cosmos.gov.v1.MsgVote",
"voter": "` + icaAddress + `",
"proposal_id": "1",
"option": "VOTE_OPTION_YES"
}
]
}`)
// this is the way cosmwasm encodes byte arrays by default
// golang doesn't use this encoding by default, but it can still deserialize:
byteArrayString := strings.Join(strings.Fields(fmt.Sprint(msgBytes)), ",") //nolint:staticcheck

packetData = []byte(`{
"type": 1,
"data":` + byteArrayString + `
}`)

params := types.NewParams(true, []string{"*"})
s.chainB.GetSimApp().ICAHostKeeper.SetParams(s.chainB.GetContext(), params)
},
ibcerrors.ErrInvalidType,
},
{
"failure: alternative int representation of enum field",
func(icaAddress string) {
proposal, err := govtypesv1.NewProposal([]sdk.Msg{getTestProposalMessage()}, govtypesv1.DefaultStartingProposalID, s.chainA.GetContext().BlockTime(), s.chainA.GetContext().BlockTime(), "test proposal", "title", "Description", sdk.AccAddress(interchainAccountAddr), false)
s.Require().NoError(err)

err = s.chainB.GetSimApp().GovKeeper.SetProposal(s.chainB.GetContext(), proposal)
s.Require().NoError(err)
err = s.chainB.GetSimApp().GovKeeper.ActivateVotingPeriod(s.chainB.GetContext(), proposal)
s.Require().NoError(err)

msgBytes := []byte(`{
"messages": [
{
"@type": "/cosmos.gov.v1.MsgVote",
"voter": "` + icaAddress + `",
"proposal_id": "1",
"option": 1,
"metadata": ""
}
]
}`)
// this is the way cosmwasm encodes byte arrays by default
// golang doesn't use this encoding by default, but it can still deserialize:
byteArrayString := strings.Join(strings.Fields(fmt.Sprint(msgBytes)), ",") //nolint:staticcheck

packetData = []byte(`{
"type": 1,
"data":` + byteArrayString + `
}`)

params := types.NewParams(true, []string{"*"})
s.chainB.GetSimApp().ICAHostKeeper.SetParams(s.chainB.GetContext(), params)
},
ibcerrors.ErrInvalidType,
},
{
"failure: alternative integer field representation",
func(icaAddress string) {
proposal, err := govtypesv1.NewProposal([]sdk.Msg{getTestProposalMessage()}, govtypesv1.DefaultStartingProposalID, s.chainA.GetContext().BlockTime(), s.chainA.GetContext().BlockTime(), "test proposal", "title", "Description", sdk.AccAddress(interchainAccountAddr), false)
s.Require().NoError(err)

err = s.chainB.GetSimApp().GovKeeper.SetProposal(s.chainB.GetContext(), proposal)
s.Require().NoError(err)
err = s.chainB.GetSimApp().GovKeeper.ActivateVotingPeriod(s.chainB.GetContext(), proposal)
s.Require().NoError(err)

msgBytes := []byte(`{
"messages": [
{
"@type": "/cosmos.gov.v1.MsgVote",
"voter": "` + icaAddress + `",
"proposal_id": 1,
"option": "VOTE_OPTION_YES",
"metadata": ""
}
]
}`)
// this is the way cosmwasm encodes byte arrays by default
// golang doesn't use this encoding by default, but it can still deserialize:
byteArrayString := strings.Join(strings.Fields(fmt.Sprint(msgBytes)), ",") //nolint:staticcheck

packetData = []byte(`{
"type": 1,
"data":` + byteArrayString + `
}`)

params := types.NewParams(true, []string{"*"})
s.chainB.GetSimApp().ICAHostKeeper.SetParams(s.chainB.GetContext(), params)
},
ibcerrors.ErrInvalidType,
},
}

for _, ordering := range []channeltypes.Order{channeltypes.UNORDERED, channeltypes.ORDERED} {
Expand Down
2 changes: 1 addition & 1 deletion modules/apps/27-interchain-accounts/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import (
"encoding/json"
"reflect"

"github.com/cosmos/gogoproto/proto"

Expand Down Expand Up @@ -102,7 +102,7 @@
if isEqual, err := equalJSON(data, reconstructedData); err != nil {
return nil, errorsmod.Wrapf(ibcerrors.ErrInvalidType, "cannot compare original and reconstructed JSON: %v", err)
} else if !isEqual {
return nil, errorsmod.Wrapf(ibcerrors.ErrInvalidType, "original and reconstructed JSON do not match, all optional fields must be explicitly set")
return nil, errorsmod.Wrapf(ibcerrors.ErrInvalidType, "original and reconstructed JSON objects do not match, original: %s, reconstructed: %s", string(data), string(reconstructedData))
}
default:
return nil, errorsmod.Wrapf(ErrInvalidCodec, "unsupported encoding format %s", encoding)
Expand Down
Loading