neotest

package
v0.98.1-pre Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2021 License: MIT Imports: 30 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) 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) 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.

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

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

NewAccount returns new signer holding 100.0 GAS. 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.

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.

func NewMultiSigner

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

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

func NewSingleSigner

func NewSingleSigner(acc *wallet.Account) Signer

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