fix(tests): Fixes LatestHeight in testutil network (#16219)

Co-authored-by: Facundo Medica <14063057+facundomedica@users.noreply.github.com>
This commit is contained in:
ocnc 2023-05-19 06:28:49 -04:00 committed by GitHub
parent b20bd5d932
commit 5865050f01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -677,9 +677,21 @@ func (n *Network) LatestHeight() (int64, error) {
case <-timeout.C:
return latestHeight, errors.New("timeout exceeded waiting for block")
case <-ticker.C:
res, err := queryClient.GetLatestBlock(context.Background(), &cmtservice.GetLatestBlockRequest{})
if err == nil && res != nil {
return res.SdkBlock.Header.Height, nil
done := make(chan struct{})
go func() {
res, err := queryClient.GetLatestBlock(context.Background(), &cmtservice.GetLatestBlockRequest{})
if err == nil && res != nil {
latestHeight = res.SdkBlock.Header.Height
}
done <- struct{}{}
}()
select {
case <-timeout.C:
return latestHeight, errors.New("timeout exceeded waiting for block")
case <-done:
if latestHeight != 0 {
return latestHeight, nil
}
}
}
}