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
- Variables
- func DeployContract(t *testing.T, e *Executor, inPath, configPath, wallet, address, pass string) util.Uint160
- func GenerateKeys(t *testing.T, n int) ([]*keys.PrivateKey, keys.PublicKeys)
- func NewTestChain(t *testing.T, f func(*config.Config), run bool) (*core.Blockchain, *rpcsrv.Server, *network.Server)
- type ConcurrentBuffer
- type Executor
- func (e *Executor) CheckAwaitableTxPersisted(t *testing.T, prefix ...string) (*transaction.Transaction, uint32)
- func (e *Executor) CheckEOF(t *testing.T)
- func (e *Executor) CheckLine(t *testing.T, line, expected string)
- func (e *Executor) CheckNextLine(t *testing.T, expected string)
- func (e *Executor) CheckScriptDump(t *testing.T, scriptSize int)
- func (e *Executor) CheckTxPersisted(t *testing.T, prefix ...string) (*transaction.Transaction, uint32)
- func (e *Executor) CheckTxTestInvokeOutput(t *testing.T, scriptSize int)
- func (e *Executor) Close(t *testing.T)
- func (e *Executor) GetNextLine(t *testing.T) string
- func (e *Executor) GetTransaction(t *testing.T, h util.Uint256) (*transaction.Transaction, uint32)
- func (e *Executor) Run(t *testing.T, args ...string)
- func (e *Executor) RunUnchecked(t *testing.T, args ...string) error
- func (e *Executor) RunWithError(t *testing.T, args ...string)
- func (e *Executor) RunWithErrorCheck(t *testing.T, msg string, args ...string)
- func (e *Executor) RunWithErrorCheckExit(t *testing.T, msg string, args ...string)
Constants ¶
const ( ValidatorWIF = "KxyjQ8eUa4FHt3Gvioyt1Wz29cTUrE4eTqX3yFSk1YFCsPL8uNsY" ValidatorAddr = "NfgHwwTi3wHAS8aFAN243C5vGbkYDpqLHP" MultisigAddr = "NVTiAjNgagDkTr5HTzDmQP9kPwPHN5BgVq" TestWalletPath = "../testdata/testwallet.json" TestWalletAccount = "Nfyz4KcsgYepRJw1W5C2uKCi6QWKf7v6gG" TestWalletMultiPath = "../testdata/testwallet_multi.json" TestWalletMultiAccount1 = "NgHcPxgEKZQV4QBedzyASJrgiANhJqBVLw" TestWalletMultiAccount2 = "NLvHRfKAifjio2z9HiwLo9ZnpRPHUbAHgH" TestWalletMultiAccount3 = "NcDfG8foJx79XSihcDDrx1df7cHAoJBfXj" ValidatorWallet = "../testdata/wallet1_solo.json" ValidatorPass = "one" )
Variables ¶
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 GenerateKeys ¶
func GenerateKeys(t *testing.T, n int) ([]*keys.PrivateKey, keys.PublicKeys)
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.
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 NewExecutorSuspended ¶
func NewExecutorWithConfig ¶
func (*Executor) CheckAwaitableTxPersisted ¶ added in v0.105.0
func (e *Executor) CheckAwaitableTxPersisted(t *testing.T, prefix ...string) (*transaction.Transaction, uint32)
func (*Executor) CheckTxPersisted ¶
func (e *Executor) CheckTxPersisted(t *testing.T, prefix ...string) (*transaction.Transaction, uint32)
func (*Executor) CheckTxTestInvokeOutput ¶
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) RunUnchecked ¶ added in v0.106.0
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 ¶
RunWithError runs command and checks that is exits with error and exit code 1.
func (*Executor) RunWithErrorCheck ¶ added in v0.106.3
RunWithErrorCheck runs command and checks that there were errors with the specified message. Exit code is not checked.