no cache tests (#3284)

This commit is contained in:
Raul Jordan 2019-08-23 09:56:48 -05:00 committed by GitHub
parent ebb0e398d3
commit 7f475bee00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 79 additions and 0 deletions

View File

@ -50,6 +50,47 @@ func TestStore_BlocksCRUD(t *testing.T) {
}
}
func TestStore_BlocksCRUD_NoCache(t *testing.T) {
db := setupDB(t)
defer teardownDB(t, db)
ctx := context.Background()
block := &ethpb.BeaconBlock{
Slot: 20,
ParentRoot: []byte{1, 2, 3},
}
blockRoot, err := ssz.SigningRoot(block)
if err != nil {
t.Fatal(err)
}
retrievedBlock, err := db.Block(ctx, blockRoot)
if err != nil {
t.Fatal(err)
}
if retrievedBlock != nil {
t.Errorf("Expected nil block, received %v", retrievedBlock)
}
if err := db.SaveBlock(ctx, block); err != nil {
t.Fatal(err)
}
db.blockCache.Delete(string(blockRoot[:]))
if !db.HasBlock(ctx, blockRoot) {
t.Error("Expected block to exist in the db")
}
retrievedBlock, err = db.Block(ctx, blockRoot)
if err != nil {
t.Fatal(err)
}
if !proto.Equal(block, retrievedBlock) {
t.Errorf("Wanted %v, received %v", block, retrievedBlock)
}
if err := db.DeleteBlock(ctx, blockRoot); err != nil {
t.Fatal(err)
}
if db.HasBlock(ctx, blockRoot) {
t.Error("Expected block to have been deleted from the db")
}
}
func TestStore_Blocks_FiltersCorrectly(t *testing.T) {
db := setupDB(t)
defer teardownDB(t, db)

View File

@ -78,3 +78,41 @@ func TestStore_ValidatorLatestVoteCRUD(t *testing.T) {
t.Error("Expected validator latest vote to have been deleted from the db")
}
}
func TestStore_ValidatorLatestVoteCRUD_NoCache(t *testing.T) {
db := setupDB(t)
defer teardownDB(t, db)
ctx := context.Background()
validatorIdx := uint64(100)
latestVote := &pb.ValidatorLatestVote{
Epoch: 1,
Root: []byte("root"),
}
retrievedVote, err := db.ValidatorLatestVote(ctx, validatorIdx)
if err != nil {
t.Fatal(err)
}
if retrievedVote != nil {
t.Errorf("Expected nil validator latest vote, received %v", retrievedVote)
}
if err := db.SaveValidatorLatestVote(ctx, validatorIdx, latestVote); err != nil {
t.Fatal(err)
}
db.votesCache.Delete(string(validatorIdx))
if !db.HasValidatorLatestVote(ctx, validatorIdx) {
t.Error("Expected validator latest vote to exist in the db")
}
retrievedVote, err = db.ValidatorLatestVote(ctx, validatorIdx)
if err != nil {
t.Fatal(err)
}
if !proto.Equal(latestVote, retrievedVote) {
t.Errorf("Wanted %d, received %d", latestVote, retrievedVote)
}
if err := db.DeleteValidatorLatestVote(ctx, validatorIdx); err != nil {
t.Fatal(err)
}
if db.HasValidatorLatestVote(ctx, validatorIdx) {
t.Error("Expected validator latest vote to have been deleted from the db")
}
}