0b334bc841
This commit corrects the reading of the serialized height in coinbase transactions for block height of version 2 or greater. On mainnet, the serialized height is always 3 bytes and will continue to be so for something like another ~159 years, so there was no issue with mainnet. However on testnet, there are some version 2 blocks which are low enough in the chain to only take 2 bytes to serialize. In addition, this commit adds a full tests for the relavant function including negative tests and variable length serialized lengths for block heights. Closes #1.
42 lines
1.3 KiB
Go
42 lines
1.3 KiB
Go
// Copyright (c) 2013 Conformal Systems LLC.
|
|
// Use of this source code is governed by an ISC
|
|
// license that can be found in the LICENSE file.
|
|
|
|
/*
|
|
This test file is part of the btcchain package rather than than the
|
|
btcchain_test package so it can bridge access to the internals to properly test
|
|
cases which are either not possible or can't reliably be tested via the public
|
|
interface. The functions are only exported while the tests are being run.
|
|
*/
|
|
|
|
package btcchain
|
|
|
|
import (
|
|
"github.com/conformal/btcutil"
|
|
"github.com/conformal/btcwire"
|
|
"time"
|
|
)
|
|
|
|
// TstCheckBlockSanity makes the internal checkBlockSanity function available to
|
|
// the test package.
|
|
func (b *BlockChain) TstCheckBlockSanity(block *btcutil.Block) error {
|
|
return b.checkBlockSanity(block)
|
|
}
|
|
|
|
// TstSetCoinbaseMaturity makes the ability to set the coinbase maturity
|
|
// available to the test package.
|
|
func TstSetCoinbaseMaturity(maturity int64) {
|
|
coinbaseMaturity = maturity
|
|
}
|
|
|
|
// TstTimeSorter makes the internal timeSorter type available to the test
|
|
// package.
|
|
func TstTimeSorter(times []time.Time) timeSorter {
|
|
return timeSorter(times)
|
|
}
|
|
|
|
// TstCheckSerializedHeight makes the internal checkSerializedHeight function
|
|
// available to the test package.
|
|
func TstCheckSerializedHeight(coinbaseTx *btcwire.MsgTx, wantHeight int64) error {
|
|
return checkSerializedHeight(coinbaseTx, wantHeight)
|
|
}
|