diff --git a/modules/core/04-channel/keeper/packet.go b/modules/core/04-channel/keeper/packet.go index 6d36285c..900e42cf 100644 --- a/modules/core/04-channel/keeper/packet.go +++ b/modules/core/04-channel/keeper/packet.go @@ -98,10 +98,7 @@ func (k Keeper) SendPacket( } if packet.GetTimeoutTimestamp() != 0 && latestTimestamp >= packet.GetTimeoutTimestamp() { - return sdkerrors.Wrapf( - types.ErrPacketTimeout, - "receiving chain block timestamp >= packet timeout timestamp (%s >= %s)", time.Unix(0, int64(latestTimestamp)), time.Unix(0, int64(packet.GetTimeoutTimestamp())), - ) + return GetPacketTimeoutErrorMessage(int64(latestTimestamp), int64(packet.GetTimeoutTimestamp())) } } @@ -140,6 +137,15 @@ func (k Keeper) SendPacket( return nil } +func GetPacketTimeoutErrorMessage(latestTimestamp int64, timeoutTimestamp int64) error { + return sdkerrors.Wrapf( + types.ErrPacketTimeout, + "receiving chain block timestamp >= packet timeout timestamp (%s >= %s)", + time.Unix(0, latestTimestamp).UTC(), + time.Unix(0, timeoutTimestamp).UTC(), + ) +} + // RecvPacket is called by a module in order to receive & process an IBC packet // sent on the corresponding channel end on the counterparty chain. func (k Keeper) RecvPacket( diff --git a/modules/core/04-channel/keeper/packet_test.go b/modules/core/04-channel/keeper/packet_test.go index 4d05df46..505ed516 100644 --- a/modules/core/04-channel/keeper/packet_test.go +++ b/modules/core/04-channel/keeper/packet_test.go @@ -3,6 +3,8 @@ package keeper_test import ( "errors" "fmt" + "github.com/cosmos/ibc-go/v3/modules/core/04-channel/keeper" + "testing" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" @@ -868,3 +870,35 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() { }) } } + +func Test_GetPacketTimeoutErrorMessage(t *testing.T) { + type args struct { + latestTimestamp int64 + timeoutTimestamp int64 + } + tests := []struct { + name string + args args + wantErr bool + wantErrMsg string + }{ + { + "test that timestamp is in UTC", + args{ + latestTimestamp: 1734828084008577679, + timeoutTimestamp: 1734882264, + }, + true, + "receiving chain block timestamp >= packet timeout timestamp (2024-12-22 00:41:24.008577679 +0000 UTC >= 1970-01-01 00:00:01.734882264 +0000 UTC): packet timeout", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := keeper.GetPacketTimeoutErrorMessage(tt.args.latestTimestamp, tt.args.timeoutTimestamp); (err != nil) != tt.wantErr { + t.Errorf("getWrongTimestampErrorMessage() error = %v, wantErr %v", err, tt.wantErr) + } else if err != nil && err.Error() != tt.wantErrMsg { + t.Errorf("getWrongTimestampErrorMessage() error = %v, wantErrMsg %v", err.Error(), tt.wantErrMsg) + } + }) + } +}