10 dbm "github.com/vapor/database/leveldb"
11 "github.com/vapor/netsync/peers"
12 "github.com/vapor/protocol/bc/types"
13 "github.com/vapor/test/mock"
16 func TestBlockProcess(t *testing.T) {
17 tmp, err := ioutil.TempDir(".", "")
21 defer os.RemoveAll(tmp)
23 testDB := dbm.NewDB("testdb", "leveldb", tmp)
32 blocks: mockBlocks(nil, 200),
37 blocks: mockBlocks(nil, 200),
42 blocks: mockErrorBlocks(nil, 200, 150),
47 s := newStorage(testDB)
48 mockChain := mock.NewChain(nil)
49 for i, c := range cases {
50 for i := 0; i <= len(c.blocks)/2; i++ {
51 mockChain.SetBlockByHeight(uint64(i), c.blocks[i])
52 mockChain.SetBestBlockHeader(&c.blocks[i].BlockHeader)
55 if err := s.writeBlocks("testPeer", c.blocks); err != nil {
59 bp := newBlockProcessor(mockChain, s, peers.NewPeerSet(nil))
60 downloadNotifyCh := make(chan struct{}, 1)
61 ProcessStopCh := make(chan struct{})
64 time.Sleep(1 * time.Second)
65 close(downloadNotifyCh)
69 bp.process(downloadNotifyCh, ProcessStopCh, c.startHeight, &wg)
70 if bp.chain.BestBlockHeight() != c.stopHeight {
71 t.Fatalf("TestBlockProcess index: %d fail: got %d want %d", i, bp.chain.BestBlockHeight(), c.stopHeight)