github.com/prysmaticlabs/prysm@v1.4.4/slasher/db/kv/chain_data_test.go (about)

     1  package kv
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1"
     8  	"github.com/prysmaticlabs/prysm/shared/testutil/assert"
     9  	"github.com/prysmaticlabs/prysm/shared/testutil/require"
    10  )
    11  
    12  func TestChainHead(t *testing.T) {
    13  	db := setupDB(t)
    14  	ctx := context.Background()
    15  
    16  	tests := []struct {
    17  		head *ethpb.ChainHead
    18  	}{
    19  		{
    20  			head: &ethpb.ChainHead{
    21  				HeadSlot:       20,
    22  				HeadEpoch:      20,
    23  				FinalizedSlot:  10,
    24  				FinalizedEpoch: 10,
    25  				JustifiedSlot:  10,
    26  				JustifiedEpoch: 10,
    27  			},
    28  		},
    29  		{
    30  			head: &ethpb.ChainHead{
    31  				HeadSlot: 1,
    32  			},
    33  		},
    34  		{
    35  			head: &ethpb.ChainHead{
    36  				HeadBlockRoot: make([]byte, 32),
    37  			},
    38  		},
    39  	}
    40  
    41  	for _, tt := range tests {
    42  		require.NoError(t, db.SaveChainHead(ctx, tt.head))
    43  		head, err := db.ChainHead(ctx)
    44  		require.NoError(t, err, "Failed to get block")
    45  		assert.NotNil(t, head)
    46  		assert.DeepEqual(t, tt.head, head)
    47  	}
    48  }