prysm-pulse/slasher/db/kv/chain_data_test.go
Raul Jordan d143187b7e
Request All Indexed Attestations Since Genesis in Slasher on Startup (#4894)
* include fixes

* rev

* logrus

* tests for query sync status and chain head

* begin tests for indexed atts

* test passing for requesting historical atts

* Update slasher/beaconclient/chain_data_test.go

* Update slasher/beaconclient/historical_data_retrieval.go

* lint

* fixed up wanted vs receied

* fix mock

* gazelle

* fix broken build

* tests pass

* dep

* gaz

* add dep

* tests pass

Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
2020-02-19 16:26:14 -06:00

57 lines
1.0 KiB
Go

package kv
import (
"context"
"flag"
"testing"
"github.com/gogo/protobuf/proto"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/urfave/cli"
)
func TestChainHead(t *testing.T) {
app := cli.NewApp()
set := flag.NewFlagSet("test", 0)
db := setupDB(t, cli.NewContext(app, set, nil))
ctx := context.Background()
tests := []struct {
head *ethpb.ChainHead
}{
{
head: &ethpb.ChainHead{
HeadSlot: 20,
HeadEpoch: 20,
FinalizedSlot: 10,
FinalizedEpoch: 10,
JustifiedSlot: 10,
JustifiedEpoch: 10,
},
},
{
head: &ethpb.ChainHead{
HeadSlot: 1,
},
},
{
head: &ethpb.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)
}
}
}