diff options
author | Jimmy Hu <jimmy.hu@dexon.org> | 2018-07-24 10:02:44 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-24 10:02:44 +0800 |
commit | 2108b92131fff21c8e2b7e5b85a77e3f693dadd9 (patch) | |
tree | e6271ff1519cf04e12654e3cf866d0039a610488 /blockdb | |
parent | 8223b1e396ddad3700ca24426fc91b04e8062feb (diff) | |
download | tangerine-consensus-2108b92131fff21c8e2b7e5b85a77e3f693dadd9.tar tangerine-consensus-2108b92131fff21c8e2b7e5b85a77e3f693dadd9.tar.gz tangerine-consensus-2108b92131fff21c8e2b7e5b85a77e3f693dadd9.tar.bz2 tangerine-consensus-2108b92131fff21c8e2b7e5b85a77e3f693dadd9.tar.lz tangerine-consensus-2108b92131fff21c8e2b7e5b85a77e3f693dadd9.tar.xz tangerine-consensus-2108b92131fff21c8e2b7e5b85a77e3f693dadd9.tar.zst tangerine-consensus-2108b92131fff21c8e2b7e5b85a77e3f693dadd9.zip |
Add test to cover blockdb.syncIndex.
* Add test to cover blockdb.syncIndex
* Test GetByValidatorAndHeight after syncIndex
Diffstat (limited to 'blockdb')
-rw-r--r-- | blockdb/level-db_test.go | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/blockdb/level-db_test.go b/blockdb/level-db_test.go index 4ab8067..13a934d 100644 --- a/blockdb/level-db_test.go +++ b/blockdb/level-db_test.go @@ -87,6 +87,54 @@ func (s *LevelDBTestSuite) TestBasicUsage() { s.Equal(now, queried.Timestamps[queried.ProposerID]) } +func (s *LevelDBTestSuite) TestSyncIndex() { + dbName := fmt.Sprintf("test-db-%v-si.db", time.Now().UTC()) + db, err := NewLevelDBBackendBlockDB(dbName) + s.Require().Nil(err) + defer func(dbName string) { + err = db.Close() + s.Nil(err) + err = os.RemoveAll(dbName) + s.Nil(err) + }(dbName) + + // Create some blocks. + blocks := [10]types.Block{} + for i := range blocks { + block := types.Block{ + ProposerID: types.ValidatorID{Hash: common.NewRandomHash()}, + Hash: common.NewRandomHash(), + Height: uint64(i), + State: types.BlockStatusInit, + } + db.Put(block) + blocks[i] = block + } + + // Save blocks to db. + err = db.Close() + s.Nil(err) + + // Load back blocks(syncIndex is called). + db, err = NewLevelDBBackendBlockDB(dbName) + s.Require().Nil(err) + + // Verify result. + for _, block := range blocks { + queried, err := db.Get(block.Hash) + s.Nil(err) + s.Equal(block.ProposerID, queried.ProposerID) + s.Equal(block.Height, queried.Height) + } + + // Verify result using GetByValidatorAndHeight(). + for _, block := range blocks { + queried, err := db.GetByValidatorAndHeight(block.ProposerID, block.Height) + s.Nil(err) + s.Equal(block.Hash, queried.Hash) + } +} + func TestLevelDB(t *testing.T) { suite.Run(t, new(LevelDBTestSuite)) } |