-
Notifications
You must be signed in to change notification settings - Fork 424
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 IBC packet sequence number #1225
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,12 @@ message MsgIBCSend { | |
bytes data = 6; | ||
} | ||
|
||
// MsgIBCSendResponse | ||
message MsgIBCSendResponse { | ||
// Sequence number of the IBC packet sent | ||
uint64 sequence = 1; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
// MsgIBCCloseChannel port and channel need to be owned by the contract | ||
message MsgIBCCloseChannel { | ||
string channel = 2 [ (gogoproto.moretags) = "yaml:\"source_channel\"" ]; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -151,7 +151,7 @@ func NewIBCRawPacketHandler(chk types.ChannelKeeper, cak types.CapabilityKeeper) | |
} | ||
|
||
// DispatchMsg publishes a raw IBC packet onto the channel. | ||
func (h IBCRawPacketHandler) DispatchMsg(ctx sdk.Context, _ sdk.AccAddress, contractIBCPortID string, msg wasmvmtypes.CosmosMsg) (events []sdk.Event, data [][]byte, err error) { | ||
func (h IBCRawPacketHandler) DispatchMsg(ctx sdk.Context, _ sdk.AccAddress, contractIBCPortID string, msg wasmvmtypes.CosmosMsg) ([]sdk.Event, [][]byte, error) { | ||
if msg.IBC == nil || msg.IBC.SendPacket == nil { | ||
return nil, nil, types.ErrUnknownMsg | ||
} | ||
|
@@ -188,7 +188,18 @@ func (h IBCRawPacketHandler) DispatchMsg(ctx sdk.Context, _ sdk.AccAddress, cont | |
ConvertWasmIBCTimeoutHeightToCosmosHeight(msg.IBC.SendPacket.Timeout.Block), | ||
msg.IBC.SendPacket.Timeout.Timestamp, | ||
) | ||
return nil, nil, h.channelKeeper.SendPacket(ctx, channelCap, packet) | ||
|
||
if err := h.channelKeeper.SendPacket(ctx, channelCap, packet); err != nil { | ||
return nil, nil, sdkerrors.Wrap(err, "failed to send packet") | ||
} | ||
|
||
resp := &types.MsgIBCSendResponse{Sequence: sequence} | ||
val, err := resp.Marshal() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This does work correct! |
||
if err != nil { | ||
return nil, nil, sdkerrors.Wrap(err, "failed to marshal IBC send response") | ||
} | ||
|
||
return nil, [][]byte{val}, nil | ||
} | ||
|
||
var _ Messenger = MessageHandlerFunc(nil) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -308,14 +308,23 @@ func TestIBCRawPacketHandler(t *testing.T) { | |
capturedPacket = nil | ||
// when | ||
h := NewIBCRawPacketHandler(spec.chanKeeper, spec.capKeeper) | ||
data, evts, gotErr := h.DispatchMsg(ctx, RandomAccountAddress(t), ibcPort, wasmvmtypes.CosmosMsg{IBC: &wasmvmtypes.IBCMsg{SendPacket: &spec.srcMsg}}) | ||
evts, data, gotErr := h.DispatchMsg(ctx, RandomAccountAddress(t), ibcPort, wasmvmtypes.CosmosMsg{IBC: &wasmvmtypes.IBCMsg{SendPacket: &spec.srcMsg}}) | ||
// then | ||
require.True(t, spec.expErr.Is(gotErr), "exp %v but got %#+v", spec.expErr, gotErr) | ||
if spec.expErr != nil { | ||
return | ||
} | ||
assert.Nil(t, data) | ||
|
||
assert.Nil(t, evts) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Really? The events are nil? How do we get the ibc packet events to the relayers here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, via context. |
||
require.NotNil(t, data) | ||
|
||
expMsg := types.MsgIBCSendResponse{Sequence: 1} | ||
|
||
actualMsg := types.MsgIBCSendResponse{} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice test case |
||
err := actualMsg.Unmarshal(data[0]) | ||
require.NoError(t, err) | ||
|
||
assert.Equal(t, expMsg, actualMsg) | ||
assert.Equal(t, spec.expPacketSent, capturedPacket) | ||
}) | ||
} | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍