fullblocktests

package
v0.14.6 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2019 License: ISC Imports: 18 Imported by: 0

README

fullblocktests

Build Status ISC License GoDoc

Package fullblocktests provides a set of full block tests to be used for testing the consensus validation rules. The tests are intended to be flexible enough to allow both unit-style tests directly against the blockchain code as well as integration style tests over the peer-to-peer network. To achieve that goal, each test contains additional information about the expected result, however that information can be ignored when doing comparison tests between two independent versions over the peer-to-peer network.

This package has intentionally been designed so it can be used as a standalone package for any projects needing to test their implementation against a full set of blocks that exercise the consensus validation rules.

Installation and Updating

$ go get -u github.com/gcash/bchd/blockchain/fullblocktests

License

Package fullblocktests is licensed under the copyfree ISC License.

Documentation

Overview

Package fullblocktests provides a set of block consensus validation tests.

All of the generated test instances involve full blocks that are to be used for testing the consensus validation rules. The tests are intended to be flexible enough to allow both unit-style tests directly against the blockchain code as well as integration style tests over the peer-to-peer network. To achieve that goal, each test contains additional information about the expected result, however that information can be ignored when doing comparison tests between two independent versions over the peer-to-peer network.

This package has intentionally been designed so it can be used as a standalone package for any projects needing to test their implementation against a full set of blocks that exercise the consensus validation rules.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Generate

func Generate(includeLargeReorg bool) (tests [][]TestInstance, err error)

Generate returns a slice of tests that can be used to exercise the consensus validation rules. The tests are intended to be flexible enough to allow both unit-style tests directly against the blockchain code as well as integration style tests over the peer-to-peer network. To achieve that goal, each test contains additional information about the expected result, however that information can be ignored when doing comparison tests between two independent versions over the peer-to-peer network.

func GenerateBlocksWithSchnorrSigs

func GenerateBlocksWithSchnorrSigs() (tests [][]TestInstance, err error)

GenerateBlocksWithSchnorrSigs generates a test chain containing several schnorr transactions per block.

func GenerateWithTxs

func GenerateWithTxs(chainLength int, txsPerBlock int) (tests [][]TestInstance, err error)

GenerateWithTxs generates a test chain of chainLength length with the given number of txsPerBlock. This function is primarily for use with CTOR tests as it will test sort transactions into CTOR order.

Types

type AcceptedBlock

type AcceptedBlock struct {
	Name        string
	Block       *wire.MsgBlock
	Height      int32
	IsMainChain bool
	IsOrphan    bool
}

AcceptedBlock defines a test instance that expects a block to be accepted to the blockchain either by extending the main chain, on a side chain, or as an orphan.

func (AcceptedBlock) FullBlockTestInstance

func (b AcceptedBlock) FullBlockTestInstance()

FullBlockTestInstance only exists to allow AcceptedBlock to be treated as a TestInstance.

This implements the TestInstance interface.

type ExpectedTip

type ExpectedTip struct {
	Name   string
	Block  *wire.MsgBlock
	Height int32
}

ExpectedTip defines a test instance that expects a block to be the current tip of the main chain.

func (ExpectedTip) FullBlockTestInstance

func (b ExpectedTip) FullBlockTestInstance()

FullBlockTestInstance only exists to allow ExpectedTip to be treated as a TestInstance.

This implements the TestInstance interface.

type OrphanOrRejectedBlock

type OrphanOrRejectedBlock struct {
	Name   string
	Block  *wire.MsgBlock
	Height int32
}

OrphanOrRejectedBlock defines a test instance that expects a block to either be accepted as an orphan or rejected. This is useful since some implementations might optimize the immediate rejection of orphan blocks when their parent was previously rejected, while others might accept it as an orphan that eventually gets flushed (since the parent can never be accepted to ultimately link it).

func (OrphanOrRejectedBlock) FullBlockTestInstance

func (b OrphanOrRejectedBlock) FullBlockTestInstance()

FullBlockTestInstance only exists to allow OrphanOrRejectedBlock to be treated as a TestInstance.

This implements the TestInstance interface.

type RejectedBlock

type RejectedBlock struct {
	Name       string
	Block      *wire.MsgBlock
	Height     int32
	RejectCode blockchain.ErrorCode
}

RejectedBlock defines a test instance that expects a block to be rejected by the blockchain consensus rules.

func (RejectedBlock) FullBlockTestInstance

func (b RejectedBlock) FullBlockTestInstance()

FullBlockTestInstance only exists to allow RejectedBlock to be treated as a TestInstance.

This implements the TestInstance interface.

type RejectedNonCanonicalBlock

type RejectedNonCanonicalBlock struct {
	Name     string
	RawBlock []byte
	Height   int32
}

RejectedNonCanonicalBlock defines a test instance that expects a serialized block that is not canonical and therefore should be rejected.

func (RejectedNonCanonicalBlock) FullBlockTestInstance

func (b RejectedNonCanonicalBlock) FullBlockTestInstance()

FullBlockTestInstance only exists to allow RejectedNonCanonicalBlock to be treated as a TestInstance.

This implements the TestInstance interface.

type TestInstance

type TestInstance interface {
	FullBlockTestInstance()
}

TestInstance is an interface that describes a specific test instance returned by the tests generated in this package. It should be type asserted to one of the concrete test instance types in order to test accordingly.

Jump to

Keyboard shortcuts

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