testcli

package
v0.105.1 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2024 License: MIT Imports: 29 Imported by: 0

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"

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

Variables

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

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) RunWithError

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

RunWithError runs command and checks that is exits with error.

Jump to

Keyboard shortcuts

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