Skip to content

Commit

Permalink
Merge branch 'main' into damian/08-wasm-migration-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
crodriguezvega authored Jul 26, 2024
2 parents 3d09f60 + 27d234b commit 5d18272
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion modules/apps/transfer/keeper/relay_forwarding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1145,6 +1145,9 @@ func (suite *ForwardingTestSuite) TestForwardingWithMoreThanOneHop() {
suite.Require().NoError(err)
}

// TestMultihopForwardingErrorAcknowledgement tests the scenario in which a packet goes from
// A to D, using B and C as forwarding hops. The packet fails on D where we set the ReceiveEnabled
// param to false. We verify that funds are properly returned to A.
func (suite *ForwardingTestSuite) TestMultihopForwardingErrorAcknowledgement() {
// Setup A->B->C->D
coinOnA := ibctesting.TestCoin
Expand Down Expand Up @@ -1226,14 +1229,18 @@ func (suite *ForwardingTestSuite) TestMultihopForwardingErrorAcknowledgement() {
err = pathCtoD.EndpointB.UpdateClient()
suite.Require().NoError(err)

// force an error acknowledgement by disabling the receive param on chain D.
// force an error acknowledgement by disabling the ReceiveEnabled param on chain D.
ctx := pathCtoD.EndpointB.Chain.GetContext()
pathCtoD.EndpointB.Chain.GetSimApp().TransferKeeper.SetParams(ctx, types.NewParams(true, false))

result, err = pathCtoD.EndpointB.RecvPacketWithResult(packetFromCtoD)
suite.Require().NoError(err)
suite.Require().NotNil(result)

// forward packet exists on C before ack
_, found := suite.chainC.GetSimApp().TransferKeeper.GetForwardedPacket(suite.chainC.GetContext(), pathCtoD.EndpointA.ChannelConfig.PortID, pathCtoD.EndpointA.ChannelID, packetFromBtoC.GetSequence())
suite.Require().True(found)

// propagate the acknowledgement from chain D to chain A.
ack, err := ibctesting.ParseAckFromEvents(result.Events)
suite.Require().NoError(err)
Expand All @@ -1242,15 +1249,46 @@ func (suite *ForwardingTestSuite) TestMultihopForwardingErrorAcknowledgement() {
result, err = pathCtoD.EndpointA.AcknowledgePacketWithResult(packetFromCtoD, ack)
suite.Require().NoError(err)

// forward packet is deleted after ack
_, found = suite.chainC.GetSimApp().TransferKeeper.GetForwardedPacket(suite.chainC.GetContext(), pathCtoD.EndpointA.ChannelConfig.PortID, pathCtoD.EndpointA.ChannelID, packetFromBtoC.GetSequence())
suite.Require().False(found)

// Ensure that chainC has an ack.
storedAck, found := suite.chainC.App.GetIBCKeeper().ChannelKeeper.GetPacketAcknowledgement(suite.chainC.GetContext(), pathBtoC.EndpointB.ChannelConfig.PortID, pathBtoC.EndpointB.ChannelID, packetFromBtoC.GetSequence())
suite.Require().True(found, "chainC does not have an ack")

// And that this ack is of the type we expect (Error due to ReceiveEnabled param being false)
initialErrorAck := channeltypes.NewErrorAcknowledgement(types.ErrReceiveDisabled)
forwardErrorAck := internaltypes.NewForwardErrorAcknowledgement(packetFromCtoD, initialErrorAck)
ackbytes := channeltypes.CommitAcknowledgement(forwardErrorAck.Acknowledgement())
suite.Require().Equal(ackbytes, storedAck)

ack, err = ibctesting.ParseAckFromEvents(result.Events)
suite.Require().NoError(err)

err = pathBtoC.EndpointA.UpdateClient()
suite.Require().NoError(err)

// forward packet exists on B before ack
_, found = suite.chainB.GetSimApp().TransferKeeper.GetForwardedPacket(suite.chainB.GetContext(), pathBtoC.EndpointA.ChannelConfig.PortID, pathBtoC.EndpointA.ChannelID, packetFromAtoB.GetSequence())
suite.Require().True(found)

result, err = pathBtoC.EndpointA.AcknowledgePacketWithResult(packetFromBtoC, ack)
suite.Require().NoError(err)

// forward packet is deleted after ack
_, found = suite.chainB.GetSimApp().TransferKeeper.GetForwardedPacket(suite.chainB.GetContext(), pathBtoC.EndpointA.ChannelConfig.PortID, pathBtoC.EndpointA.ChannelID, packetFromAtoB.GetSequence())
suite.Require().False(found)

// Ensure that chainB has an ack.
storedAck, found = suite.chainB.App.GetIBCKeeper().ChannelKeeper.GetPacketAcknowledgement(suite.chainB.GetContext(), pathAtoB.EndpointB.ChannelConfig.PortID, pathAtoB.EndpointB.ChannelID, packetFromAtoB.GetSequence())
suite.Require().True(found, "chainB does not have an ack")

// And that this ack is of the type we expect (Error due to ReceiveEnabled param being false)
forwardErrorAck = internaltypes.NewForwardErrorAcknowledgement(packetFromBtoC, forwardErrorAck)
ackbytes = channeltypes.CommitAcknowledgement(forwardErrorAck.Acknowledgement())
suite.Require().Equal(ackbytes, storedAck)

ack, err = ibctesting.ParseAckFromEvents(result.Events)
suite.Require().NoError(err)

Expand Down

0 comments on commit 5d18272

Please sign in to comment.