chain

package
v0.106.1 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2024 License: MIT Imports: 15 Imported by: 4

Documentation

Overview

Package chain contains functions creating new test blockchain instances. Different configurations can be used, but all chains created here use well-known keys. Most of the time, a single-node chain is the best choice to use unless you specifically need multiple validators and a large committee.

Index

Constants

View Source
const (
	// MaxTraceableBlocks is the default MaxTraceableBlocks setting used for test chains.
	// We don't need a lot of traceable blocks for tests.
	MaxTraceableBlocks = 1000

	// TimePerBlock is the default TimePerBlock setting used for test chains (1s).
	// Usually blocks are created by tests bypassing this setting.
	TimePerBlock = time.Second
)

Variables

This section is empty.

Functions

func NewMulti

NewMulti creates a new blockchain instance with four validators and six committee members. Otherwise, it does not differ much from NewSingle. The second value returned contains the validators Signer, the third -- the committee one.

func NewMultiWithCustomConfig added in v0.98.1

func NewMultiWithCustomConfig(t testing.TB, f func(*config.Blockchain)) (*core.Blockchain, neotest.Signer, neotest.Signer)

NewMultiWithCustomConfig is similar to NewMulti, except it allows to override the default configuration.

func NewMultiWithCustomConfigAndStore added in v0.99.0

func NewMultiWithCustomConfigAndStore(t testing.TB, f func(*config.Blockchain), st storage.Store, run bool) (*core.Blockchain, neotest.Signer, neotest.Signer)

NewMultiWithCustomConfigAndStore is similar to NewMultiWithCustomConfig, but also allows to override backend Store being used. The last parameter controls if Run method is called on the Blockchain instance. If not, it is its caller's responsibility to do that before using the chain and to properly Close the chain when done.

func NewMultiWithCustomConfigAndStoreNoCheck added in v0.99.0

func NewMultiWithCustomConfigAndStoreNoCheck(t testing.TB, f func(*config.Blockchain), st storage.Store) (*core.Blockchain, neotest.Signer, neotest.Signer, error)

NewMultiWithCustomConfigAndStoreNoCheck is similar to NewMultiWithCustomConfig, but do not perform Blockchain run and do not check Blockchain constructor error.

func NewMultiWithOptions added in v0.106.0

func NewMultiWithOptions(t testing.TB, options *Options) (*core.Blockchain, neotest.Signer, neotest.Signer)

NewMultiWithOptions creates a new blockchain instance with four validators and six committee members. Otherwise, it does not differ much from NewSingle. The second value returned contains the validators Signer, the third -- the committee one.

func NewMultiWithOptionsNoCheck added in v0.106.0

func NewMultiWithOptionsNoCheck(t testing.TB, options *Options) (*core.Blockchain, neotest.Signer, neotest.Signer, error)

NewMultiWithOptionsNoCheck is similar to NewMultiWithOptions, but does not verify blockchain constructor error. It will start blockchain only if construction has completed successfully.

func NewSingle

func NewSingle(t testing.TB) (*core.Blockchain, neotest.Signer)

NewSingle creates a new blockchain instance with a single validator and setups cleanup functions. The configuration used is with netmode.UnitTestNet magic and TimePerBlock/MaxTraceableBlocks options defined by constants in this package. MemoryStore is used as the backend storage, so all of the chain contents is always in RAM. The Signer returned is the validator (and the committee at the same time).

func NewSingleWithCustomConfig added in v0.98.1

func NewSingleWithCustomConfig(t testing.TB, f func(*config.Blockchain)) (*core.Blockchain, neotest.Signer)

NewSingleWithCustomConfig is similar to NewSingle, but allows to override the default configuration.

func NewSingleWithCustomConfigAndStore added in v0.98.1

func NewSingleWithCustomConfigAndStore(t testing.TB, f func(cfg *config.Blockchain), st storage.Store, run bool) (*core.Blockchain, neotest.Signer)

NewSingleWithCustomConfigAndStore is similar to NewSingleWithCustomConfig, but also allows to override backend Store being used. The last parameter controls if Run method is called on the Blockchain instance. If not, it is its caller's responsibility to do that before using the chain and to properly Close the chain when done.

func NewSingleWithOptions added in v0.106.0

func NewSingleWithOptions(t testing.TB, options *Options) (*core.Blockchain, neotest.Signer)

NewSingleWithOptions creates a new blockchain instance with a single validator using specified options.

Types

type Options added in v0.106.0

type Options struct {
	// Logger allows to customize logging performed by the test chain.
	// If Logger is not set, zaptest.Logger will be used with default configuration.
	Logger *zap.Logger
	// BlockchainConfigHook function is sort of visitor pattern for blockchain configuration.
	// It takes in the default configuration as an argument and can perform any adjustments in it.
	BlockchainConfigHook func(*config.Blockchain)
	// Store allows to customize storage for blockchain data.
	// If Store is not set, MemoryStore is used by default.
	Store storage.Store
	// If SkipRun is false, then the blockchain will be started (if its' construction
	// has succeeded) and will be registered for cleanup when the test completes.
	// If SkipRun is true, it is caller's responsibility to call Run before using
	// the chain and to properly Close the chain when done.
	SkipRun bool
}

Options contains parameters to customize parameters of the test chain.

Jump to

Keyboard shortcuts

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