testhelper

package
v0.0.2-vendor Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 31, 2024 License: ISC Imports: 8 Imported by: 0

README

testhelper

Build Status ISC License GoDoc

Package testhelper provides functions that are used internally in the btcd/blockchain and btcd/blockchain/fullblocktests package to test consensus validation rules. Mainly provided to avoid dependency cycles internally among the different packages in btcd.

License

Package testhelper is licensed under the copyfree ISC License.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// OpTrueScript is simply a public key script that contains the OP_TRUE
	// opcode.  It is defined here to reduce garbage creation.
	OpTrueScript = []byte{txscript.OP_TRUE}

	// LowFee is a single satoshi and exists to make the test code more
	// readable.
	LowFee = btcutil.Amount(1)
)

Functions

func CreateCoinbaseTx

func CreateCoinbaseTx(blockHeight int32, blockSubsidy int64) *wire.MsgTx

CreateCoinbaseTx returns a coinbase transaction paying an appropriate subsidy based on the passed block height and the block subsidy. The coinbase signature script conforms to the requirements of version 2 blocks.

func CreateSpendTx

func CreateSpendTx(spend *SpendableOut, fee btcutil.Amount) *wire.MsgTx

CreateSpendTx creates a transaction that spends from the provided spendable output and includes an additional unique OP_RETURN output to ensure the transaction ends up with a unique hash. The script is a simple OP_TRUE script which avoids the need to track addresses and signature scripts in the tests.

func OpReturnScript

func OpReturnScript(data []byte) ([]byte, error)

OpReturnScript returns a provably-pruneable OP_RETURN script with the provided data.

func SolveBlock

func SolveBlock(header *wire.BlockHeader) bool

SolveBlock attempts to find a nonce which makes the passed block header hash to a value less than the target difficulty. When a successful solution is found true is returned and the nonce field of the passed header is updated with the solution. False is returned if no solution exists.

NOTE: This function will never solve blocks with a nonce of 0. This is done so the 'nextBlock' function can properly detect when a nonce was modified by a munge function.

func StandardCoinbaseScript

func StandardCoinbaseScript(blockHeight int32, extraNonce uint64) ([]byte, error)

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 UniqueOpReturnScript

func UniqueOpReturnScript() ([]byte, error)

UniqueOpReturnScript returns a standard provably-pruneable OP_RETURN script with a random uint64 encoded as the data.

Types

type SpendableOut

type SpendableOut struct {
	PrevOut wire.OutPoint
	Amount  btcutil.Amount
}

SpendableOut represents a transaction output that is spendable along with additional metadata such as the block its in and how much it pays.

func MakeSpendableOut

func MakeSpendableOut(block *wire.MsgBlock, txIndex, txOutIndex uint32) SpendableOut

MakeSpendableOut returns a spendable output for the given block, transaction index within the block, and transaction output index within the transaction.

func MakeSpendableOutForTx

func MakeSpendableOutForTx(tx *wire.MsgTx, txOutIndex uint32) SpendableOut

MakeSpendableOutForTx returns a spendable output for the given transaction and transaction output index within the transaction.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL