Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

return UTC time in time out error message #39

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 10 additions & 4 deletions modules/core/04-channel/keeper/packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
}
}

Expand Down Expand Up @@ -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(
Expand Down
34 changes: 34 additions & 0 deletions modules/core/04-channel/keeper/packet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
})
}
}
Loading