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
- func NewMulti(t testing.TB) (*core.Blockchain, neotest.Signer, neotest.Signer)
- func NewMultiWithCustomConfig(t testing.TB, f func(*config.Blockchain)) (*core.Blockchain, neotest.Signer, neotest.Signer)
- func NewMultiWithCustomConfigAndStore(t testing.TB, f func(*config.Blockchain), st storage.Store, run bool) (*core.Blockchain, neotest.Signer, neotest.Signer)
- func NewMultiWithCustomConfigAndStoreNoCheck(t testing.TB, f func(*config.Blockchain), st storage.Store) (*core.Blockchain, neotest.Signer, neotest.Signer, error)
- func NewMultiWithOptions(t testing.TB, options *Options) (*core.Blockchain, neotest.Signer, neotest.Signer)
- func NewMultiWithOptionsNoCheck(t testing.TB, options *Options) (*core.Blockchain, neotest.Signer, neotest.Signer, error)
- func NewSingle(t testing.TB) (*core.Blockchain, neotest.Signer)
- func NewSingleWithCustomConfig(t testing.TB, f func(*config.Blockchain)) (*core.Blockchain, neotest.Signer)
- func NewSingleWithCustomConfigAndStore(t testing.TB, f func(cfg *config.Blockchain), st storage.Store, run bool) (*core.Blockchain, neotest.Signer)
- func NewSingleWithOptions(t testing.TB, options *Options) (*core.Blockchain, neotest.Signer)
- type Options
Constants ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
NewSingleWithOptions creates a new blockchain instance with a single validator using specified options.
Types ¶
type Options ¶
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.