header check for test

This commit is contained in:
zelig 2015-03-25 11:28:17 +00:00
parent 9d592c0445
commit 18d1569ce5
2 changed files with 8 additions and 3 deletions

@ -238,7 +238,11 @@ func (self *BlockPool) Start() {
case event := <-self.tdSub.Chan(): case event := <-self.tdSub.Chan():
if ev, ok := event.(core.ChainHeadEvent); ok { if ev, ok := event.(core.ChainHeadEvent); ok {
td := ev.Block.Td td := ev.Block.Td
plog.DebugDetailf("ChainHeadEvent: height: %v, td: %v, hash: %s", ev.Block.Number(), td, hex(ev.Block.Hash())) var height *big.Int
if (ev.Block.HeaderHash == common.Hash{}) {
height = ev.Block.Header().Number
}
plog.DebugDetailf("ChainHeadEvent: height: %v, td: %v, hash: %s", height, td, hex(ev.Block.Hash()))
self.setTD(td) self.setTD(td)
self.peers.lock.Lock() self.peers.lock.Lock()

@ -14,7 +14,7 @@ import (
// the actual tests // the actual tests
func TestAddPeer(t *testing.T) { func TestAddPeer(t *testing.T) {
test.LogInit() test.LogInit()
_, blockPool, blockPoolTester := newTestBlockPool(t) hashPool, blockPool, blockPoolTester := newTestBlockPool(t)
peer0 := blockPoolTester.newPeer("peer0", 1, 1) peer0 := blockPoolTester.newPeer("peer0", 1, 1)
peer1 := blockPoolTester.newPeer("peer1", 2, 2) peer1 := blockPoolTester.newPeer("peer1", 2, 2)
peer2 := blockPoolTester.newPeer("peer2", 3, 3) peer2 := blockPoolTester.newPeer("peer2", 3, 3)
@ -119,7 +119,8 @@ func TestAddPeer(t *testing.T) {
} }
peer0.waitBlocksRequests(3) peer0.waitBlocksRequests(3)
newblock := &types.Block{Td: common.Big3} hash := hashPool.IndexesToHashes([]int{0})[0]
newblock := &types.Block{Td: common.Big3, HeaderHash: hash}
blockPool.chainEvents.Post(core.ChainHeadEvent{newblock}) blockPool.chainEvents.Post(core.ChainHeadEvent{newblock})
time.Sleep(100 * time.Millisecond) time.Sleep(100 * time.Millisecond)
if blockPool.peers.best != nil { if blockPool.peers.best != nil {