-
Notifications
You must be signed in to change notification settings - Fork 657
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
Add helper functions for MsgSendPacket, MsgRecvPacket and MsgAcknowledgePacket #7465
Merged
chatton
merged 6 commits into
feat/ibc-eureka
from
cian/issue#7459-update-testing-library-types-to-support-message-server-v2-messages
Oct 15, 2024
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5d50ebb
chore: added msg send packet fucntion on endpoint
chatton 493c716
chore: added MsgRecvPacket to endpoint
chatton 225b71a
chore: modify ack test to use new endpoint send and recv functions
chatton 61a5227
chore: refactored msg ack to use new endpoint fn
chatton 794ede7
chore: added test case to verify proof failure
chatton 0320253
Update testing/endpoint_v2.go
chatton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package ibctesting | ||
|
||
import ( | ||
"github.com/stretchr/testify/require" | ||
|
||
channeltypesv2 "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" | ||
hostv2 "github.com/cosmos/ibc-go/v9/modules/core/24-host/v2" | ||
) | ||
|
||
// MsgSendPacket sends a packet on the associated endpoint. The constructed packet is returned. | ||
func (endpoint *Endpoint) MsgSendPacket(timeoutTimestamp uint64, packetData channeltypesv2.PacketData) (channeltypesv2.Packet, error) { | ||
msgSendPacket := channeltypesv2.NewMsgSendPacket(endpoint.ChannelID, timeoutTimestamp, endpoint.Chain.SenderAccount.GetAddress().String(), packetData) | ||
|
||
_, err := endpoint.Chain.SendMsgs(msgSendPacket) | ||
if err != nil { | ||
return channeltypesv2.Packet{}, err | ||
} | ||
|
||
if err := endpoint.Counterparty.UpdateClient(); err != nil { | ||
return channeltypesv2.Packet{}, err | ||
} | ||
|
||
// TODO: parse the packet from events instead of manually constructing it. https://github.com/cosmos/ibc-go/issues/7459 | ||
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. #7459 linkerino |
||
nextSequenceSend, ok := endpoint.Chain.GetSimApp().IBCKeeper.ChannelKeeperV2.GetNextSequenceSend(endpoint.Chain.GetContext(), endpoint.ChannelID) | ||
require.True(endpoint.Chain.TB, ok) | ||
packet := channeltypesv2.NewPacket(nextSequenceSend-1, endpoint.ChannelID, endpoint.Counterparty.ChannelID, timeoutTimestamp, packetData) | ||
|
||
return packet, nil | ||
} | ||
|
||
// MsgRecvPacket sends a MsgRecvPacket on the associated endpoint with the provided packet. | ||
func (endpoint *Endpoint) MsgRecvPacket(packet channeltypesv2.Packet) error { | ||
// get proof of packet commitment from chainA | ||
packetKey := hostv2.PacketCommitmentKey(packet.SourceChannel, packet.Sequence) | ||
proof, proofHeight := endpoint.Counterparty.QueryProof(packetKey) | ||
|
||
msg := channeltypesv2.NewMsgRecvPacket(packet, proof, proofHeight, endpoint.Chain.SenderAccount.GetAddress().String()) | ||
|
||
if err := endpoint.Chain.sendMsgs(msg); err != nil { | ||
return err | ||
} | ||
|
||
return endpoint.Counterparty.UpdateClient() | ||
} | ||
|
||
// MsgAcknowledgePacket sends a MsgAcknowledgement on the associated endpoint with the provided packet and ack. | ||
func (endpoint *Endpoint) MsgAcknowledgePacket(packet channeltypesv2.Packet, ack channeltypesv2.Acknowledgement) error { | ||
packetKey := hostv2.PacketAcknowledgementKey(packet.DestinationChannel, packet.Sequence) | ||
proof, proofHeight := endpoint.Counterparty.QueryProof(packetKey) | ||
msg := channeltypesv2.NewMsgAcknowledgement(packet, ack, proof, proofHeight, endpoint.Chain.SenderAccount.GetAddress().String()) | ||
if err := endpoint.Chain.sendMsgs(msg); err != nil { | ||
return err | ||
} | ||
chatton marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return endpoint.Counterparty.UpdateClient() | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
how come you didn't allow chan id as arg? No strong opinions i think, mostly curious.
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.
figured we can just modify endpoint.ChannelID if we need to in a
malleate
fn