Test improvement TestValidateVoluntaryExit_ValidExit (#13313)

This commit is contained in:
terence 2023-12-11 16:01:56 +08:00 committed by GitHub
parent 122a7782ff
commit 7d2ddaee43
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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")
}
}