/
check_resolve_virtual.go
40 lines (34 loc) · 1.04 KB
/
check_resolve_virtual.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package main
import (
"fmt"
"github.com/sedracoin/sedrad/app/appmessage"
"github.com/sedracoin/sedrad/stability-tests/common/rpc"
"github.com/pkg/errors"
"time"
)
func checkResolveVirtual(syncerClient, syncedClient *rpc.Client) error {
err := syncedClient.RegisterForBlockAddedNotifications()
if err != nil {
return errors.Wrap(err, "error registering for blockAdded notifications")
}
syncedBlockCountResponse, err := syncedClient.GetBlockCount()
if err != nil {
return err
}
rejectReason, err := mineOnTips(syncerClient)
if err != nil {
panic(err)
}
if rejectReason != appmessage.RejectReasonNone {
panic(fmt.Sprintf("mined block rejected: %s", rejectReason))
}
expectedDuration := time.Duration(syncedBlockCountResponse.BlockCount) * 100 * time.Millisecond
start := time.Now()
select {
case <-time.After(expectedDuration):
return errors.Errorf("it took more than %s to resolve the virtual", expectedDuration)
case <-syncedClient.OnBlockAdded:
}
log.Infof("It took %s to resolve the virtual", time.Since(start))
return nil
}