Fix e2e test

This commit is contained in:
Saolyn
2023-08-17 18:18:55 +02:00
parent 9370abacde
commit 6289c1de5c

View File

@@ -16,11 +16,8 @@ import (
"time"
"github.com/prysmaticlabs/prysm/v4/api/client/beacon"
"github.com/prysmaticlabs/prysm/v4/encoding/bytesutil"
"github.com/prysmaticlabs/prysm/v4/io/file"
enginev1 "github.com/prysmaticlabs/prysm/v4/proto/engine/v1"
"github.com/prysmaticlabs/prysm/v4/proto/eth/service"
v1 "github.com/prysmaticlabs/prysm/v4/proto/eth/v1"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
@@ -234,12 +231,19 @@ func (r *testRunner) testTxGeneration(ctx context.Context, g *errgroup.Group, ke
})
}
func (r *testRunner) waitForMatchingHead(ctx context.Context, timeout time.Duration, check, ref *grpc.ClientConn) error {
func (r *testRunner) waitForMatchingHead(ctx context.Context, timeout time.Duration) error {
start := time.Now()
dctx, cancel := context.WithDeadline(ctx, start.Add(timeout))
defer cancel()
checkClient := service.NewBeaconChainClient(check)
refClient := service.NewBeaconChainClient(ref)
httpEndpoints := helpers.BeaconAPIHostnames(e2e.TestParams.BeaconNodeCount)
checkClient, err := beacon.NewClient(httpEndpoints[0])
if err != nil {
return fmt.Errorf("could not initialize client for %s: %w", httpEndpoints[0], err)
}
refClient, err := beacon.NewClient(httpEndpoints[1])
if err != nil {
return fmt.Errorf("could not initialize client for %s: %w", httpEndpoints[1], err)
}
for {
select {
case <-dctx.Done():
@@ -247,7 +251,7 @@ func (r *testRunner) waitForMatchingHead(ctx context.Context, timeout time.Durat
elapsed := time.Since(start)
return fmt.Errorf("deadline exceeded after %s waiting for known good block to appear in checkpoint-synced node", elapsed)
default:
cResp, err := checkClient.GetBlockRoot(ctx, &v1.BlockRequest{BlockId: []byte("head")})
cResp, err := checkClient.GetBlockRoot(ctx, "head")
if err != nil {
errStatus, ok := status.FromError(err)
// in the happy path we expect NotFound results until the node has synced
@@ -256,11 +260,11 @@ func (r *testRunner) waitForMatchingHead(ctx context.Context, timeout time.Durat
}
return fmt.Errorf("error requesting head from 'check' beacon node")
}
rResp, err := refClient.GetBlockRoot(ctx, &v1.BlockRequest{BlockId: []byte("head")})
rResp, err := refClient.GetBlockRoot(ctx, "head")
if err != nil {
return errors.Wrap(err, "unexpected error requesting head block root from 'ref' beacon node")
}
if bytesutil.ToBytes32(cResp.Data.Root) == bytesutil.ToBytes32(rResp.Data.Root) {
if cResp == rResp {
return nil
}
}
@@ -317,7 +321,7 @@ func (r *testRunner) testCheckpointSync(ctx context.Context, g *errgroup.Group,
// this is so that the syncEvaluators checks can run on the checkpoint sync'd node
conns = append(conns, c)
err = r.waitForMatchingHead(ctx, matchTimeout, c, conns[0])
err = r.waitForMatchingHead(ctx, matchTimeout)
if err != nil {
return err
}