github.com/aergoio/aergo@v1.3.1/syncer/stubsyncerchain.go (about)

     1  package syncer
     2  
     3  import (
     4  	"fmt"
     5  	"github.com/aergoio/aergo/chain"
     6  	"github.com/aergoio/aergo/message"
     7  	"github.com/aergoio/aergo/types"
     8  	"time"
     9  )
    10  
    11  type StubPeer struct {
    12  	addr    *types.PeerAddress
    13  	lastBlk *types.NewBlockNotice
    14  	state   types.PeerState
    15  
    16  	blockChain *chain.StubBlockChain
    17  
    18  	blockFetched bool //check if called while testing
    19  
    20  	timeDelaySec time.Duration
    21  
    22  	HookGetBlockChunkRsp func(msgReq *message.GetBlockChunks)
    23  }
    24  
    25  var (
    26  	TestMaxBlockFetchSize = 2
    27  	TestMaxHashReqSize    = uint64(3)
    28  )
    29  
    30  func NewStubPeer(idx int, lastNo uint64, blockChain *chain.StubBlockChain) *StubPeer {
    31  	stubPeer := &StubPeer{}
    32  
    33  	peerIDBytes := []byte(fmt.Sprintf("peer-%d", idx))
    34  	stubPeer.addr = &types.PeerAddress{PeerID: peerIDBytes}
    35  	stubPeer.lastBlk = &types.NewBlockNotice{BlockNo: lastNo}
    36  	stubPeer.state = types.RUNNING
    37  
    38  	stubPeer.blockChain = blockChain
    39  
    40  	return stubPeer
    41  }