diff options
author | Jimmy Hu <jimmy.hu@dexon.org> | 2018-12-11 18:47:49 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@dexon.org> | 2018-12-19 20:54:27 +0800 |
commit | 4c31b498bcc0db8926ad2610afa4533fc20ef737 (patch) | |
tree | 7bd33b286cc47841e87c6129f63561e50e332ff1 /dex/cache_test.go | |
parent | 4149d8a61a63c6df8e9ce6799203c369aa840c90 (diff) | |
download | dexon-4c31b498bcc0db8926ad2610afa4533fc20ef737.tar dexon-4c31b498bcc0db8926ad2610afa4533fc20ef737.tar.gz dexon-4c31b498bcc0db8926ad2610afa4533fc20ef737.tar.bz2 dexon-4c31b498bcc0db8926ad2610afa4533fc20ef737.tar.lz dexon-4c31b498bcc0db8926ad2610afa4533fc20ef737.tar.xz dexon-4c31b498bcc0db8926ad2610afa4533fc20ef737.tar.zst dexon-4c31b498bcc0db8926ad2610afa4533fc20ef737.zip |
dex: Pull blocks from blockdb if cache miss (#84)
Diffstat (limited to 'dex/cache_test.go')
-rw-r--r-- | dex/cache_test.go | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/dex/cache_test.go b/dex/cache_test.go index ac5609c1a..8a0066c94 100644 --- a/dex/cache_test.go +++ b/dex/cache_test.go @@ -23,6 +23,7 @@ import ( "testing" coreCommon "github.com/dexon-foundation/dexon-consensus/common" + coreBlockdb "github.com/dexon-foundation/dexon-consensus/core/blockdb" coreTypes "github.com/dexon-foundation/dexon-consensus/core/types" ) @@ -41,7 +42,11 @@ func (v byHash) Swap(i int, j int) { } func TestCacheVote(t *testing.T) { - cache := newCache(3) + db, err := coreBlockdb.NewMemBackedBlockDB() + if err != nil { + panic(err) + } + cache := newCache(3, db) pos0 := coreTypes.Position{ Height: uint64(0), } @@ -126,7 +131,11 @@ func TestCacheVote(t *testing.T) { } func TestCacheBlock(t *testing.T) { - cache := newCache(3) + db, err := coreBlockdb.NewMemBackedBlockDB() + if err != nil { + panic(err) + } + cache := newCache(3, db) block1 := &coreTypes.Block{ Hash: coreCommon.NewRandomHash(), } @@ -178,4 +187,19 @@ func TestCacheBlock(t *testing.T) { if !hasNewBlock { t.Errorf("expect block %s in cache, have %v", block4, blocks) } + + block5 := &coreTypes.Block{ + Hash: coreCommon.NewRandomHash(), + } + if err := db.Put(*block5); err != nil { + panic(err) + } + blocks = cache.blocks(coreCommon.Hashes{block5.Hash}) + if len(blocks) != 1 { + t.Errorf("fail to get blocks: have %d, want 1", len(blocks)) + } else { + if !blocks[0].Hash.Equal(block5.Hash) { + t.Errorf("get wrong block: have %s, want %s", blocks[0], block5) + } + } } |