mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-03-30 15:08:33 +00:00
[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:
parent
c8461dfcba
commit
fae411706e
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user