testcli

package
v0.124.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 29 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package testcli contains auxiliary code to test CLI commands.

All testdata assets for it are contained in the cli directory and paths here use `../` prefix to reference them because the package itself is used from cli/* subpackages.

Index

Constants

View Source
const (
	ValidatorWIF  = "KxyjQ8eUa4FHt3Gvioyt1Wz29cTUrE4eTqX3yFSk1YFCsPL8uNsY"
	ValidatorAddr = "NfgHwwTi3wHAS8aFAN243C5vGbkYDpqLHP"
	MultisigAddr  = "NVTiAjNgagDkTr5HTzDmQP9kPwPHN5BgVq"

	TestWalletPath    = "../testdata/testwallet.json"
	TestWalletAccount = "Nfyz4KcsgYepRJw1W5C2uKCi6QWKf7v6gG"
	TestWalletPass    = "testpass"

	TestWalletMultiPath     = "../testdata/testwallet_multi.json"
	TestWalletMultiAccount1 = "NgHcPxgEKZQV4QBedzyASJrgiANhJqBVLw"
	TestWalletMultiAccount2 = "NLvHRfKAifjio2z9HiwLo9ZnpRPHUbAHgH"
	TestWalletMultiAccount3 = "NcDfG8foJx79XSihcDDrx1df7cHAoJBfXj"

	ValidatorWallet = "../testdata/wallet1_solo.json"
	ValidatorPass   = "one"
)

Variables

View Source
var (
	ValidatorHash, _ = address.StringToUint160(ValidatorAddr)
	ValidatorPriv, _ = keys.NewPrivateKeyFromWIF(ValidatorWIF)

	TestWalletMultiAccount1Hash, _ = address.StringToUint160(TestWalletMultiAccount1)
	TestWalletMultiAccount2Hash, _ = address.StringToUint160(TestWalletMultiAccount2)
	TestWalletMultiAccount3Hash, _ = address.StringToUint160(TestWalletMultiAccount3)
)

Functions

func DeployContract

func DeployContract(t *testing.T, e *Executor, inPath, configPath, wallet, address, pass string) util.Uint160

func GenerateKeys

func GenerateKeys(t *testing.T, n int) ([]*keys.PrivateKey, keys.PublicKeys)

func NewTestChain

func NewTestChain(t *testing.T, f func(*config.Config), run bool) (*core.Blockchain, *rpcsrv.Server, *network.Server)

Types

type ConcurrentBuffer

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

ConcurrentBuffer is a wrapper over Buffer with mutex.

func NewConcurrentBuffer

func NewConcurrentBuffer() *ConcurrentBuffer

NewConcurrentBuffer returns new ConcurrentBuffer with underlying buffer initialized.

func (*ConcurrentBuffer) Bytes

func (w *ConcurrentBuffer) Bytes() []byte

Bytes is a concurrent wrapper over the corresponding method of bytes.Buffer.

func (*ConcurrentBuffer) ReadString

func (w *ConcurrentBuffer) ReadString(delim byte) (string, error)

ReadString is a concurrent wrapper over the corresponding method of bytes.Buffer.

func (*ConcurrentBuffer) Reset

func (w *ConcurrentBuffer) Reset()

Reset is a concurrent wrapper over the corresponding method of bytes.Buffer.

func (*ConcurrentBuffer) String

func (w *ConcurrentBuffer) String() string

String is a concurrent wrapper over the corresponding method of bytes.Buffer.

func (*ConcurrentBuffer) Write

func (w *ConcurrentBuffer) Write(p []byte) (int, error)

Write is a concurrent wrapper over the corresponding method of bytes.Buffer.

type Executor

type Executor struct {
	// CLI is a cli application to test.
	CLI *cli.App
	// Chain is a blockchain instance (can be empty).
	Chain *core.Blockchain
	// RPC is an RPC server to query (can be empty).
	RPC *rpcsrv.Server
	// NetSrv is a network server (can be empty).
	NetSrv *network.Server
	// Out contains command output.
	Out *ConcurrentBuffer
	// Err contains command errors.
	Err *bytes.Buffer
	// In contains command input.
	In *bytes.Buffer
}

Executor represents context for a test instance. It can be safely used in multiple tests, but not in parallel.

func NewExecutor

func NewExecutor(t *testing.T, needChain bool) *Executor

func NewExecutorSuspended

func NewExecutorSuspended(t *testing.T) *Executor

func NewExecutorWithConfig

func NewExecutorWithConfig(t *testing.T, needChain, runChain bool, f func(*config.Config)) *Executor

func (*Executor) CheckAwaitableTxPersisted added in v0.105.0

func (e *Executor) CheckAwaitableTxPersisted(t *testing.T, prefix ...string) (*transaction.Transaction, uint32)

func (*Executor) CheckEOF

func (e *Executor) CheckEOF(t *testing.T)

func (*Executor) CheckLine

func (e *Executor) CheckLine(t *testing.T, line, expected string)

func (*Executor) CheckNextLine

func (e *Executor) CheckNextLine(t *testing.T, expected string)

func (*Executor) CheckScriptDump

func (e *Executor) CheckScriptDump(t *testing.T, scriptSize int)

func (*Executor) CheckTxPersisted

func (e *Executor) CheckTxPersisted(t *testing.T, prefix ...string) (*transaction.Transaction, uint32)

func (*Executor) CheckTxTestInvokeOutput

func (e *Executor) CheckTxTestInvokeOutput(t *testing.T, scriptSize int)

func (*Executor) Close

func (e *Executor) Close(t *testing.T)

func (*Executor) GetNextLine

func (e *Executor) GetNextLine(t *testing.T) string

func (*Executor) GetTransaction

func (e *Executor) GetTransaction(t *testing.T, h util.Uint256) (*transaction.Transaction, uint32)

GetTransaction returns tx with hash h after it has persisted. If it is in mempool, we can just wait for the next block, otherwise it must be already in chain. 1 second is time per block in a unittest chain.

func (*Executor) Run

func (e *Executor) Run(t *testing.T, args ...string)

Run runs command and checks that there were no errors.

func (*Executor) RunUnchecked added in v0.106.0

func (e *Executor) RunUnchecked(t *testing.T, args ...string) error

RunUnchecked runs command and ensures that proper exit code is set (0 if no error is returned, 1 is an error is returned). The resulting error is returned (if so).

func (*Executor) RunWithError

func (e *Executor) RunWithError(t *testing.T, args ...string)

RunWithError runs command and checks that is exits with error and exit code 1.

func (*Executor) RunWithErrorCheck added in v0.106.3

func (e *Executor) RunWithErrorCheck(t *testing.T, msg string, args ...string)

RunWithErrorCheck runs command and checks that there were errors with the specified message. Exit code is not checked.

func (*Executor) RunWithErrorCheckExit added in v0.106.3

func (e *Executor) RunWithErrorCheckExit(t *testing.T, msg string, args ...string)

RunWithErrorCheckExit runs command and checks that is exits with error and exit code 1.

Jump to

Keyboard shortcuts

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