diff --git a/testing/path.go b/testing/path.go index 9a97c8fe18d..ff93f3f48ca 100644 --- a/testing/path.go +++ b/testing/path.go @@ -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" ) @@ -39,25 +41,39 @@ 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()) 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()) @@ -65,21 +81,25 @@ func (path *Path) RelayPacket(packet channeltypes.Packet) error { // 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") }