testnode

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2024 License: Apache-2.0 Imports: 58 Imported by: 6

Documentation

Index

Constants

View Source
const (
	DefaultTimeout = 30 * time.Second
)

Variables

This section is empty.

Functions

func CalculateMeanGas

func CalculateMeanGas(ctx context.Context, rpcAddress, msgType string, fromHeight int64, toHeight int64) (float64, int64, error)

func CalculateMeanGasFromRecentBlocks

func CalculateMeanGasFromRecentBlocks(ctx context.Context, rpcAddress, msgType string, blocks int64) (float64, int64, error)

func DecodeBlockData

func DecodeBlockData(data types.Data) ([]sdk.Msg, error)

func DefaultAppConfig

func DefaultAppConfig() *srvconfig.Config

DefaultAppConfig wraps the default config described in the server

func DefaultGenesisState

func DefaultGenesisState(fundedAccounts ...string) (map[string]json.RawMessage, keyring.Keyring, error)

DefaultGenesisState returns a default genesis state and a keyring with accounts that have coins. It adds a default "validator" account that is funded and used for the valop address of the single validator. The keyring accounts are based on the fundedAccounts parameter.

func DefaultParams

func DefaultParams() *tmproto.ConsensusParams

func DefaultTendermintConfig

func DefaultTendermintConfig() *tmconfig.Config

func GetFreePort

func GetFreePort() int

func InitFiles

func InitFiles(
	t testing.TB,
	cparams *tmproto.ConsensusParams,
	tmCfg *config.Config,
	genState map[string]json.RawMessage,
	kr keyring.Keyring,
	chainID string,
) (string, keyring.Keyring, error)

InitFiles initializes the files for a new tendermint node with the provided genesis state and consensus parameters. The provided keyring is used to create a validator key and the chainID is used to initialize the genesis state. The keyring is returned with the validator account added.

func NewCometNode

func NewCometNode(t testing.TB, baseDir string, cfg *Config) (*node.Node, srvtypes.Application, error)

NewCometNode creates a ready to use comet node that operates a single validator celestia-app network. It expects that all configuration files are already initialized and saved to the baseDir.

func QueryTx

func QueryTx(clientCtx client.Context, hashHexStr string, prove bool) (*rpctypes.ResultTx, error)

func ReadBlockHeights

func ReadBlockHeights(ctx context.Context, rpcAddress string, fromHeight, toHeight int64) ([]*types.Block, error)

func ReadBlockchain

func ReadBlockchain(ctx context.Context, rpcAddress string) ([]*types.Block, error)

func ReadRecentBlocks

func ReadRecentBlocks(ctx context.Context, rpcAddress string, blocks int64) ([]*types.Block, error)

func SignAndBroadcastTx

func SignAndBroadcastTx(encCfg encoding.Config, c client.Context, account string, msg ...sdk.Msg) (res *sdk.TxResponse, err error)

SignAndBroadcastTx signs a transaction using the provided account and keyring inside the client.Context, then broadcasts it synchronously.

Types

type Config

type Config struct {
	// ChainID is the chain ID of the network.
	ChainID string
	// TmConfig is the Tendermint configuration used for the network.
	TmConfig *tmconfig.Config
	// AppConfig is the application configuration of the test node.
	AppConfig *srvconfig.Config
	// ConsensusParams are the consensus parameters of the test node.
	ConsensusParams *tmproto.ConsensusParams
	// AppOptions are the application options of the test node. Portions of the
	// app config will automatically be set into the app option when the app
	// config is set.
	AppOptions *KVAppOptions
	// GenesisOptions are the genesis options of the test node.
	GenesisOptions []GenesisOption
	// Accounts are the accounts of the test node.
	Accounts []string
	// AppCreator is used to create the application for the testnode.
	AppCreator srvtypes.AppCreator
	// SupressLogs
	SupressLogs bool
}

Config is the configuration of a test node.

func DefaultConfig

func DefaultConfig() *Config

func (*Config) WithAccounts

func (c *Config) WithAccounts(accs []string) *Config

WithAccounts sets the Accounts and returns the Config.

func (*Config) WithAppConfig

func (c *Config) WithAppConfig(conf *srvconfig.Config) *Config

WithAppConfig sets the AppConfig and returns the Config.

Warning: This method will also overwrite relevant portions of the app config to the app options. See the SetFromAppConfig method for more information on which values are overwritten.

func (*Config) WithAppCreator

func (c *Config) WithAppCreator(creator srvtypes.AppCreator) *Config

WithAppCreator sets the AppCreator and returns the Config.

func (*Config) WithAppOptions

func (c *Config) WithAppOptions(opts *KVAppOptions) *Config

WithAppOptions sets the AppOptions and returns the Config.

Warning: If the app config is set after this, it could overwrite some values. See SetFromAppConfig for more information on which values are overwritten.

func (*Config) WithChainID

func (c *Config) WithChainID(s string) *Config

WithChainID sets the ChainID and returns the Config.

func (*Config) WithConsensusParams

func (c *Config) WithConsensusParams(params *tmproto.ConsensusParams) *Config

WithConsensusParams sets the ConsensusParams and returns the Config.

func (*Config) WithGenesisOptions

func (c *Config) WithGenesisOptions(opts ...GenesisOption) *Config

WithGenesisOptions sets the GenesisOptions and returns the Config.

func (*Config) WithSupressLogs

func (c *Config) WithSupressLogs(sl bool) *Config

WithSupressLogs sets the SupressLogs and returns the Config.

func (*Config) WithTendermintConfig

func (c *Config) WithTendermintConfig(conf *tmconfig.Config) *Config

WithTendermintConfig sets the TmConfig and returns the *Config.

func (*Config) WithTimeoutCommit

func (c *Config) WithTimeoutCommit(d time.Duration) *Config

WithTimeoutCommit sets the TimeoutCommit and returns the Config.

type Context

type Context struct {
	client.Context
	// contains filtered or unexported fields
}

func NewContext

func NewContext(goCtx context.Context, kr keyring.Keyring, tmCfg *tmconfig.Config, chainID string) Context

func NewNetwork

func NewNetwork(t testing.TB, cfg *Config) (cctx Context, rpcAddr, grpcAddr string)

NewNetwork starts a single valiator celestia-app network using the provided configurations. Configured accounts will be funded and their keys can be accessed in keyring returned client.Context. All rpc, p2p, and grpc addresses in the provided configs are overwritten to use open ports. The node can be accessed via the returned client.Context or via the returned rpc and grpc addresses. Configured genesis options will be applied after all accounts have been initialized.

func StartGRPCServer

func StartGRPCServer(app srvtypes.Application, appCfg *srvconfig.Config, cctx Context) (Context, func() error, error)

StartGRPCServer starts the grpc server using the provided application and config. A grpc client connection to that server is also added to the client context. The returned function should be used to shutdown the server.

func StartNode

func StartNode(tmNode *node.Node, cctx Context) (Context, func() error, error)

StartNode starts the tendermint node along with a local core rpc client. The rpc is returned via the client.Context. The function returned should be called during cleanup to teardown the node, core client, along with canceling the internal context.Context in the returned Context.

func (*Context) FillBlock

func (c *Context) FillBlock(squareSize int, accounts []string, broadcastMode string) (*sdk.TxResponse, error)

FillBlock creates and submits a single transaction that is large enough to create a square of the desired size. broadcast mode indicates if the tx should be submitted async, sync, or block. (see flags.BroadcastModeSync). If broadcast mode is the string zero value, then it will be set to block.

func (*Context) GenesisTime

func (c *Context) GenesisTime() (time.Time, error)

GenesisTime returns the genesis block time.

func (*Context) GoContext

func (c *Context) GoContext() context.Context

func (*Context) HeightForTimestamp

func (c *Context) HeightForTimestamp(timestamp time.Time) (int64, error)

HeightForTimestamp returns the block height for the first block after a given timestamp.

func (*Context) LatestHeight

func (c *Context) LatestHeight() (int64, error)

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

func (*Context) LatestTimestamp

func (c *Context) LatestTimestamp() (time.Time, error)

LatestTimestamp returns the latest timestamp of the network or an error if the query fails.

func (*Context) PostData

func (c *Context) PostData(account, broadcastMode string, ns appns.Namespace, blobData []byte) (*sdk.TxResponse, error)

PostData will create and submit PFB transaction containing the namespace and blobData. This function blocks until the PFB has been included in a block and returns an error if the transaction is invalid or is rejected by the mempool.

func (*Context) WaitForBlocks

func (c *Context) WaitForBlocks(n int64) error

WaitForBlocks waits until n blocks have been committed, returning an error upon failure.

func (*Context) WaitForHeight

func (c *Context) 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 (*Context) WaitForHeightWithTimeout

func (c *Context) WaitForHeightWithTimeout(h int64, t time.Duration) (int64, error)

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

func (*Context) WaitForNextBlock

func (c *Context) WaitForNextBlock() error

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

func (*Context) WaitForTimestamp

func (c *Context) WaitForTimestamp(t time.Time) (time.Time, error)

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

func (*Context) WaitForTimestampWithTimeout

func (c *Context) WaitForTimestampWithTimeout(t time.Time, d time.Duration) (time.Time, error)

WaitForTimestampWithTimeout waits for a block with a timestamp greater than t.

func (*Context) WaitForTx

func (c *Context) WaitForTx(hashHexStr string, blocks int) (*rpctypes.ResultTx, error)

type GenesisOption

type GenesisOption func(state map[string]json.RawMessage) map[string]json.RawMessage

GenesisOption allows for arbitrary changes to be made on the genesis state after initial accounts have been added. It accepts the genesis state as input and is expected to return the modifed genesis as output.

func ImmediateProposals

func ImmediateProposals(codec codec.Codec) GenesisOption

ImmediateProposals sets the thresholds for getting a gov proposal to very low levels.

func SetBlobParams

func SetBlobParams(codec codec.Codec, params blobtypes.Params) GenesisOption

SetBlobParams will set the provided blob params as genesis state.

type KVAppOptions

type KVAppOptions struct {
	// contains filtered or unexported fields
}

func DefaultAppOptions

func DefaultAppOptions() *KVAppOptions

DefaultAppOptions returns the default application options. The options are set using the default app config. If the app config is set after this, it will overwrite these values.

func NewKVAppOptions

func NewKVAppOptions() *KVAppOptions

func (*KVAppOptions) Get

func (ao *KVAppOptions) Get(o string) interface{}

Get implements AppOptions

func (*KVAppOptions) Set

func (ao *KVAppOptions) Set(o string, v interface{})

Set adds an option to the KVAppOptions

func (*KVAppOptions) SetFromAppConfig

func (ao *KVAppOptions) SetFromAppConfig(appCfg *srvconfig.Config)

func (*KVAppOptions) SetMany

func (ao *KVAppOptions) SetMany(o map[string]interface{})

SetMany adds an option to the KVAppOptions

Jump to

Keyboard shortcuts

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