Skip to content

Commit

Permalink
Merge pull request #495 from ava-labs/wait-teleporter-msg-util
Browse files Browse the repository at this point in the history
Wait for Teleporter message delivery test utility
  • Loading branch information
cam-schultz authored Aug 19, 2024
2 parents 14734f3 + 32ddad9 commit d043135
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions tests/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -1207,3 +1207,40 @@ func InstantiateGenesisTemplate(

return subnetGenesisFile.Name()
}

//
// Teleporter message utils
//

// Blocks until the given teleporter message is delivered to the specified TeleporterMessenger
// before the timeout, or if an error occurred.
func WaitTeleporterMessageDelivered(
ctx context.Context,
teleporterMessenger *teleportermessenger.TeleporterMessenger,
teleporterMessageID ids.ID,
) error {
cctx, cancel := context.WithTimeout(ctx, 20*time.Second)
defer cancel()

queryTicker := time.NewTicker(200 * time.Millisecond)
defer queryTicker.Stop()
for {
delivered, err := teleporterMessenger.MessageReceived(
&bind.CallOpts{}, teleporterMessageID,
)
if err != nil {
return err
}

if delivered {
return nil
}

// Wait for the next round.
select {
case <-cctx.Done():
return cctx.Err()
case <-queryTicker.C:
}
}
}

0 comments on commit d043135

Please sign in to comment.