2020-02-19 22:26:14 +00:00
|
|
|
package kv
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"flag"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/gogo/protobuf/proto"
|
|
|
|
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
2020-03-19 21:46:44 +00:00
|
|
|
"gopkg.in/urfave/cli.v2"
|
2020-02-19 22:26:14 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestChainHead(t *testing.T) {
|
2020-03-19 21:46:44 +00:00
|
|
|
app := &cli.App{}
|
2020-02-19 22:26:14 +00:00
|
|
|
set := flag.NewFlagSet("test", 0)
|
|
|
|
db := setupDB(t, cli.NewContext(app, set, nil))
|
|
|
|
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 {
|
|
|
|
if err := db.SaveChainHead(ctx, tt.head); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
head, err := db.ChainHead(ctx)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("failed to get block: %v", err)
|
|
|
|
}
|
|
|
|
if head == nil || !proto.Equal(head, tt.head) {
|
|
|
|
t.Errorf("Expected %v, got %v", tt.head, head)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|