Skip to content

Commit

Permalink
review: address feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
DimitrisJim committed May 22, 2024
1 parent 9eadd72 commit 1528eda
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 25 deletions.
1 change: 1 addition & 0 deletions modules/apps/29-fee/ibc_middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1573,6 +1573,7 @@ func (suite *FeeTestSuite) TestPacketDataUnmarshalerInterface() {
feeModule, ok := cbs.(porttypes.PacketDataUnmarshaler)
suite.Require().True(ok)

// Context, port identifier, channel identifier are not used in current wiring of fee.
packetData, err := feeModule.UnmarshalPacketData(suite.chainA.GetContext(), "", "", ibcmock.MockPacketData)
suite.Require().NoError(err)
suite.Require().Equal(ibcmock.MockPacketData, packetData)
Expand Down
2 changes: 2 additions & 0 deletions modules/apps/callbacks/ibc_middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ func (im IBCMiddleware) SendPacket(
return 0, err
}

// packet is created withouth destination information present, GetSourceCallbackData does not use these.
packet := channeltypes.NewPacket(data, seq, sourcePort, sourceChannel, "", "", timeoutHeight, timeoutTimestamp)

callbackData, err := types.GetSourceCallbackData(ctx, im.app, packet, im.maxCallbackGas)
// SendPacket is not blocked if the packet does not opt-in to callbacks
if err != nil {
Expand Down
7 changes: 5 additions & 2 deletions modules/apps/callbacks/ibc_middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1003,15 +1003,18 @@ func (s *CallbacksTestSuite) TestUnmarshalPacketData() {
Memo: fmt.Sprintf(`{"src_callback": {"address": "%s"}, "dest_callback": {"address":"%s"}}`, ibctesting.TestAccAddress, ibctesting.TestAccAddress),
}

portID := s.path.EndpointA.ChannelConfig.PortID
channelID := s.path.EndpointA.ChannelID

// Unmarshal ICS20 v1 packet data
data := expPacketDataICS20V1.GetBytes()
packetData, err := unmarshalerStack.UnmarshalPacketData(s.chainA.GetContext(), "", "", data)
packetData, err := unmarshalerStack.UnmarshalPacketData(s.chainA.GetContext(), portID, channelID, data)
s.Require().NoError(err)
s.Require().Equal(expPacketDataICS20V2, packetData)

// Unmarshal ICS20 v1 packet data
data = expPacketDataICS20V2.GetBytes()
packetData, err = unmarshalerStack.UnmarshalPacketData(s.chainA.GetContext(), "", "", data)
packetData, err = unmarshalerStack.UnmarshalPacketData(s.chainA.GetContext(), portID, channelID, data)
s.Require().NoError(err)
s.Require().Equal(expPacketDataICS20V2, packetData)
}
Expand Down
11 changes: 10 additions & 1 deletion modules/apps/callbacks/types/callbacks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,16 @@ func (s *CallbacksTypesTestSuite) TestGetCallbackData() {
ctx := s.chain.GetContext().WithGasMeter(gasMeter)

packet := channeltypes.NewPacket(packetData, 0, ibcmock.PortID, "", "", "", clienttypes.ZeroHeight(), 0)
callbackData, err := types.GetCallbackData(ctx, packetDataUnmarshaler, packet, remainingGas, uint64(1_000_000), callbackKey)

var (
callbackData types.CallbackData
err error
)
if callbackKey == types.DestinationCallbackKey {
callbackData, err = types.GetDestCallbackData(ctx, packetDataUnmarshaler, packet, uint64(1_000_000))
} else {
callbackData, err = types.GetSourceCallbackData(ctx, packetDataUnmarshaler, packet, uint64(1_000_000))
}

expPass := tc.expError == nil
if expPass {
Expand Down
22 changes: 0 additions & 22 deletions modules/apps/callbacks/types/export_test.go
Original file line number Diff line number Diff line change
@@ -1,31 +1,9 @@
package types

import (
sdk "github.com/cosmos/cosmos-sdk/types"

channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"
porttypes "github.com/cosmos/ibc-go/v8/modules/core/05-port/types"
)

/*
This file is to allow for unexported functions to be accessible to the testing package.
*/

// GetCallbackData is a wrapper around getCallbackData to allow the function to be directly called in tests.
func GetCallbackData(
ctx sdk.Context,
packetDataUnmarshaler porttypes.PacketDataUnmarshaler,
packet channeltypes.Packet,
remainingGas,
maxGas uint64, callbackKey string,
) (CallbackData, error) {
// TODO(jim): Probably just refactor single occurrence of this in tests
if callbackKey == DestinationCallbackKey {
return GetDestCallbackData(ctx, packetDataUnmarshaler, packet, maxGas)
}
return GetSourceCallbackData(ctx, packetDataUnmarshaler, packet, maxGas)
}

// GetCallbackAddress is a wrapper around getCallbackAddress to allow the function to be directly called in tests.
func GetCallbackAddress(callbackData map[string]interface{}) string {
return getCallbackAddress(callbackData)
Expand Down

0 comments on commit 1528eda

Please sign in to comment.