network

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2025 License: Apache-2.0 Imports: 54 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetFreePorts

func GetFreePorts(count int) ([]int, error)

GetFreePorts asks the kernel for free open ports that are ready to use.

Types

type AppConstructor

type AppConstructor = func(val ValidatorI) servertypes.Application

AppConstructor defines a function which accepts a network configuration and creates an ABCI Application to provide to Tendermint.

type Config

type Config struct {
	Codec             codec.Codec
	LegacyAmino       *codec.LegacyAmino // TODO: Remove!
	InterfaceRegistry codectypes.InterfaceRegistry
	TxConfig          sdkclient.TxConfig
	AccountRetriever  sdkclient.AccountRetriever
	AppConstructor    AppConstructor             // the ABCI application constructor
	GenesisState      map[string]json.RawMessage // custom genesis state to provide
	TimeoutCommit     time.Duration              // the consensus commitment timeout
	ChainID           string                     // the network chain-id
	NumValidators     int                        // the total number of validators to create and bond
	Mnemonics         []string                   // custom user-provided validator operator mnemonics
	BondDenom         string                     // the staking bond denomination
	Denoms            []string                   // list of additional denoms could be used on network
	MinGasPrices      string                     // the minimum gas prices each validator will accept
	AccountTokens     math.Int                   // the amount of unique validator tokens (e.g. 1000node0)
	StakingTokens     math.Int                   // the amount of tokens each validator has available to stake
	BondedTokens      math.Int                   // the amount of tokens each validator stakes
	PruningStrategy   string                     // the pruning strategy each validator will have
	EnableLogging     bool                       // enable Tendermint logging to STDOUT
	CleanupDir        bool                       // remove base temporary directory during cleanup
	SigningAlgo       string                     // signing algorithm for keys
	KeyringOptions    []keyring.Option
}

Config defines the necessary configuration used to bootstrap and start an in-process local testing network.

func DefaultConfig

func DefaultConfig(factory TestFixtureFactory, opts ...ConfigOption) Config

DefaultConfig returns a default configuration suitable for nearly all testing requirements.

type ConfigOption

type ConfigOption func(*networkConfigOptions)

func WithInterceptState

func WithInterceptState(val InterceptState) ConfigOption

WithInterceptState set custom name of the log object

type InterceptState

type InterceptState func(codec.Codec, string, json.RawMessage) json.RawMessage

type Network

type Network struct {
	T          *testing.T
	BaseDir    string
	Validators []*Validator

	Config Config
}

Network defines a local in-process testing network using SimApp. It can be configured to start any number of validators, each with its own RPC and API clients. Typically, this test network would be used in client and integration testing where user input is expected.

Note, due to Tendermint constraints in regard to RPC functionality, there may only be one test network running at a time. Thus, any caller must be sure to Cleanup after testing is finished in order to allow other tests to create networks. In addition, only the first validator will have a valid RPC and API server/client.

func New

func New(t *testing.T, cfg Config) *Network

New creates a new Network for integration tests.

func (*Network) Cleanup

func (n *Network) Cleanup()

Cleanup removes the root testing (temporary) directory and stops both the Tendermint and API services. It allows other callers to create and start test networks. This method must be called when a test is finished, typically in defer.

func (*Network) LatestHeight

func (n *Network) LatestHeight() (int64, error)

LatestHeight returns the latest height of the network or an error if the query fails or no validators exist.

func (*Network) WaitForBlocks

func (n *Network) WaitForBlocks(blocks int64) error

WaitForBlocks waits for the next amount of blocks to be committed, returning an error upon failure.

func (*Network) WaitForHeight

func (n *Network) WaitForHeight(h int64) (int64, error)

WaitForHeight performs a blocking check where it waits for a block to be committed after a given block. If that height is not reached within a timeout, an error is returned. Regardless, the latest height queried is returned.

func (*Network) WaitForHeightWithTimeout

func (n *Network) WaitForHeightWithTimeout(h int64, t time.Duration) (int64, error)

WaitForHeightWithTimeout is the same as WaitForHeight except the caller can provide a custom timeout.

func (*Network) WaitForNextBlock

func (n *Network) WaitForNextBlock() error

WaitForNextBlock waits for the next block to be committed, returning an error upon failure.

type TestFixture

type TestFixture struct {
	AppConstructor AppConstructor
	GenesisState   map[string]json.RawMessage
	EncodingConfig sdkutil.EncodingConfig
}

type TestFixtureFactory

type TestFixtureFactory = func(opts ...TestnetFixtureOption) TestFixture

AppConstructor defines a function which accepts a network configuration and creates an ABCI Application to provide to Tendermint.

type TestnetFixtureOption

type TestnetFixtureOption func(*TestnetFixtureOptions)

type TestnetFixtureOptions

type TestnetFixtureOptions struct {
	EncCfg sdkutil.EncodingConfig
}

type Validator

type Validator struct {
	AppConfig  *srvconfig.Config
	ClientCtx  sdkclient.Context
	Ctx        *server.Context
	Dir        string
	NodeID     string
	PubKey     cryptotypes.PubKey
	Moniker    string
	APIAddress string
	RPCAddress string
	P2PAddress string
	Address    sdk.AccAddress
	ValAddress sdk.ValAddress
	RPCClient  tmclient.Client
	// contains filtered or unexported fields
}

Validator defines an in-process Tendermint validator node. Through this object, a client can make RPC and API calls and interact with any client command or handler.

func (Validator) GetAppConfig

func (v Validator) GetAppConfig() *srvconfig.Config

func (Validator) GetCtx

func (v Validator) GetCtx() *server.Context

type ValidatorI

type ValidatorI interface {
	GetCtx() *server.Context
	GetAppConfig() *srvconfig.Config
}

ValidatorI expose a validator's context and configuration

Jump to

Keyboard shortcuts

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