2020-02-19 22:26:14 +00:00
|
|
|
package kv
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
2021-07-21 21:34:07 +00:00
|
|
|
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
2020-08-18 12:41:25 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
|
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
2020-02-19 22:26:14 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestChainHead(t *testing.T) {
|
2020-10-12 08:11:05 +00:00
|
|
|
db := setupDB(t)
|
2020-02-19 22:26:14 +00:00
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
head *ethpb.ChainHead
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
head: ðpb.ChainHead{
|
|
|
|
HeadSlot: 20,
|
|
|
|
HeadEpoch: 20,
|
|
|
|
FinalizedSlot: 10,
|
|
|
|
FinalizedEpoch: 10,
|
|
|
|
JustifiedSlot: 10,
|
|
|
|
JustifiedEpoch: 10,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
head: ðpb.ChainHead{
|
|
|
|
HeadSlot: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
head: ðpb.ChainHead{
|
|
|
|
HeadBlockRoot: make([]byte, 32),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
2020-08-18 12:41:25 +00:00
|
|
|
require.NoError(t, db.SaveChainHead(ctx, tt.head))
|
2020-02-19 22:26:14 +00:00
|
|
|
head, err := db.ChainHead(ctx)
|
2020-08-18 12:41:25 +00:00
|
|
|
require.NoError(t, err, "Failed to get block")
|
|
|
|
assert.NotNil(t, head)
|
|
|
|
assert.DeepEqual(t, tt.head, head)
|
2020-02-19 22:26:14 +00:00
|
|
|
}
|
|
|
|
}
|