integration

package
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2025 License: UNKNOWN not legal advice Imports: 0 Imported by: 0

Documentation

Overview

Package integration offers utilities to run txtar-based tests against the gnoland system by extending the functionalities provided by the standard testscript package. This package is currently in an experimental phase and may undergo significant changes in the future.

SetupGnolandTestScript, sets up the environment for running txtar tests, introducing additional commands like "gnoland" and "gnokey" into the test script ecosystem. Specifically, it allows the user to initiate an in-memory gnoland node and interact with it via the `gnokey` command.

Additional Command Overview:

1. `gnoland [start|stop|restart]`:

  • The gnoland node doesn't start automatically. This enables the user to do some pre-configuration or pass custom arguments to the start command.
  • `gnoland restart` will simulate restarting a node, as in stopping and starting it again, recovering state from the persisted database data.
  • `gnoland start -non-validator` can be used to start a node as a non-validator node.

2. `gnokey`:

  • Supports most of the common commands.
  • `--remote`, `--insecure-password-stdin`, and `--home` flags are set automatically to communicate with the gnoland node.
  • In order to handle escape sequences like `\n` within arguments, you can enclose the argument in `"`

3. `adduser`:

  • Must be run before `gnoland start`.
  • Creates a new user in the default keybase directory.

4. `adduserfrom`:

  • Must be run before `gnoland start`.
  • Creates a new user in the default keybase directory from a given seed. ( Optionally, account and index can be provided )

5. `loadpkg`:

  • Must be run before `gnoland start`.
  • Loads a specific package from the 'examples' directory or from the working ($WORK) directory.
  • Can be used to load a single package or all packages within a directory.
  • If the target package has a `gno.mod`, all its dependencies (and their respective dependencies) will also be loaded.
  • The command takes either one or two arguments. The first argument is the name of the package(s), and the second (optional) argument is the path to the package(s). Examples: -- # Load a package from the 'examples' directory: -- loadpkg gno.land/p/demo/ufmt -- # Load a package `./bar` from the testscript's working directory with the name `gno.land/r/foobar/bar`: -- loadpkg gno.land/r/foobar/bar $WORK/bar
  • If the path is not prefixed with the working directory, it is assumed to be relative to the examples directory.
  • It's important to note that the load order is significant when using multiple `loadpkg` command; packages should be loaded in the order they are dependent upon.

6. `patchpkg`:

  • Patches any loaded files by package by replacing all occurrences of the first argument with the second.
  • This is mostly used to replace hardcoded addresses from loaded packages.
  • NOTE: this command may only be temporary, as it's not best approach to solve the above problem

Logging:

Gnoland logs aren't forwarded to stdout to avoid overwhelming the tests with too much information. Instead, a log directory can be specified with `LOG_DIR`, or you can set `TESTWORK=true` to persist logs in the txtar working directory. In any case, the log file should be printed on start if one of these environment variables is set.

Accounts:

By default, only the test1 user will be created in the default keybase directory, with no password set. The default gnoland genesis balance file and the genesis transaction file are also registered by default.

Examples:

Examples can be found in the `testdata` directory of this package.

Environment Variables:

Input:

  • TESTWORK: A boolean that, when enabled, retains working directories after tests for inspection. If enabled, gnoland logs will be persisted inside this folder.

  • UPDATE_SCRIPTS: A boolean that, when enabled, updates the test scripts if a `cmp` command fails and its second argument refers to a file inside the testscript file. The content will be quoted with txtar.Quote if needed, requiring manual edits if it's not unquoted in the script.

Output (available inside testscripts files):

  • WORK: The path to the temporary work directory tree created for each script.

  • GNOROOT: Points to the local location of the gno repository, serving as the GOROOT equivalent for gno.

  • GNOHOME: Refers to the local directory where gnokey stores its keys.

  • GNODATA: The path where the gnoland node stores its configuration and data. It's set only if the node has started.

  • USER_SEED_test1: Contains the seed for the test1 account.

  • USER_ADDR_test1: Contains the address for the test1 account.

  • RPC_ADDR: Points to the gnoland node's remote address. It's set only if the node has started.

For a more comprehensive guide on original behaviors, additional commands and environment variables, refer to the original documentation of testscripts available here: https://github.com/rogpeppe/go-internal/blob/master/testscript/doc.go

Index

Constants

View Source
const (
	DefaultAccount_Name    = "test1"
	DefaultAccount_Address = "g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5"
	DefaultAccount_Seed    = "" /* 161-byte string literal not displayed */
)

Variables

This section is empty.

Functions

func DefaultTestingGenesisConfig

func DefaultTestingGenesisConfig(gnoroot string, self crypto.PubKey, tmconfig *tmcfg.Config) *bft.GenesisDoc

func DefaultTestingTMConfig

func DefaultTestingTMConfig(gnoroot string) *tmcfg.Config

DefaultTestingTMConfig constructs the default Tendermint configuration for testing.

func LoadDefaultGenesisBalanceFile

func LoadDefaultGenesisBalanceFile(t TestingTS, gnoroot string) []gnoland.Balance

LoadDefaultGenesisBalanceFile loads the default genesis balance file for testing.

func LoadDefaultGenesisParamFile

func LoadDefaultGenesisParamFile(t TestingTS, gnoroot string) []gnoland.Param

LoadDefaultGenesisParamFile loads the default genesis balance file for testing.

func LoadDefaultGenesisTXsFile

func LoadDefaultGenesisTXsFile(t TestingTS, chainid string, gnoroot string) []gnoland.TxWithMetadata

LoadDefaultGenesisTXsFile loads the default genesis transactions file for testing.

func LoadDefaultPackages

func LoadDefaultPackages(t TestingTS, creator bft.Address, gnoroot string) []gnoland.TxWithMetadata

LoadDefaultPackages loads the default packages for testing using a given creator address and gnoroot directory.

func RunMain

func RunMain(ctx context.Context, stdin io.Reader, stdout, stderr io.Writer) error

func RunNode

func RunNode(ctx context.Context, pcfg *ProcessNodeConfig, stdout, stderr io.Writer) error

RunNode initializes and runs a gnoaland node with the provided configuration.

func SetupGnolandTestscript

func SetupGnolandTestscript(t *testing.T, p *testscript.Params) error

func TestingInMemoryNode

func TestingInMemoryNode(t TestingTS, logger *slog.Logger, config *gnoland.InMemoryNodeConfig) (*node.Node, string)

TestingInMemoryNode initializes and starts an in-memory node for testing. It returns the node instance and its RPC remote address.

func TestingMinimalNodeConfig

func TestingMinimalNodeConfig(gnoroot string) *gnoland.InMemoryNodeConfig

TestingMinimalNodeConfig constructs the default minimal in-memory node configuration for testing.

func TestingNodeConfig

func TestingNodeConfig(t TestingTS, gnoroot string, additionalTxs ...gnoland.TxWithMetadata) (*gnoland.InMemoryNodeConfig, bft.Address)

TestingNodeConfig constructs an in-memory node configuration with default packages and genesis transactions already loaded. It will return the default creator address of the loaded packages.

Types

type MarshalableGenesisDoc

type MarshalableGenesisDoc bft.GenesisDoc

func NewMarshalableGenesisDoc

func NewMarshalableGenesisDoc(doc *bft.GenesisDoc) *MarshalableGenesisDoc

func (*MarshalableGenesisDoc) MarshalJSON

func (m *MarshalableGenesisDoc) MarshalJSON() ([]byte, error)

func (*MarshalableGenesisDoc) ToGenesisDoc

func (m *MarshalableGenesisDoc) ToGenesisDoc() *bft.GenesisDoc

Cast back to the original bft.GenesisDoc.

func (*MarshalableGenesisDoc) UnmarshalJSON

func (m *MarshalableGenesisDoc) UnmarshalJSON(data []byte) (err error)

type NodeProcess

type NodeProcess interface {
	Stop() error
	Address() string
}

func RunInMemoryProcess

func RunInMemoryProcess(ctx context.Context, cfg ProcessConfig) (NodeProcess, error)

func RunNodeProcess

func RunNodeProcess(ctx context.Context, cfg ProcessConfig, name string, args ...string) (NodeProcess, error)

RunNodeProcess runs the binary at the given path with the provided configuration.

type NodesManager

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

NodesManager manages access to the nodes map with synchronization.

func NewNodesManager

func NewNodesManager() *NodesManager

NewNodesManager creates a new instance of NodesManager.

func (*NodesManager) Delete

func (nm *NodesManager) Delete(sid string)

Delete removes a node from the map.

func (*NodesManager) Get

func (nm *NodesManager) Get(sid string) (*tNodeProcess, bool)

Get retrieves a node by its SID.

func (*NodesManager) IsNodeRunning

func (nm *NodesManager) IsNodeRunning(sid string) bool

func (*NodesManager) Set

func (nm *NodesManager) Set(sid string, node *tNodeProcess)

Set adds or updates a node in the map.

type PkgsLoader

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

func NewPkgsLoader

func NewPkgsLoader() *PkgsLoader

func (*PkgsLoader) List

func (pl *PkgsLoader) List() gnomod.PkgList

func (*PkgsLoader) LoadAllPackagesFromDir

func (pl *PkgsLoader) LoadAllPackagesFromDir(path string) error

func (*PkgsLoader) LoadPackage

func (pl *PkgsLoader) LoadPackage(modroot string, path, name string) error

func (*PkgsLoader) LoadPackages

func (pl *PkgsLoader) LoadPackages(creator bft.Address, fee std.Fee, deposit std.Coins) ([]gnoland.TxWithMetadata, error)

func (*PkgsLoader) SetPatch

func (pl *PkgsLoader) SetPatch(replace, with string)

type ProcessConfig

type ProcessConfig struct {
	Node *ProcessNodeConfig

	// These parameters are not meant to be passed to the process
	CoverDir       string
	Stderr, Stdout io.Writer
}

type ProcessNodeConfig

type ProcessNodeConfig struct {
	ValidatorKey ed25519.PrivKeyEd25519 `json:"priv"`
	Verbose      bool                   `json:"verbose"`
	DBDir        string                 `json:"dbdir"`
	RootDir      string                 `json:"rootdir"`
	Genesis      *MarshalableGenesisDoc `json:"genesis"`
	TMConfig     *tmcfg.Config          `json:"tm"`
}

type TestingTS

type TestingTS = require.TestingT

func TSTestingT

func TSTestingT(ts *testscript.TestScript) TestingTS

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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