neotest

package
v0.98.6-pre Latest Latest
Warning

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

Go to latest
Published: May 13, 2022 License: MIT Imports: 32 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Nonce

func Nonce() uint32

Nonce returns unique number that can be used as nonce for new transactions.

func TestInvoke

func TestInvoke(bc blockchainer.Blockchainer, tx *transaction.Transaction) (*vm.VM, error)

TestInvoke creates a test VM with dummy block and executes transaction in it.

Types

type Contract

type Contract struct {
	Hash     util.Uint160
	NEF      *nef.File
	Manifest *manifest.Manifest
}

Contract contains contract info for deployment.

func CompileFile

func CompileFile(t *testing.T, sender util.Uint160, srcPath string, configPath string) *Contract

CompileFile compiles contract from file and returns it's NEF, manifest and hash.

func CompileSource

func CompileSource(t *testing.T, sender util.Uint160, src io.Reader, opts *compiler.Options) *Contract

CompileSource compiles contract from reader and returns it's NEF, manifest and hash.

type ContractInvoker

type ContractInvoker struct {
	*Executor
	Hash    util.Uint160
	Signers []Signer
}

ContractInvoker is a client for specific contract.

func (*ContractInvoker) Invoke

func (c *ContractInvoker) Invoke(t *testing.T, result interface{}, method string, args ...interface{}) util.Uint256

Invoke invokes method with args, persists transaction and checks the result. Returns transaction hash.

func (*ContractInvoker) InvokeAndCheck added in v0.98.1

func (c *ContractInvoker) InvokeAndCheck(t *testing.T, checkResult func(t *testing.T, stack []stackitem.Item), method string, args ...interface{}) util.Uint256

InvokeAndCheck invokes method with args, persists transaction and checks the result using provided function. Returns transaction hash.

func (*ContractInvoker) InvokeFail

func (c *ContractInvoker) InvokeFail(t *testing.T, message string, method string, args ...interface{})

InvokeFail invokes method with args, persists transaction and checks the error message. Returns transaction hash.

func (*ContractInvoker) InvokeWithFeeFail

func (c *ContractInvoker) InvokeWithFeeFail(t *testing.T, message string, sysFee int64, method string, args ...interface{}) util.Uint256

InvokeWithFeeFail is like InvokeFail but sets custom system fee for the transaction.

func (*ContractInvoker) PrepareInvoke

func (c *ContractInvoker) PrepareInvoke(t *testing.T, method string, args ...interface{}) *transaction.Transaction

PrepareInvoke creates new invocation transaction.

func (*ContractInvoker) PrepareInvokeNoSign

func (c *ContractInvoker) PrepareInvokeNoSign(t *testing.T, method string, args ...interface{}) *transaction.Transaction

PrepareInvokeNoSign creates new unsigned invocation transaction.

func (*ContractInvoker) TestInvoke

func (c *ContractInvoker) TestInvoke(t *testing.T, method string, args ...interface{}) (*vm.Stack, error)

TestInvoke creates test VM and invokes method with args.

func (*ContractInvoker) WithSigners

func (c *ContractInvoker) WithSigners(signers ...Signer) *ContractInvoker

WithSigners creates new client with the provided signer.

type Executor

type Executor struct {
	Chain         blockchainer.Blockchainer
	Validator     Signer
	Committee     Signer
	CommitteeHash util.Uint160
	Contracts     map[string]*Contract
}

Executor is a wrapper over chain state.

func NewExecutor

func NewExecutor(t *testing.T, bc blockchainer.Blockchainer, validator, committee Signer) *Executor

NewExecutor creates new executor instance from provided blockchain and committee.

func (*Executor) AddBlockCheckHalt

func (e *Executor) AddBlockCheckHalt(t *testing.T, txs ...*transaction.Transaction) *block.Block

AddBlockCheckHalt is a convenient wrapper over AddBlock and CheckHalt.

func (*Executor) AddNewBlock

func (e *Executor) AddNewBlock(t *testing.T, txs ...*transaction.Transaction) *block.Block

AddNewBlock creates a new block from provided transactions and adds it on bc.

func (*Executor) CheckFault

func (e *Executor) CheckFault(t *testing.T, h util.Uint256, s string)

CheckFault checks that transaction persisted with FAULT state. Raised exception is also checked to contain s as a substring.

func (*Executor) CheckGASBalance added in v0.98.1

func (e *Executor) CheckGASBalance(t *testing.T, acc util.Uint160, expected *big.Int)

CheckGASBalance ensures that provided account owns specified amount of GAS.

func (*Executor) CheckHalt

func (e *Executor) CheckHalt(t *testing.T, h util.Uint256, stack ...stackitem.Item) *state.AppExecResult

CheckHalt checks that transaction persisted with HALT state.

func (*Executor) CheckTxNotificationEvent

func (e *Executor) CheckTxNotificationEvent(t *testing.T, h util.Uint256, index int, expected state.NotificationEvent)

CheckTxNotificationEvent checks that specified event was emitted at the specified position during transaction script execution. Negative index corresponds to backwards enumeration.

func (*Executor) CommitteeInvoker

func (e *Executor) CommitteeInvoker(h util.Uint160) *ContractInvoker

CommitteeInvoker creates new ContractInvoker for contract with hash h and committee multisignature signer.

func (*Executor) DeployContract

func (e *Executor) DeployContract(t *testing.T, c *Contract, data interface{}) util.Uint256

DeployContract compiles and deploys contract to bc. It also checks that precalculated contract hash matches the actual one. data is an optional argument to `_deploy`. Returns hash of the deploy transaction.

func (*Executor) DeployContractCheckFAULT

func (e *Executor) DeployContractCheckFAULT(t *testing.T, c *Contract, data interface{}, errMessage string)

DeployContractCheckFAULT compiles and deploys contract to bc. It checks that deploy transaction FAULTed with the specified error.

func (*Executor) GenerateNewBlocks added in v0.98.1

func (e *Executor) GenerateNewBlocks(t *testing.T, count int)

GenerateNewBlocks adds specified number of empty blocks to the chain.

func (*Executor) GetBlockByIndex added in v0.98.1

func (e *Executor) GetBlockByIndex(t *testing.T, idx int) *block.Block

GetBlockByIndex returns block by the specified index.

func (*Executor) GetTransaction added in v0.98.1

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

GetTransaction returns transaction and its height by the specified hash.

func (*Executor) GetTxExecResult added in v0.98.1

func (e *Executor) GetTxExecResult(t *testing.T, h util.Uint256) *state.AppExecResult

GetTxExecResult returns application execution results for the specified transaction.

func (*Executor) InvokeScript

func (e *Executor) InvokeScript(t *testing.T, script []byte, signers []Signer) util.Uint256

InvokeScript adds transaction with the specified script to the chain and returns its hash. It does no faults check.

func (*Executor) InvokeScriptCheckFAULT

func (e *Executor) InvokeScriptCheckFAULT(t *testing.T, script []byte, signers []Signer, errMessage string)

InvokeScriptCheckFAULT adds transaction with the specified script to the chain and checks it's FAULTed with the specified error.

func (*Executor) InvokeScriptCheckHALT

func (e *Executor) InvokeScriptCheckHALT(t *testing.T, script []byte, signers []Signer, stack ...stackitem.Item)

InvokeScriptCheckHALT adds transaction with the specified script to the chain and checks it's HALTed with the specified items on stack.

func (*Executor) NativeHash

func (e *Executor) NativeHash(t *testing.T, name string) util.Uint160

NativeHash returns native contract hash by name.

func (*Executor) NativeID added in v0.98.1

func (e *Executor) NativeID(t *testing.T, name string) int32

NativeID returns native contract ID by name.

func (*Executor) NewAccount

func (e *Executor) NewAccount(t *testing.T, expectedGASBalance ...int64) Signer

NewAccount returns new signer holding 100.0 GAS (or given amount is specified). This method advances the chain by one block with a transfer transaction.

func (*Executor) NewDeployTx

func (e *Executor) NewDeployTx(t *testing.T, bc blockchainer.Blockchainer, c *Contract, data interface{}) *transaction.Transaction

NewDeployTx returns new deployment tx for contract signed by committee.

func (*Executor) NewTx

func (e *Executor) NewTx(t *testing.T, signers []Signer,
	hash util.Uint160, method string, args ...interface{}) *transaction.Transaction

NewTx creates new transaction which invokes contract method. Transaction is signed with signer.

func (*Executor) NewUnsignedBlock

func (e *Executor) NewUnsignedBlock(t *testing.T, txs ...*transaction.Transaction) *block.Block

NewUnsignedBlock creates new unsigned block from txs.

func (*Executor) NewUnsignedTx

func (e *Executor) NewUnsignedTx(t *testing.T, hash util.Uint160, method string, args ...interface{}) *transaction.Transaction

NewUnsignedTx creates new unsigned transaction which invokes method of contract with hash.

func (*Executor) SignBlock

func (e *Executor) SignBlock(b *block.Block) *block.Block

SignBlock add validators signature to b.

func (*Executor) SignTx

func (e *Executor) SignTx(t *testing.T, tx *transaction.Transaction, sysFee int64, signers ...Signer) *transaction.Transaction

SignTx signs a transaction using provided signers.

func (*Executor) TopBlock

func (e *Executor) TopBlock(t *testing.T) *block.Block

TopBlock returns block with the highest index.

func (*Executor) ValidatorInvoker added in v0.98.1

func (e *Executor) ValidatorInvoker(h util.Uint160) *ContractInvoker

ValidatorInvoker creates new ContractInvoker for contract with hash h and validators multisignature signer.

type MultiSigner added in v0.98.1

type MultiSigner interface {
	Signer
	// Single returns simple-signature signer for n-th account in list.
	Single(n int) SingleSigner
}

MultiSigner is the interface for multisignature signing account.

func NewMultiSigner

func NewMultiSigner(accs ...*wallet.Account) MultiSigner

NewMultiSigner returns multi-signature signer for the provided account. It must contain at least as many accounts as needed to sign the script.

type Signer

type Signer interface {
	// ScriptHash returns signer script hash.
	Script() []byte
	// Script returns signer verification script.
	ScriptHash() util.Uint160
	// SignHashable returns invocation script for signing an item.
	SignHashable(uint32, hash.Hashable) []byte
	// SignTx signs a transaction.
	SignTx(netmode.Magic, *transaction.Transaction) error
}

Signer is a generic interface which can be either simple- or multi-signature signer.

type SingleSigner added in v0.98.1

type SingleSigner interface {
	Signer
	// Account returns underlying account which can be used to
	// get public key and/or sign arbitrary things.
	Account() *wallet.Account
}

SingleSigner is a generic interface for simple one-signature signer.

func NewSingleSigner

func NewSingleSigner(acc *wallet.Account) SingleSigner

NewSingleSigner returns multi-signature signer for the provided account. It must contain exactly as many accounts as needed to sign the script.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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