github.com/prysmaticlabs/prysm@v1.4.4/validator/client/log_test.go (about)

     1  package client
     2  
     3  import (
     4  	"testing"
     5  
     6  	types "github.com/prysmaticlabs/eth2-types"
     7  	ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1"
     8  	"github.com/prysmaticlabs/prysm/shared/testutil/require"
     9  	logTest "github.com/sirupsen/logrus/hooks/test"
    10  )
    11  
    12  func TestLogNextDutyCountDown_NoDuty(t *testing.T) {
    13  	hook := logTest.NewGlobal()
    14  	v := &validator{
    15  		logDutyCountDown: true,
    16  		duties: &ethpb.DutiesResponse{CurrentEpochDuties: []*ethpb.DutiesResponse_Duty{
    17  			{AttesterSlot: 100, ProposerSlots: []types.Slot{105}},
    18  			{AttesterSlot: 110},
    19  			{AttesterSlot: 120},
    20  		}},
    21  	}
    22  	require.NoError(t, v.LogNextDutyTimeLeft(121))
    23  	require.LogsContain(t, hook, "No duty until next epoch")
    24  }
    25  
    26  func TestLogNextDutyCountDown_HasDutyAttester(t *testing.T) {
    27  	hook := logTest.NewGlobal()
    28  	v := &validator{
    29  		logDutyCountDown: true,
    30  		duties: &ethpb.DutiesResponse{CurrentEpochDuties: []*ethpb.DutiesResponse_Duty{
    31  			{AttesterSlot: 100, ProposerSlots: []types.Slot{105}},
    32  			{AttesterSlot: 110},
    33  			{AttesterSlot: 120},
    34  		}},
    35  	}
    36  	require.NoError(t, v.LogNextDutyTimeLeft(115))
    37  	require.LogsContain(t, hook, "\"Next duty\" attesting=1 currentSlot=115 dutySlot=120 prefix=validator proposing=0")
    38  }
    39  
    40  func TestLogNextDutyCountDown_HasDutyProposer(t *testing.T) {
    41  	hook := logTest.NewGlobal()
    42  	v := &validator{
    43  		logDutyCountDown: true,
    44  		duties: &ethpb.DutiesResponse{CurrentEpochDuties: []*ethpb.DutiesResponse_Duty{
    45  			{AttesterSlot: 100, ProposerSlots: []types.Slot{105}},
    46  			{AttesterSlot: 110},
    47  			{AttesterSlot: 120},
    48  		}},
    49  	}
    50  	require.NoError(t, v.LogNextDutyTimeLeft(101))
    51  	require.LogsContain(t, hook, "\"Next duty\" attesting=0 currentSlot=101 dutySlot=105 prefix=validator proposing=1")
    52  }
    53  
    54  func TestLogNextDutyCountDown_HasMultipleDuties(t *testing.T) {
    55  	hook := logTest.NewGlobal()
    56  	v := &validator{
    57  		logDutyCountDown: true,
    58  		duties: &ethpb.DutiesResponse{CurrentEpochDuties: []*ethpb.DutiesResponse_Duty{
    59  			{AttesterSlot: 120},
    60  			{AttesterSlot: 110},
    61  			{AttesterSlot: 105},
    62  			{AttesterSlot: 105},
    63  			{AttesterSlot: 100, ProposerSlots: []types.Slot{105}},
    64  		}},
    65  	}
    66  	require.NoError(t, v.LogNextDutyTimeLeft(101))
    67  	require.LogsContain(t, hook, "\"Next duty\" attesting=2 currentSlot=101 dutySlot=105 prefix=validator proposing=1")
    68  }
    69  
    70  func TestLogNextDutyCountDown_NilDuty(t *testing.T) {
    71  	v := &validator{
    72  		logDutyCountDown: true,
    73  	}
    74  	require.NoError(t, v.LogNextDutyTimeLeft(101))
    75  }