From 59c7d105073717a9f1b7363c673a49496d76cfdd Mon Sep 17 00:00:00 2001 From: Calvin Kim Date: Tue, 2 Apr 2024 16:09:50 +0900 Subject: [PATCH] fullblocktests, testhelper: move standardCoinbaseScript to testhelper standardCoinbaseScript is moved to testhelper and is exported. This allows test code in package blockchain to reuse the code without introducing an import cycle. This code is used in the testing code for invalidateblock and reconsiderblock that's added in the later commits. --- blockchain/fullblocktests/generate.go | 10 +--------- blockchain/internal/testhelper/common.go | 8 ++++++++ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/blockchain/fullblocktests/generate.go b/blockchain/fullblocktests/generate.go index 242de647..7bd838a5 100644 --- a/blockchain/fullblocktests/generate.go +++ b/blockchain/fullblocktests/generate.go @@ -220,20 +220,12 @@ func pushDataScript(items ...[]byte) []byte { return script } -// standardCoinbaseScript returns a standard script suitable for use as the -// signature script of the coinbase transaction of a new block. In particular, -// it starts with the block height that is required by version 2 blocks. -func standardCoinbaseScript(blockHeight int32, extraNonce uint64) ([]byte, error) { - return txscript.NewScriptBuilder().AddInt64(int64(blockHeight)). - AddInt64(int64(extraNonce)).Script() -} - // createCoinbaseTx returns a coinbase transaction paying an appropriate // subsidy based on the passed block height. The coinbase signature script // conforms to the requirements of version 2 blocks. func (g *testGenerator) createCoinbaseTx(blockHeight int32) *wire.MsgTx { extraNonce := uint64(0) - coinbaseScript, err := standardCoinbaseScript(blockHeight, extraNonce) + coinbaseScript, err := testhelper.StandardCoinbaseScript(blockHeight, extraNonce) if err != nil { panic(err) } diff --git a/blockchain/internal/testhelper/common.go b/blockchain/internal/testhelper/common.go index 49f80347..7d16c2f4 100644 --- a/blockchain/internal/testhelper/common.go +++ b/blockchain/internal/testhelper/common.go @@ -21,6 +21,14 @@ var ( LowFee = btcutil.Amount(1) ) +// StandardCoinbaseScript returns a standard script suitable for use as the +// signature script of the coinbase transaction of a new block. In particular, +// it starts with the block height that is required by version 2 blocks. +func StandardCoinbaseScript(blockHeight int32, extraNonce uint64) ([]byte, error) { + return txscript.NewScriptBuilder().AddInt64(int64(blockHeight)). + AddInt64(int64(extraNonce)).Script() +} + // OpReturnScript returns a provably-pruneable OP_RETURN script with the // provided data. func OpReturnScript(data []byte) ([]byte, error) {