Skip to content

Commit

Permalink
Merge branch 'release/v10.0.x' into callbacks/release/v0.3.x+ibc-go-v…
Browse files Browse the repository at this point in the history
…10.0.x
  • Loading branch information
gjermundgaraba committed Feb 27, 2025
2 parents d65db00 + 0b45a17 commit c7a9c56
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 5 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ clean:
build-docker-wasm:
./scripts/build-wasm-simapp-docker.sh $(tag)

build-docker-local:
docker build -t ghcr.io/cosmos/ibc-go-simd:local --build-arg IBC_GO_VERSION=local .

.PHONY: build-docker-wasm

###############################################################################
Expand Down
2 changes: 1 addition & 1 deletion e2e/testsuite/query/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
ibcexported "github.com/cosmos/ibc-go/v10/modules/core/exported"
)

const queryPathTransferDenoms = "/ibc.applications.transfer.v2.QueryV2/Denoms"
const queryPathTransferDenoms = "/ibc.applications.transfer.v1.Query/Denoms"

// ModuleAccountAddress returns the address of the given module on the given chain.
// Added because interchaintest's method doesn't work.
Expand Down
2 changes: 1 addition & 1 deletion modules/apps/callbacks/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require (
github.com/cosmos/cosmos-db v1.1.1
github.com/cosmos/cosmos-sdk v0.50.10
github.com/cosmos/gogoproto v1.7.0
github.com/cosmos/ibc-go/v10 v10.0.0-beta.1
github.com/cosmos/ibc-go/v10 v10.0.0-beta.2
github.com/spf13/cast v1.7.1
github.com/stretchr/testify v1.10.0
)
Expand Down
4 changes: 2 additions & 2 deletions modules/apps/callbacks/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,8 @@ github.com/cosmos/gogoproto v1.7.0 h1:79USr0oyXAbxg3rspGh/m4SWNyoz/GLaAh0QlCe2fr
github.com/cosmos/gogoproto v1.7.0/go.mod h1:yWChEv5IUEYURQasfyBW5ffkMHR/90hiHgbNgrtp4j0=
github.com/cosmos/iavl v1.2.0 h1:kVxTmjTh4k0Dh1VNL046v6BXqKziqMDzxo93oh3kOfM=
github.com/cosmos/iavl v1.2.0/go.mod h1:HidWWLVAtODJqFD6Hbne2Y0q3SdxByJepHUOeoH4LiI=
github.com/cosmos/ibc-go/v10 v10.0.0-beta.1 h1:IPAKp0ySxpkBCwzhaaVhbwTGZFnIm2Qq6owD6LW2Dvo=
github.com/cosmos/ibc-go/v10 v10.0.0-beta.1/go.mod h1:ikF0o+cl0V7jwwe74fceRD5N2T7yfpRZju2fVJDdcu8=
github.com/cosmos/ibc-go/v10 v10.0.0-beta.2 h1:klst7EqzGK5LVuZxTn6Vcj7GD+H1hKuSzj78VVPvo44=
github.com/cosmos/ibc-go/v10 v10.0.0-beta.2/go.mod h1:ikF0o+cl0V7jwwe74fceRD5N2T7yfpRZju2fVJDdcu8=
github.com/cosmos/ics23/go v0.11.0 h1:jk5skjT0TqX5e5QJbEnwXIS2yI2vnmLOgpQPeM5RtnU=
github.com/cosmos/ics23/go v0.11.0/go.mod h1:A8OjxPE67hHST4Icw94hOxxFEJMBG031xIGF/JHNIY0=
github.com/cosmos/ledger-cosmos-go v0.13.3 h1:7ehuBGuyIytsXbd4MP43mLeoN2LTOEnk5nvue4rK+yM=
Expand Down
6 changes: 6 additions & 0 deletions modules/apps/transfer/ibc_module.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package transfer

import (
"bytes"
"fmt"
"math"
"slices"
Expand Down Expand Up @@ -231,6 +232,11 @@ func (im IBCModule) OnAcknowledgementPacket(
return err
}

bz := types.ModuleCdc.MustMarshalJSON(&ack)
if !bytes.Equal(bz, acknowledgement) {
return errorsmod.Wrapf(ibcerrors.ErrInvalidType, "acknowledgement did not marshal to expected bytes: %X ≠ %X", bz, acknowledgement)
}

if err := im.keeper.OnAcknowledgementPacket(ctx, packet.SourcePort, packet.SourceChannel, data, ack); err != nil {
return err
}
Expand Down
118 changes: 118 additions & 0 deletions modules/apps/transfer/ibc_module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,124 @@ func (suite *TransferTestSuite) TestOnRecvPacket() {
}
}

func (suite *TransferTestSuite) TestOnAcknowledgePacket() {
var (
path *ibctesting.Path
packet channeltypes.Packet
ack []byte
)

testCases := []struct {
name string
malleate func()
expError error
expRefund bool
}{
{
"success",
func() {},
nil,
false,
},
{
"success: refund coins",
func() {
ack = channeltypes.NewErrorAcknowledgement(ibcerrors.ErrInsufficientFunds).Acknowledgement()
},
nil,
true,
},
{
"cannot refund ack on non-existent channel",
func() {
ack = channeltypes.NewErrorAcknowledgement(ibcerrors.ErrInsufficientFunds).Acknowledgement()

packet.SourceChannel = "channel-100"
},
errors.New("unable to unescrow tokens"),
false,
},
{
"invalid packet data",
func() {
packet.Data = []byte("invalid data")
},
ibcerrors.ErrInvalidType,
false,
},
{
"invalid acknowledgement",
func() {
ack = []byte("invalid ack")
},
ibcerrors.ErrUnknownRequest,
false,
},
{
"cannot refund already acknowledged packet",
func() {
ack = channeltypes.NewErrorAcknowledgement(ibcerrors.ErrInsufficientFunds).Acknowledgement()

cbs, ok := suite.chainA.App.GetIBCKeeper().PortKeeper.Route(ibctesting.TransferPort)
suite.Require().True(ok)

suite.Require().NoError(cbs.OnAcknowledgementPacket(suite.chainA.GetContext(), path.EndpointA.GetChannel().Version, packet, ack, suite.chainA.SenderAccount.GetAddress()))
},
errors.New("unable to unescrow tokens"),
false,
},
}

for _, tc := range testCases {
tc := tc
suite.Run(tc.name, func() {
suite.SetupTest() // reset

path = ibctesting.NewTransferPath(suite.chainA, suite.chainB)
path.Setup()

timeoutHeight := suite.chainA.GetTimeoutHeight()
msg := types.NewMsgTransfer(
path.EndpointA.ChannelConfig.PortID,
path.EndpointA.ChannelID,
ibctesting.TestCoin,
suite.chainA.SenderAccount.GetAddress().String(),
suite.chainB.SenderAccount.GetAddress().String(),
timeoutHeight,
0,
"",
)
res, err := suite.chainA.SendMsgs(msg)
suite.Require().NoError(err) // message committed

packet, err = ibctesting.ParsePacketFromEvents(res.Events)
suite.Require().NoError(err)

cbs, ok := suite.chainA.App.GetIBCKeeper().PortKeeper.Route(ibctesting.TransferPort)
suite.Require().True(ok)

ack = channeltypes.NewResultAcknowledgement([]byte{byte(1)}).Acknowledgement()

tc.malleate() // change fields in packet

err = cbs.OnAcknowledgementPacket(suite.chainA.GetContext(), path.EndpointA.GetChannel().Version, packet, ack, suite.chainA.SenderAccount.GetAddress())

if tc.expError == nil {
suite.Require().NoError(err)

if tc.expRefund {
escrowAddress := types.GetEscrowAddress(packet.GetSourcePort(), packet.GetSourceChannel())
escrowBalanceAfter := suite.chainA.GetSimApp().BankKeeper.GetBalance(suite.chainA.GetContext(), escrowAddress, sdk.DefaultBondDenom)
suite.Require().Equal(sdkmath.NewInt(0), escrowBalanceAfter.Amount)
}
} else {
suite.Require().Error(err)
suite.Require().Contains(err.Error(), tc.expError.Error())
}
})
}
}

func (suite *TransferTestSuite) TestOnTimeoutPacket() {
var path *ibctesting.Path
var packet channeltypes.Packet
Expand Down
2 changes: 1 addition & 1 deletion modules/apps/transfer/types/packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ func UnmarshalPacketData(bz []byte, ics20Version string, encoding string) (Inter
return InternalTransferRepresentation{}, errorsmod.Wrapf(ibcerrors.ErrInvalidType, failedUnmarshalingErrorMsg, errorMsgVersion, err.Error())
}
default:
return InternalTransferRepresentation{}, errorsmod.Wrapf(ibcerrors.ErrInvalidType, "invalid encoding provided, must be either empty or one of [%q, %q], got %s", EncodingJSON, EncodingProtobuf, encoding)
return InternalTransferRepresentation{}, errorsmod.Wrapf(ibcerrors.ErrInvalidType, "invalid encoding provided, must be either empty or one of [%q, %q, %q], got %s", EncodingJSON, EncodingProtobuf, EncodingABI, encoding)
}

// When the unmarshaling is done, we want to retrieve the underlying data type based on the value of ics20Version
Expand Down

0 comments on commit c7a9c56

Please sign in to comment.