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

testing: add function RelayPacketWithResults #3986

Merged
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
38 changes: 29 additions & 9 deletions testing/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"bytes"
"fmt"

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

channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
)

Expand Down Expand Up @@ -39,47 +41,65 @@ func (path *Path) SetChannelOrdered() {
// if EndpointA does not contain a packet commitment for that packet. An error is returned
// if a relay step fails or the packet commitment does not exist on either endpoint.
func (path *Path) RelayPacket(packet channeltypes.Packet) error {
_, _, err := path.RelayPacketWithResults(packet)
return err
}

// RelayPacketWithResults attempts to relay the packet first on EndpointA and then on EndpointB
// if EndpointA does not contain a packet commitment for that packet. The function returns:
// - The result of the packet receive transaction.
// - The acknowledgement written on the receiving chain.
// - An error if a relay step fails or the packet commitment does not exist on either endpoint.
func (path *Path) RelayPacketWithResults(packet channeltypes.Packet) (*sdk.Result, []byte, error) {
pc := path.EndpointA.Chain.App.GetIBCKeeper().ChannelKeeper.GetPacketCommitment(path.EndpointA.Chain.GetContext(), packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence())
crodriguezvega marked this conversation as resolved.
Show resolved Hide resolved
if bytes.Equal(pc, channeltypes.CommitPacket(path.EndpointA.Chain.App.AppCodec(), packet)) {

// packet found, relay from A to B
if err := path.EndpointB.UpdateClient(); err != nil {
return err
return nil, nil, err
}

res, err := path.EndpointB.RecvPacketWithResult(packet)
if err != nil {
return err
return nil, nil, err
}

ack, err := ParseAckFromEvents(res.Events)
if err != nil {
return err
return nil, nil, err
}

return path.EndpointA.AcknowledgePacket(packet, ack)
if err := path.EndpointA.AcknowledgePacket(packet, ack); err != nil {
return nil, nil, err
}

return res, ack, nil
}

pc = path.EndpointB.Chain.App.GetIBCKeeper().ChannelKeeper.GetPacketCommitment(path.EndpointB.Chain.GetContext(), packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence())
if bytes.Equal(pc, channeltypes.CommitPacket(path.EndpointB.Chain.App.AppCodec(), packet)) {

// packet found, relay B to A
if err := path.EndpointA.UpdateClient(); err != nil {
return err
return nil, nil, err
}

res, err := path.EndpointA.RecvPacketWithResult(packet)
if err != nil {
return err
return nil, nil, err
}

ack, err := ParseAckFromEvents(res.Events)
if err != nil {
return err
return nil, nil, err
}

if err := path.EndpointB.AcknowledgePacket(packet, ack); err != nil {
return nil, nil, err
}

return path.EndpointB.AcknowledgePacket(packet, ack)
return res, ack, nil
}

return fmt.Errorf("packet commitment does not exist on either endpoint for provided packet")
return nil, nil, fmt.Errorf("packet commitment does not exist on either endpoint for provided packet")
}
Loading