From 7f475bee00006232cb772a6d44c3531b7ba07780 Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Fri, 23 Aug 2019 09:56:48 -0500 Subject: [PATCH] no cache tests (#3284) --- beacon-chain/db/kv/blocks_test.go | 41 +++++++++++++++++++++++++++ beacon-chain/db/kv/validators_test.go | 38 +++++++++++++++++++++++++ 2 files changed, 79 insertions(+) diff --git a/beacon-chain/db/kv/blocks_test.go b/beacon-chain/db/kv/blocks_test.go index 840496968..67bddeebc 100644 --- a/beacon-chain/db/kv/blocks_test.go +++ b/beacon-chain/db/kv/blocks_test.go @@ -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 := ðpb.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) diff --git a/beacon-chain/db/kv/validators_test.go b/beacon-chain/db/kv/validators_test.go index 294615139..7158bb9c7 100644 --- a/beacon-chain/db/kv/validators_test.go +++ b/beacon-chain/db/kv/validators_test.go @@ -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") + } +}