7 "github.com/vapor/netsync/peers"
8 "github.com/vapor/protocol/bc"
9 "github.com/vapor/protocol/bc/types"
15 func (pm *peerMgr) IsBanned(peerID string, level byte, reason string) bool {
19 func (pm *peerMgr) StopPeerGracefully(string) {
27 func newChain() *chain {
28 blocks := make([]uint64, 1, 1)
35 func (c *chain) BestBlockHeight() uint64 {
36 return c.blocks[len(c.blocks)-1]
39 func (c *chain) GetHeaderByHash(*bc.Hash) (*types.BlockHeader, error) {
43 func (c *chain) ProcessBlock(block *types.Block) (bool, error) {
44 c.blocks = append(c.blocks, block.Height)
48 func (c *chain) ProcessBlockSignature(signature, pubkey []byte, blockHash *bc.Hash) error {
52 func TestBlockFetcher(t *testing.T) {
53 peers := peers.NewPeerSet(&peerMgr{})
54 testCase := []struct {
61 BlockHeader: types.BlockHeader{
71 BlockHeader: types.BlockHeader{
81 BlockHeader: types.BlockHeader{
91 BlockHeader: types.BlockHeader{
101 BlockHeader: types.BlockHeader{
111 BlockHeader: types.BlockHeader{
121 BlockHeader: types.BlockHeader{
129 fetcher := newBlockFetcher(newChain(), peers)
131 for i, c := range testCase {
132 fetcher.processNewBlock(c.blockMsg)
133 time.Sleep(10 * time.Millisecond)
134 chainHeight := fetcher.chain.BestBlockHeight()
135 if chainHeight != c.height {
136 t.Fatalf("test block fetcher error. index %d expected chain height %d but got %d", i, chainHeight, c.height)