[DEV-137] calculate height correctly in blockdag and mining packages (#72)

* [DEV-137] calculate height correctly in blockdag and mining packages

* [DEV-137] Fix tests that didn't set block height
This commit is contained in:
Svarog 2018-09-30 11:16:51 +03:00 committed by stasatdaglabs
parent c8461dfcba
commit fae411706e
3 changed files with 8 additions and 5 deletions

View File

@ -45,7 +45,7 @@ func loadBlocks(filename string) (blocks []*util.Block, err error) {
var block *util.Block
err = nil
for height := int64(1); err == nil; height++ {
for height := 0; err == nil; height++ {
var rintbuf uint32
err = binary.Read(dr, binary.LittleEndian, &rintbuf)
if err == io.EOF {
@ -72,6 +72,7 @@ func loadBlocks(filename string) (blocks []*util.Block, err error) {
if err != nil {
return
}
block.SetHeight(int32(height))
blocks = append(blocks, block)
}

View File

@ -126,9 +126,11 @@ func TestCheckConnectBlockTemplate(t *testing.T) {
}
// Block 4 should connect even if proof of work is invalid.
invalidPowBlock := *blocks[4].MsgBlock()
invalidPowBlock.Header.Nonce++
err = dag.CheckConnectBlockTemplate(util.NewBlock(&invalidPowBlock))
invalidPowMsgBlock := *blocks[4].MsgBlock()
invalidPowMsgBlock.Header.Nonce++
invalidPowBlock := util.NewBlock(&invalidPowMsgBlock)
invalidPowBlock.SetHeight(blocks[4].Height())
err = dag.CheckConnectBlockTemplate(invalidPowBlock)
if err != nil {
t.Fatalf("CheckConnectBlockTemplate: Received unexpected error on "+
"block 4 with bad nonce: %v", err)

View File

@ -9,8 +9,8 @@ import (
"fmt"
"io"
"github.com/daglabs/btcd/wire"
"github.com/daglabs/btcd/dagconfig/daghash"
"github.com/daglabs/btcd/wire"
)
// OutOfRangeError describes an error due to accessing an element that is out