diff --git a/beacon-chain/sync/validate_voluntary_exit_test.go b/beacon-chain/sync/validate_voluntary_exit_test.go index 4a9526567..30d65f377 100644 --- a/beacon-chain/sync/validate_voluntary_exit_test.go +++ b/beacon-chain/sync/validate_voluntary_exit_test.go @@ -84,16 +84,17 @@ func TestValidateVoluntaryExit_ValidExit(t *testing.T) { exit, s := setupValidExit(t) gt := time.Now() + mockChainService := &mock.ChainService{ + State: s, + Genesis: gt, + } r := &Service{ cfg: &config{ - p2p: p, - chain: &mock.ChainService{ - State: s, - Genesis: gt, - }, + p2p: p, + chain: mockChainService, clock: startup.NewClock(gt, [32]byte{}), initialSync: &mockSync.Sync{IsSyncing: false}, - operationNotifier: (&mock.ChainService{}).OperationNotifier(), + operationNotifier: mockChainService.OperationNotifier(), }, seenExitCache: lruwrpr.New(10), } @@ -118,25 +119,22 @@ func TestValidateVoluntaryExit_ValidExit(t *testing.T) { defer opSub.Unsubscribe() res, err := r.validateVoluntaryExit(ctx, "", m) - assert.NoError(t, err) - valid := res == pubsub.ValidationAccept - assert.Equal(t, true, valid, "Failed validation") - assert.NotNil(t, m.ValidatorData, "Decoded message was not set on the message validator data") + require.NoError(t, err) + require.Equal(t, pubsub.ValidationAccept, res, "Failed validation") + require.NotNil(t, m.ValidatorData, "Decoded message was not set on the message validator data") - // Ensure the state notification was broadcast. - notificationFound := false - for !notificationFound { - select { - case event := <-opChannel: - if event.Type == opfeed.ExitReceived { - notificationFound = true - _, ok := event.Data.(*opfeed.ExitReceivedData) - assert.Equal(t, true, ok, "Entity is not of type *opfeed.ExitReceivedData") - } - case <-opSub.Err(): - t.Error("Subscription to state notifier failed") - return + select { + case event := <-opChannel: + if event.Type == opfeed.ExitReceived { + _, ok := event.Data.(*opfeed.ExitReceivedData) + assert.Equal(t, true, ok, "Entity is not of type *opfeed.ExitReceivedData") + } else { + t.Error("Unexpected event type received") } + case <-opSub.Err(): + t.Error("Subscription to state notifier failed") + case <-time.After(10 * time.Second): // Timeout to prevent hanging tests + t.Error("Timeout waiting for exit notification") } }