Skip to content

Commit

Permalink
chore: Progress
Browse files Browse the repository at this point in the history
  • Loading branch information
kulikthebird committed Jan 17, 2025
1 parent 213acc2 commit c19c018
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 4 deletions.
51 changes: 51 additions & 0 deletions tests/ibctesting/chain2.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,57 @@ func (chain *WasmTestChain) SmartQuery(contractAddr string, queryMsg, response i
return json.Unmarshal(resp.Data, response)
}

// RelayPacketWithoutAck attempts to relay the packet first on EndpointA and then on EndpointB
// 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.
// In contrast to RelayPacket, this function does not acknowledge the packet and expects it to have no acknowledgement yet.
// It is useful for testing async acknowledgement.
func RelayPacketWithoutAck(path *ibctesting.Path, packet channeltypes.Packet) 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
}

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

_, err = ParseAckFromEvents(res.GetEvents())
if err == nil {
return fmt.Errorf("tried to relay packet without ack but got ack")
}

return 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
}

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

_, err = ParseAckFromEvents(res.GetEvents())
if err == nil {
return fmt.Errorf("tried to relay packet without ack but got ack")
}

return nil
}

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

// RelayAndAckPendingPackets sends pending packages from path.EndpointA to the counterparty chain and acks
func RelayAndAckPendingPackets(chainA *WasmTestChain, chainB *WasmTestChain, path *ibctesting.Path) error {
// get all the packet to relay src->dest
Expand Down
5 changes: 1 addition & 4 deletions tests/integration/ibc_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,10 +416,7 @@ func TestIBCAsyncAck(t *testing.T) {
require.Equal(t, 0, len(chainB.PendingSendPackets))

// we don't expect an ack yet

// TODO tkulik:
// err = path.RelayPacketWithoutAck(chainA.PendingSendPackets[0], nil)
err = wasmibctesting.RelayAndAckPendingPackets(&chainA, &chainB, path)
err = wasmibctesting.RelayPacketWithoutAck(path, chainA.PendingSendPackets[0])

noAckPacket := chainA.PendingSendPackets[0]
chainA.PendingSendPackets = []channeltypes.Packet{}
Expand Down

0 comments on commit c19c018

Please sign in to comment.