Skip to content

Commit

Permalink
wait teleporter msg util
Browse files Browse the repository at this point in the history
  • Loading branch information
cam-schultz committed Aug 19, 2024
1 parent 14734f3 commit 32ddad9
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 32ddad9

Please sign in to comment.