6 "github.com/vapor/protocol/bc"
7 "github.com/vapor/protocol/bc/types"
10 func TestBlockCache(t *testing.T) {
11 newBlock := func(h uint64) *types.Block {
13 BlockHeader: types.BlockHeader{
18 blocks := make(map[bc.Hash]*types.Block)
19 for i := 0; i < maxCachedBlocks+10; i++ {
20 block := newBlock(uint64(i))
21 blocks[block.Hash()] = block
24 cache := newBlockCache(func(hash *bc.Hash) (*types.Block, error) {
25 return blocks[*hash], nil
28 for i := 0; i < maxCachedBlocks+10; i++ {
29 block := newBlock(uint64(i))
34 for i := 0; i < 10; i++ {
35 block := newBlock(uint64(i))
37 if b, _ := cache.get(&hash); b != nil {
38 t.Fatalf("find old block")
42 for i := 10; i < maxCachedBlocks+10; i++ {
43 block := newBlock(uint64(i))
45 if b, _ := cache.get(&hash); b == nil {
46 t.Fatalf("can't find new block")