neotest: adapt framework to work with *testing.B
This commit is contained in:
parent
ff13af804d
commit
59f3fa1ef1
7 changed files with 55 additions and 56 deletions
|
@ -90,7 +90,7 @@ func setNodesByRole(t *testing.T, designateInvoker *neotest.ContractInvoker, ok
|
||||||
|
|
||||||
func checkNodeRoles(t *testing.T, designateInvoker *neotest.ContractInvoker, ok bool, r noderoles.Role, index uint32, res keys.PublicKeys) {
|
func checkNodeRoles(t *testing.T, designateInvoker *neotest.ContractInvoker, ok bool, r noderoles.Role, index uint32, res keys.PublicKeys) {
|
||||||
if ok {
|
if ok {
|
||||||
designateInvoker.InvokeAndCheck(t, func(t *testing.T, stack []stackitem.Item) {
|
designateInvoker.InvokeAndCheck(t, func(t testing.TB, stack []stackitem.Item) {
|
||||||
require.Equal(t, 1, len(stack))
|
require.Equal(t, 1, len(stack))
|
||||||
arr := stack[0].Value().([]stackitem.Item)
|
arr := stack[0].Value().([]stackitem.Item)
|
||||||
require.Equal(t, len(res), len(arr))
|
require.Equal(t, len(res), len(arr))
|
||||||
|
|
|
@ -82,7 +82,7 @@ func TestLedger_GetTransactionFromBlock(t *testing.T) {
|
||||||
ledgerInvoker.Invoke(t, e.Chain.BlockHeight(), "currentIndex") // Adds a block.
|
ledgerInvoker.Invoke(t, e.Chain.BlockHeight(), "currentIndex") // Adds a block.
|
||||||
b := e.GetBlockByIndex(t, int(e.Chain.BlockHeight()))
|
b := e.GetBlockByIndex(t, int(e.Chain.BlockHeight()))
|
||||||
|
|
||||||
check := func(t *testing.T, stack []stackitem.Item) {
|
check := func(t testing.TB, stack []stackitem.Item) {
|
||||||
require.Equal(t, 1, len(stack))
|
require.Equal(t, 1, len(stack))
|
||||||
actual, ok := stack[0].Value().([]stackitem.Item)
|
actual, ok := stack[0].Value().([]stackitem.Item)
|
||||||
require.True(t, ok)
|
require.True(t, ok)
|
||||||
|
|
|
@ -36,7 +36,7 @@ type Executor struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewExecutor creates new executor instance from provided blockchain and committee.
|
// NewExecutor creates new executor instance from provided blockchain and committee.
|
||||||
func NewExecutor(t *testing.T, bc blockchainer.Blockchainer, validator, committee Signer) *Executor {
|
func NewExecutor(t testing.TB, bc blockchainer.Blockchainer, validator, committee Signer) *Executor {
|
||||||
checkMultiSigner(t, validator)
|
checkMultiSigner(t, validator)
|
||||||
checkMultiSigner(t, committee)
|
checkMultiSigner(t, committee)
|
||||||
|
|
||||||
|
@ -50,28 +50,28 @@ func NewExecutor(t *testing.T, bc blockchainer.Blockchainer, validator, committe
|
||||||
}
|
}
|
||||||
|
|
||||||
// TopBlock returns block with the highest index.
|
// TopBlock returns block with the highest index.
|
||||||
func (e *Executor) TopBlock(t *testing.T) *block.Block {
|
func (e *Executor) TopBlock(t testing.TB) *block.Block {
|
||||||
b, err := e.Chain.GetBlock(e.Chain.GetHeaderHash(int(e.Chain.BlockHeight())))
|
b, err := e.Chain.GetBlock(e.Chain.GetHeaderHash(int(e.Chain.BlockHeight())))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
// NativeHash returns native contract hash by name.
|
// NativeHash returns native contract hash by name.
|
||||||
func (e *Executor) NativeHash(t *testing.T, name string) util.Uint160 {
|
func (e *Executor) NativeHash(t testing.TB, name string) util.Uint160 {
|
||||||
h, err := e.Chain.GetNativeContractScriptHash(name)
|
h, err := e.Chain.GetNativeContractScriptHash(name)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
return h
|
return h
|
||||||
}
|
}
|
||||||
|
|
||||||
// ContractHash returns contract hash by ID.
|
// ContractHash returns contract hash by ID.
|
||||||
func (e *Executor) ContractHash(t *testing.T, id int32) util.Uint160 {
|
func (e *Executor) ContractHash(t testing.TB, id int32) util.Uint160 {
|
||||||
h, err := e.Chain.GetContractScriptHash(id)
|
h, err := e.Chain.GetContractScriptHash(id)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
return h
|
return h
|
||||||
}
|
}
|
||||||
|
|
||||||
// NativeID returns native contract ID by name.
|
// NativeID returns native contract ID by name.
|
||||||
func (e *Executor) NativeID(t *testing.T, name string) int32 {
|
func (e *Executor) NativeID(t testing.TB, name string) int32 {
|
||||||
h := e.NativeHash(t, name)
|
h := e.NativeHash(t, name)
|
||||||
cs := e.Chain.GetContractState(h)
|
cs := e.Chain.GetContractState(h)
|
||||||
require.NotNil(t, cs)
|
require.NotNil(t, cs)
|
||||||
|
@ -79,7 +79,7 @@ func (e *Executor) NativeID(t *testing.T, name string) int32 {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewUnsignedTx creates new unsigned transaction which invokes method of contract with hash.
|
// NewUnsignedTx creates new unsigned transaction which invokes method of contract with hash.
|
||||||
func (e *Executor) NewUnsignedTx(t *testing.T, hash util.Uint160, method string, args ...interface{}) *transaction.Transaction {
|
func (e *Executor) NewUnsignedTx(t testing.TB, hash util.Uint160, method string, args ...interface{}) *transaction.Transaction {
|
||||||
w := io.NewBufBinWriter()
|
w := io.NewBufBinWriter()
|
||||||
emit.AppCall(w.BinWriter, hash, method, callflag.All, args...)
|
emit.AppCall(w.BinWriter, hash, method, callflag.All, args...)
|
||||||
require.NoError(t, w.Err)
|
require.NoError(t, w.Err)
|
||||||
|
@ -93,14 +93,14 @@ func (e *Executor) NewUnsignedTx(t *testing.T, hash util.Uint160, method string,
|
||||||
|
|
||||||
// NewTx creates new transaction which invokes contract method.
|
// NewTx creates new transaction which invokes contract method.
|
||||||
// Transaction is signed with signer.
|
// Transaction is signed with signer.
|
||||||
func (e *Executor) NewTx(t *testing.T, signers []Signer,
|
func (e *Executor) NewTx(t testing.TB, signers []Signer,
|
||||||
hash util.Uint160, method string, args ...interface{}) *transaction.Transaction {
|
hash util.Uint160, method string, args ...interface{}) *transaction.Transaction {
|
||||||
tx := e.NewUnsignedTx(t, hash, method, args...)
|
tx := e.NewUnsignedTx(t, hash, method, args...)
|
||||||
return e.SignTx(t, tx, -1, signers...)
|
return e.SignTx(t, tx, -1, signers...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SignTx signs a transaction using provided signers.
|
// SignTx signs a transaction using provided signers.
|
||||||
func (e *Executor) SignTx(t *testing.T, tx *transaction.Transaction, sysFee int64, signers ...Signer) *transaction.Transaction {
|
func (e *Executor) SignTx(t testing.TB, tx *transaction.Transaction, sysFee int64, signers ...Signer) *transaction.Transaction {
|
||||||
for _, acc := range signers {
|
for _, acc := range signers {
|
||||||
tx.Signers = append(tx.Signers, transaction.Signer{
|
tx.Signers = append(tx.Signers, transaction.Signer{
|
||||||
Account: acc.ScriptHash(),
|
Account: acc.ScriptHash(),
|
||||||
|
@ -118,7 +118,7 @@ func (e *Executor) SignTx(t *testing.T, tx *transaction.Transaction, sysFee int6
|
||||||
|
|
||||||
// NewAccount returns new signer holding 100.0 GAS (or given amount is specified).
|
// 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.
|
// This method advances the chain by one block with a transfer transaction.
|
||||||
func (e *Executor) NewAccount(t *testing.T, expectedGASBalance ...int64) Signer {
|
func (e *Executor) NewAccount(t testing.TB, expectedGASBalance ...int64) Signer {
|
||||||
acc, err := wallet.NewAccount()
|
acc, err := wallet.NewAccount()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
@ -138,7 +138,7 @@ func (e *Executor) NewAccount(t *testing.T, expectedGASBalance ...int64) Signer
|
||||||
// precalculated contract hash matches the actual one.
|
// precalculated contract hash matches the actual one.
|
||||||
// data is an optional argument to `_deploy`.
|
// data is an optional argument to `_deploy`.
|
||||||
// Returns hash of the deploy transaction.
|
// Returns hash of the deploy transaction.
|
||||||
func (e *Executor) DeployContract(t *testing.T, c *Contract, data interface{}) util.Uint256 {
|
func (e *Executor) DeployContract(t testing.TB, c *Contract, data interface{}) util.Uint256 {
|
||||||
return e.DeployContractBy(t, e.Validator, c, data)
|
return e.DeployContractBy(t, e.Validator, c, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,7 +146,7 @@ func (e *Executor) DeployContract(t *testing.T, c *Contract, data interface{}) u
|
||||||
// It also checks that precalculated contract hash matches the actual one.
|
// It also checks that precalculated contract hash matches the actual one.
|
||||||
// data is an optional argument to `_deploy`.
|
// data is an optional argument to `_deploy`.
|
||||||
// Returns hash of the deploy transaction.
|
// Returns hash of the deploy transaction.
|
||||||
func (e *Executor) DeployContractBy(t *testing.T, signer Signer, c *Contract, data interface{}) util.Uint256 {
|
func (e *Executor) DeployContractBy(t testing.TB, signer Signer, c *Contract, data interface{}) util.Uint256 {
|
||||||
tx := NewDeployTxBy(t, e.Chain, signer, c, data)
|
tx := NewDeployTxBy(t, e.Chain, signer, c, data)
|
||||||
e.AddNewBlock(t, tx)
|
e.AddNewBlock(t, tx)
|
||||||
e.CheckHalt(t, tx.Hash())
|
e.CheckHalt(t, tx.Hash())
|
||||||
|
@ -165,7 +165,7 @@ func (e *Executor) DeployContractBy(t *testing.T, signer Signer, c *Contract, da
|
||||||
|
|
||||||
// DeployContractCheckFAULT compiles and deploys contract to bc using validator
|
// DeployContractCheckFAULT compiles and deploys contract to bc using validator
|
||||||
// account. It checks that deploy transaction FAULTed with the specified error.
|
// account. It checks that deploy transaction FAULTed with the specified error.
|
||||||
func (e *Executor) DeployContractCheckFAULT(t *testing.T, c *Contract, data interface{}, errMessage string) {
|
func (e *Executor) DeployContractCheckFAULT(t testing.TB, c *Contract, data interface{}, errMessage string) {
|
||||||
tx := e.NewDeployTx(t, e.Chain, c, data)
|
tx := e.NewDeployTx(t, e.Chain, c, data)
|
||||||
e.AddNewBlock(t, tx)
|
e.AddNewBlock(t, tx)
|
||||||
e.CheckFault(t, tx.Hash(), errMessage)
|
e.CheckFault(t, tx.Hash(), errMessage)
|
||||||
|
@ -173,7 +173,7 @@ func (e *Executor) DeployContractCheckFAULT(t *testing.T, c *Contract, data inte
|
||||||
|
|
||||||
// InvokeScript adds transaction with the specified script to the chain and
|
// InvokeScript adds transaction with the specified script to the chain and
|
||||||
// returns its hash. It does no faults check.
|
// returns its hash. It does no faults check.
|
||||||
func (e *Executor) InvokeScript(t *testing.T, script []byte, signers []Signer) util.Uint256 {
|
func (e *Executor) InvokeScript(t testing.TB, script []byte, signers []Signer) util.Uint256 {
|
||||||
tx := transaction.New(script, 0)
|
tx := transaction.New(script, 0)
|
||||||
tx.Nonce = Nonce()
|
tx.Nonce = Nonce()
|
||||||
tx.ValidUntilBlock = e.Chain.BlockHeight() + 1
|
tx.ValidUntilBlock = e.Chain.BlockHeight() + 1
|
||||||
|
@ -184,20 +184,20 @@ func (e *Executor) InvokeScript(t *testing.T, script []byte, signers []Signer) u
|
||||||
|
|
||||||
// InvokeScriptCheckHALT adds transaction with the specified script to the chain
|
// InvokeScriptCheckHALT adds transaction with the specified script to the chain
|
||||||
// and checks it's HALTed with the specified items on stack.
|
// and checks it's HALTed with the specified items on stack.
|
||||||
func (e *Executor) InvokeScriptCheckHALT(t *testing.T, script []byte, signers []Signer, stack ...stackitem.Item) {
|
func (e *Executor) InvokeScriptCheckHALT(t testing.TB, script []byte, signers []Signer, stack ...stackitem.Item) {
|
||||||
hash := e.InvokeScript(t, script, signers)
|
hash := e.InvokeScript(t, script, signers)
|
||||||
e.CheckHalt(t, hash, stack...)
|
e.CheckHalt(t, hash, stack...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// InvokeScriptCheckFAULT adds transaction with the specified script to the
|
// InvokeScriptCheckFAULT adds transaction with the specified script to the
|
||||||
// chain and checks it's FAULTed with the specified error.
|
// chain and checks it's FAULTed with the specified error.
|
||||||
func (e *Executor) InvokeScriptCheckFAULT(t *testing.T, script []byte, signers []Signer, errMessage string) {
|
func (e *Executor) InvokeScriptCheckFAULT(t testing.TB, script []byte, signers []Signer, errMessage string) {
|
||||||
hash := e.InvokeScript(t, script, signers)
|
hash := e.InvokeScript(t, script, signers)
|
||||||
e.CheckFault(t, hash, errMessage)
|
e.CheckFault(t, hash, errMessage)
|
||||||
}
|
}
|
||||||
|
|
||||||
// CheckHalt checks that transaction persisted with HALT state.
|
// CheckHalt checks that transaction persisted with HALT state.
|
||||||
func (e *Executor) CheckHalt(t *testing.T, h util.Uint256, stack ...stackitem.Item) *state.AppExecResult {
|
func (e *Executor) CheckHalt(t testing.TB, h util.Uint256, stack ...stackitem.Item) *state.AppExecResult {
|
||||||
aer, err := e.Chain.GetAppExecResults(h, trigger.Application)
|
aer, err := e.Chain.GetAppExecResults(h, trigger.Application)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, vm.HaltState, aer[0].VMState, aer[0].FaultException)
|
require.Equal(t, vm.HaltState, aer[0].VMState, aer[0].FaultException)
|
||||||
|
@ -209,7 +209,7 @@ func (e *Executor) CheckHalt(t *testing.T, h util.Uint256, stack ...stackitem.It
|
||||||
|
|
||||||
// CheckFault checks that transaction persisted with FAULT state.
|
// CheckFault checks that transaction persisted with FAULT state.
|
||||||
// Raised exception is also checked to contain s as a substring.
|
// Raised exception is also checked to contain s as a substring.
|
||||||
func (e *Executor) CheckFault(t *testing.T, h util.Uint256, s string) {
|
func (e *Executor) CheckFault(t testing.TB, h util.Uint256, s string) {
|
||||||
aer, err := e.Chain.GetAppExecResults(h, trigger.Application)
|
aer, err := e.Chain.GetAppExecResults(h, trigger.Application)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, vm.FaultState, aer[0].VMState)
|
require.Equal(t, vm.FaultState, aer[0].VMState)
|
||||||
|
@ -219,7 +219,7 @@ func (e *Executor) CheckFault(t *testing.T, h util.Uint256, s string) {
|
||||||
|
|
||||||
// CheckTxNotificationEvent checks that specified event was emitted at the specified position
|
// CheckTxNotificationEvent checks that specified event was emitted at the specified position
|
||||||
// during transaction script execution. Negative index corresponds to backwards enumeration.
|
// during transaction script execution. Negative index corresponds to backwards enumeration.
|
||||||
func (e *Executor) CheckTxNotificationEvent(t *testing.T, h util.Uint256, index int, expected state.NotificationEvent) {
|
func (e *Executor) CheckTxNotificationEvent(t testing.TB, h util.Uint256, index int, expected state.NotificationEvent) {
|
||||||
aer, err := e.Chain.GetAppExecResults(h, trigger.Application)
|
aer, err := e.Chain.GetAppExecResults(h, trigger.Application)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
l := len(aer[0].Events)
|
l := len(aer[0].Events)
|
||||||
|
@ -231,24 +231,24 @@ func (e *Executor) CheckTxNotificationEvent(t *testing.T, h util.Uint256, index
|
||||||
}
|
}
|
||||||
|
|
||||||
// CheckGASBalance ensures that provided account owns specified amount of GAS.
|
// CheckGASBalance ensures that provided account owns specified amount of GAS.
|
||||||
func (e *Executor) CheckGASBalance(t *testing.T, acc util.Uint160, expected *big.Int) {
|
func (e *Executor) CheckGASBalance(t testing.TB, acc util.Uint160, expected *big.Int) {
|
||||||
actual := e.Chain.GetUtilityTokenBalance(acc)
|
actual := e.Chain.GetUtilityTokenBalance(acc)
|
||||||
require.Equal(t, expected, actual, fmt.Errorf("invalid GAS balance: expected %s, got %s", expected.String(), actual.String()))
|
require.Equal(t, expected, actual, fmt.Errorf("invalid GAS balance: expected %s, got %s", expected.String(), actual.String()))
|
||||||
}
|
}
|
||||||
|
|
||||||
// EnsureGASBalance ensures that provided account owns amount of GAS that satisfies provided condition.
|
// EnsureGASBalance ensures that provided account owns amount of GAS that satisfies provided condition.
|
||||||
func (e *Executor) EnsureGASBalance(t *testing.T, acc util.Uint160, isOk func(balance *big.Int) bool) {
|
func (e *Executor) EnsureGASBalance(t testing.TB, acc util.Uint160, isOk func(balance *big.Int) bool) {
|
||||||
actual := e.Chain.GetUtilityTokenBalance(acc)
|
actual := e.Chain.GetUtilityTokenBalance(acc)
|
||||||
require.True(t, isOk(actual), fmt.Errorf("invalid GAS balance: got %s, condition is not satisfied", actual.String()))
|
require.True(t, isOk(actual), fmt.Errorf("invalid GAS balance: got %s, condition is not satisfied", actual.String()))
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewDeployTx returns new deployment tx for contract signed by committee.
|
// NewDeployTx returns new deployment tx for contract signed by committee.
|
||||||
func (e *Executor) NewDeployTx(t *testing.T, bc blockchainer.Blockchainer, c *Contract, data interface{}) *transaction.Transaction {
|
func (e *Executor) NewDeployTx(t testing.TB, bc blockchainer.Blockchainer, c *Contract, data interface{}) *transaction.Transaction {
|
||||||
return NewDeployTxBy(t, bc, e.Validator, c, data)
|
return NewDeployTxBy(t, bc, e.Validator, c, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewDeployTxBy returns new deployment tx for contract signed by the specified signer.
|
// NewDeployTxBy returns new deployment tx for contract signed by the specified signer.
|
||||||
func NewDeployTxBy(t *testing.T, bc blockchainer.Blockchainer, signer Signer, c *Contract, data interface{}) *transaction.Transaction {
|
func NewDeployTxBy(t testing.TB, bc blockchainer.Blockchainer, signer Signer, c *Contract, data interface{}) *transaction.Transaction {
|
||||||
rawManifest, err := json.Marshal(c.Manifest)
|
rawManifest, err := json.Marshal(c.Manifest)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
@ -292,7 +292,7 @@ func addNetworkFee(bc blockchainer.Blockchainer, tx *transaction.Transaction, si
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewUnsignedBlock creates new unsigned block from txs.
|
// NewUnsignedBlock creates new unsigned block from txs.
|
||||||
func (e *Executor) NewUnsignedBlock(t *testing.T, txs ...*transaction.Transaction) *block.Block {
|
func (e *Executor) NewUnsignedBlock(t testing.TB, txs ...*transaction.Transaction) *block.Block {
|
||||||
lastBlock := e.TopBlock(t)
|
lastBlock := e.TopBlock(t)
|
||||||
b := &block.Block{
|
b := &block.Block{
|
||||||
Header: block.Header{
|
Header: block.Header{
|
||||||
|
@ -315,7 +315,7 @@ func (e *Executor) NewUnsignedBlock(t *testing.T, txs ...*transaction.Transactio
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddNewBlock creates a new block from provided transactions and adds it on bc.
|
// AddNewBlock creates a new block from provided transactions and adds it on bc.
|
||||||
func (e *Executor) AddNewBlock(t *testing.T, txs ...*transaction.Transaction) *block.Block {
|
func (e *Executor) AddNewBlock(t testing.TB, txs ...*transaction.Transaction) *block.Block {
|
||||||
b := e.NewUnsignedBlock(t, txs...)
|
b := e.NewUnsignedBlock(t, txs...)
|
||||||
e.SignBlock(b)
|
e.SignBlock(b)
|
||||||
require.NoError(t, e.Chain.AddBlock(b))
|
require.NoError(t, e.Chain.AddBlock(b))
|
||||||
|
@ -323,7 +323,7 @@ func (e *Executor) AddNewBlock(t *testing.T, txs ...*transaction.Transaction) *b
|
||||||
}
|
}
|
||||||
|
|
||||||
// GenerateNewBlocks adds specified number of empty blocks to the chain.
|
// GenerateNewBlocks adds specified number of empty blocks to the chain.
|
||||||
func (e *Executor) GenerateNewBlocks(t *testing.T, count int) {
|
func (e *Executor) GenerateNewBlocks(t testing.TB, count int) {
|
||||||
for i := 0; i < count; i++ {
|
for i := 0; i < count; i++ {
|
||||||
e.AddNewBlock(t)
|
e.AddNewBlock(t)
|
||||||
}
|
}
|
||||||
|
@ -337,7 +337,7 @@ func (e *Executor) SignBlock(b *block.Block) *block.Block {
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddBlockCheckHalt is a convenient wrapper over AddBlock and CheckHalt.
|
// AddBlockCheckHalt is a convenient wrapper over AddBlock and CheckHalt.
|
||||||
func (e *Executor) AddBlockCheckHalt(t *testing.T, txs ...*transaction.Transaction) *block.Block {
|
func (e *Executor) AddBlockCheckHalt(t testing.TB, txs ...*transaction.Transaction) *block.Block {
|
||||||
b := e.AddNewBlock(t, txs...)
|
b := e.AddNewBlock(t, txs...)
|
||||||
for _, tx := range txs {
|
for _, tx := range txs {
|
||||||
e.CheckHalt(t, tx.Hash())
|
e.CheckHalt(t, tx.Hash())
|
||||||
|
@ -370,14 +370,14 @@ func TestInvoke(bc blockchainer.Blockchainer, tx *transaction.Transaction) (*vm.
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetTransaction returns transaction and its height by the specified hash.
|
// GetTransaction returns transaction and its height by the specified hash.
|
||||||
func (e *Executor) GetTransaction(t *testing.T, h util.Uint256) (*transaction.Transaction, uint32) {
|
func (e *Executor) GetTransaction(t testing.TB, h util.Uint256) (*transaction.Transaction, uint32) {
|
||||||
tx, height, err := e.Chain.GetTransaction(h)
|
tx, height, err := e.Chain.GetTransaction(h)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
return tx, height
|
return tx, height
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetBlockByIndex returns block by the specified index.
|
// GetBlockByIndex returns block by the specified index.
|
||||||
func (e *Executor) GetBlockByIndex(t *testing.T, idx int) *block.Block {
|
func (e *Executor) GetBlockByIndex(t testing.TB, idx int) *block.Block {
|
||||||
h := e.Chain.GetHeaderHash(idx)
|
h := e.Chain.GetHeaderHash(idx)
|
||||||
require.NotEmpty(t, h)
|
require.NotEmpty(t, h)
|
||||||
b, err := e.Chain.GetBlock(h)
|
b, err := e.Chain.GetBlock(h)
|
||||||
|
@ -386,7 +386,7 @@ func (e *Executor) GetBlockByIndex(t *testing.T, idx int) *block.Block {
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetTxExecResult returns application execution results for the specified transaction.
|
// GetTxExecResult returns application execution results for the specified transaction.
|
||||||
func (e *Executor) GetTxExecResult(t *testing.T, h util.Uint256) *state.AppExecResult {
|
func (e *Executor) GetTxExecResult(t testing.TB, h util.Uint256) *state.AppExecResult {
|
||||||
aer, err := e.Chain.GetAppExecResults(h, trigger.Application)
|
aer, err := e.Chain.GetAppExecResults(h, trigger.Application)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, 1, len(aer))
|
require.Equal(t, 1, len(aer))
|
||||||
|
|
|
@ -121,13 +121,13 @@ func init() {
|
||||||
// this package. MemoryStore is used as the backend storage, so all of the chain
|
// this package. MemoryStore is used as the backend storage, so all of the chain
|
||||||
// contents is always in RAM. The Signer returned is validator (and committee at
|
// contents is always in RAM. The Signer returned is validator (and committee at
|
||||||
// the same time).
|
// the same time).
|
||||||
func NewSingle(t *testing.T) (*core.Blockchain, neotest.Signer) {
|
func NewSingle(t testing.TB) (*core.Blockchain, neotest.Signer) {
|
||||||
return NewSingleWithCustomConfig(t, nil)
|
return NewSingleWithCustomConfig(t, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewSingleWithCustomConfig is similar to NewSingle, but allows to override the
|
// NewSingleWithCustomConfig is similar to NewSingle, but allows to override the
|
||||||
// default configuration.
|
// default configuration.
|
||||||
func NewSingleWithCustomConfig(t *testing.T, f func(*config.ProtocolConfiguration)) (*core.Blockchain, neotest.Signer) {
|
func NewSingleWithCustomConfig(t testing.TB, f func(*config.ProtocolConfiguration)) (*core.Blockchain, neotest.Signer) {
|
||||||
st := storage.NewMemoryStore()
|
st := storage.NewMemoryStore()
|
||||||
return NewSingleWithCustomConfigAndStore(t, f, st, true)
|
return NewSingleWithCustomConfigAndStore(t, f, st, true)
|
||||||
}
|
}
|
||||||
|
@ -137,7 +137,7 @@ func NewSingleWithCustomConfig(t *testing.T, f func(*config.ProtocolConfiguratio
|
||||||
// Run method is called on the Blockchain instance, if not then it's caller's
|
// Run method is called on the Blockchain instance, if not then it's caller's
|
||||||
// responsibility to do that before using the chain and its caller's responsibility
|
// responsibility to do that before using the chain and its caller's responsibility
|
||||||
// also to properly Close the chain when done.
|
// also to properly Close the chain when done.
|
||||||
func NewSingleWithCustomConfigAndStore(t *testing.T, f func(cfg *config.ProtocolConfiguration), st storage.Store, run bool) (*core.Blockchain, neotest.Signer) {
|
func NewSingleWithCustomConfigAndStore(t testing.TB, f func(cfg *config.ProtocolConfiguration), st storage.Store, run bool) (*core.Blockchain, neotest.Signer) {
|
||||||
protoCfg := config.ProtocolConfiguration{
|
protoCfg := config.ProtocolConfiguration{
|
||||||
Magic: netmode.UnitTestNet,
|
Magic: netmode.UnitTestNet,
|
||||||
MaxTraceableBlocks: MaxTraceableBlocks,
|
MaxTraceableBlocks: MaxTraceableBlocks,
|
||||||
|
@ -163,20 +163,22 @@ func NewSingleWithCustomConfigAndStore(t *testing.T, f func(cfg *config.Protocol
|
||||||
// NewMulti creates new blockchain instance with four validators and six
|
// NewMulti creates new blockchain instance with four validators and six
|
||||||
// committee members, otherwise not differring much from NewSingle. The
|
// committee members, otherwise not differring much from NewSingle. The
|
||||||
// second value returned contains validators Signer, the third -- committee one.
|
// second value returned contains validators Signer, the third -- committee one.
|
||||||
func NewMulti(t *testing.T) (*core.Blockchain, neotest.Signer, neotest.Signer) {
|
func NewMulti(t testing.TB) (*core.Blockchain, neotest.Signer, neotest.Signer) {
|
||||||
return NewMultiWithCustomConfig(t, nil)
|
return NewMultiWithCustomConfig(t, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewMultiWithCustomConfig is similar to NewMulti except it allows to override the
|
// NewMultiWithCustomConfig is similar to NewMulti except it allows to override the
|
||||||
// default configuration.
|
// default configuration.
|
||||||
func NewMultiWithCustomConfig(t *testing.T, f func(*config.ProtocolConfiguration)) (*core.Blockchain, neotest.Signer, neotest.Signer) {
|
func NewMultiWithCustomConfig(t testing.TB, f func(*config.ProtocolConfiguration)) (*core.Blockchain, neotest.Signer, neotest.Signer) {
|
||||||
return NewMultiWithCustomConfigAndStore(t, f, nil, true)
|
return NewMultiWithCustomConfigAndStore(t, f, nil, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewMultiWithCustomConfigAndStore creates new blockchain instance with custom
|
// NewMultiWithCustomConfigAndStore is similar to NewMultiWithCustomConfig, but
|
||||||
// protocol configuration, custom storage, 4 validators and 6 committee members.
|
// also allows to override backend Store being used. The last parameter controls if
|
||||||
// Second return value is for validator signer, third -- for committee.
|
// Run method is called on the Blockchain instance, if not then it's caller's
|
||||||
func NewMultiWithCustomConfigAndStore(t *testing.T, f func(*config.ProtocolConfiguration), st storage.Store, run bool) (*core.Blockchain, neotest.Signer, neotest.Signer) {
|
// responsibility to do that before using the chain and its caller's responsibility
|
||||||
|
// also to properly Close the chain when done.
|
||||||
|
func NewMultiWithCustomConfigAndStore(t testing.TB, f func(*config.ProtocolConfiguration), st storage.Store, run bool) (*core.Blockchain, neotest.Signer, neotest.Signer) {
|
||||||
bc, validator, committee, err := NewMultiWithCustomConfigAndStoreNoCheck(t, f, st)
|
bc, validator, committee, err := NewMultiWithCustomConfigAndStoreNoCheck(t, f, st)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
if run {
|
if run {
|
||||||
|
@ -186,12 +188,9 @@ func NewMultiWithCustomConfigAndStore(t *testing.T, f func(*config.ProtocolConfi
|
||||||
return bc, validator, committee
|
return bc, validator, committee
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewMultiWithCustomConfigAndStoreNoCheck creates new blockchain instance with
|
// NewMultiWithCustomConfigAndStoreNoCheck is similar to NewMultiWithCustomConfig,
|
||||||
// custom protocol configuration, custom store, 4 validators and 6 committee
|
// but do not perform Blockchain run and do not check Blockchain constructor error.
|
||||||
// members. Second return value is for validator signer, third -- for committee.
|
func NewMultiWithCustomConfigAndStoreNoCheck(t testing.TB, f func(*config.ProtocolConfiguration), st storage.Store) (*core.Blockchain, neotest.Signer, neotest.Signer, error) {
|
||||||
// The resulting blockchain instance is not running and constructor error is
|
|
||||||
// returned.
|
|
||||||
func NewMultiWithCustomConfigAndStoreNoCheck(t *testing.T, f func(*config.ProtocolConfiguration), st storage.Store) (*core.Blockchain, neotest.Signer, neotest.Signer, error) {
|
|
||||||
protoCfg := config.ProtocolConfiguration{
|
protoCfg := config.ProtocolConfiguration{
|
||||||
Magic: netmode.UnitTestNet,
|
Magic: netmode.UnitTestNet,
|
||||||
MaxTraceableBlocks: MaxTraceableBlocks,
|
MaxTraceableBlocks: MaxTraceableBlocks,
|
||||||
|
|
|
@ -47,7 +47,7 @@ func (e *Executor) ValidatorInvoker(h util.Uint160) *ContractInvoker {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestInvoke creates test VM and invokes method with args.
|
// TestInvoke creates test VM and invokes method with args.
|
||||||
func (c *ContractInvoker) TestInvoke(t *testing.T, method string, args ...interface{}) (*vm.Stack, error) {
|
func (c *ContractInvoker) TestInvoke(t testing.TB, method string, args ...interface{}) (*vm.Stack, error) {
|
||||||
tx := c.PrepareInvokeNoSign(t, method, args...)
|
tx := c.PrepareInvokeNoSign(t, method, args...)
|
||||||
b := c.NewUnsignedBlock(t, tx)
|
b := c.NewUnsignedBlock(t, tx)
|
||||||
ic := c.Chain.GetTestVM(trigger.Application, tx, b)
|
ic := c.Chain.GetTestVM(trigger.Application, tx, b)
|
||||||
|
@ -66,18 +66,18 @@ func (c *ContractInvoker) WithSigners(signers ...Signer) *ContractInvoker {
|
||||||
}
|
}
|
||||||
|
|
||||||
// PrepareInvoke creates new invocation transaction.
|
// PrepareInvoke creates new invocation transaction.
|
||||||
func (c *ContractInvoker) PrepareInvoke(t *testing.T, method string, args ...interface{}) *transaction.Transaction {
|
func (c *ContractInvoker) PrepareInvoke(t testing.TB, method string, args ...interface{}) *transaction.Transaction {
|
||||||
return c.Executor.NewTx(t, c.Signers, c.Hash, method, args...)
|
return c.Executor.NewTx(t, c.Signers, c.Hash, method, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// PrepareInvokeNoSign creates new unsigned invocation transaction.
|
// PrepareInvokeNoSign creates new unsigned invocation transaction.
|
||||||
func (c *ContractInvoker) PrepareInvokeNoSign(t *testing.T, method string, args ...interface{}) *transaction.Transaction {
|
func (c *ContractInvoker) PrepareInvokeNoSign(t testing.TB, method string, args ...interface{}) *transaction.Transaction {
|
||||||
return c.Executor.NewUnsignedTx(t, c.Hash, method, args...)
|
return c.Executor.NewUnsignedTx(t, c.Hash, method, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Invoke invokes method with args, persists transaction and checks the result.
|
// Invoke invokes method with args, persists transaction and checks the result.
|
||||||
// Returns transaction hash.
|
// Returns transaction hash.
|
||||||
func (c *ContractInvoker) Invoke(t *testing.T, result interface{}, method string, args ...interface{}) util.Uint256 {
|
func (c *ContractInvoker) Invoke(t testing.TB, result interface{}, method string, args ...interface{}) util.Uint256 {
|
||||||
tx := c.PrepareInvoke(t, method, args...)
|
tx := c.PrepareInvoke(t, method, args...)
|
||||||
c.AddNewBlock(t, tx)
|
c.AddNewBlock(t, tx)
|
||||||
c.CheckHalt(t, tx.Hash(), stackitem.Make(result))
|
c.CheckHalt(t, tx.Hash(), stackitem.Make(result))
|
||||||
|
@ -86,7 +86,7 @@ func (c *ContractInvoker) Invoke(t *testing.T, result interface{}, method string
|
||||||
|
|
||||||
// InvokeAndCheck invokes method with args, persists transaction and checks the result
|
// InvokeAndCheck invokes method with args, persists transaction and checks the result
|
||||||
// using provided function. Returns transaction hash.
|
// using provided function. Returns transaction hash.
|
||||||
func (c *ContractInvoker) InvokeAndCheck(t *testing.T, checkResult func(t *testing.T, stack []stackitem.Item), method string, args ...interface{}) util.Uint256 {
|
func (c *ContractInvoker) InvokeAndCheck(t testing.TB, checkResult func(t testing.TB, stack []stackitem.Item), method string, args ...interface{}) util.Uint256 {
|
||||||
tx := c.PrepareInvoke(t, method, args...)
|
tx := c.PrepareInvoke(t, method, args...)
|
||||||
c.AddNewBlock(t, tx)
|
c.AddNewBlock(t, tx)
|
||||||
aer, err := c.Chain.GetAppExecResults(tx.Hash(), trigger.Application)
|
aer, err := c.Chain.GetAppExecResults(tx.Hash(), trigger.Application)
|
||||||
|
@ -99,7 +99,7 @@ func (c *ContractInvoker) InvokeAndCheck(t *testing.T, checkResult func(t *testi
|
||||||
}
|
}
|
||||||
|
|
||||||
// InvokeWithFeeFail is like InvokeFail but sets custom system fee for the transaction.
|
// InvokeWithFeeFail is like InvokeFail but sets custom system fee for the transaction.
|
||||||
func (c *ContractInvoker) InvokeWithFeeFail(t *testing.T, message string, sysFee int64, method string, args ...interface{}) util.Uint256 {
|
func (c *ContractInvoker) InvokeWithFeeFail(t testing.TB, message string, sysFee int64, method string, args ...interface{}) util.Uint256 {
|
||||||
tx := c.PrepareInvokeNoSign(t, method, args...)
|
tx := c.PrepareInvokeNoSign(t, method, args...)
|
||||||
c.Executor.SignTx(t, tx, sysFee, c.Signers...)
|
c.Executor.SignTx(t, tx, sysFee, c.Signers...)
|
||||||
c.AddNewBlock(t, tx)
|
c.AddNewBlock(t, tx)
|
||||||
|
@ -109,7 +109,7 @@ func (c *ContractInvoker) InvokeWithFeeFail(t *testing.T, message string, sysFee
|
||||||
|
|
||||||
// InvokeFail invokes method with args, persists transaction and checks the error message.
|
// InvokeFail invokes method with args, persists transaction and checks the error message.
|
||||||
// Returns transaction hash.
|
// Returns transaction hash.
|
||||||
func (c *ContractInvoker) InvokeFail(t *testing.T, message string, method string, args ...interface{}) {
|
func (c *ContractInvoker) InvokeFail(t testing.TB, message string, method string, args ...interface{}) {
|
||||||
tx := c.PrepareInvoke(t, method, args...)
|
tx := c.PrepareInvoke(t, method, args...)
|
||||||
c.AddNewBlock(t, tx)
|
c.AddNewBlock(t, tx)
|
||||||
c.CheckFault(t, tx.Hash(), message)
|
c.CheckFault(t, tx.Hash(), message)
|
||||||
|
|
|
@ -25,7 +25,7 @@ type Contract struct {
|
||||||
var contracts = make(map[string]*Contract)
|
var contracts = make(map[string]*Contract)
|
||||||
|
|
||||||
// CompileSource compiles contract from reader and returns it's NEF, manifest and hash.
|
// CompileSource compiles contract from reader and returns it's NEF, manifest and hash.
|
||||||
func CompileSource(t *testing.T, sender util.Uint160, src io.Reader, opts *compiler.Options) *Contract {
|
func CompileSource(t testing.TB, sender util.Uint160, src io.Reader, opts *compiler.Options) *Contract {
|
||||||
// nef.NewFile() cares about version a lot.
|
// nef.NewFile() cares about version a lot.
|
||||||
config.Version = "neotest"
|
config.Version = "neotest"
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ func CompileSource(t *testing.T, sender util.Uint160, src io.Reader, opts *compi
|
||||||
}
|
}
|
||||||
|
|
||||||
// CompileFile compiles contract from file and returns it's NEF, manifest and hash.
|
// CompileFile compiles contract from file and returns it's NEF, manifest and hash.
|
||||||
func CompileFile(t *testing.T, sender util.Uint160, srcPath string, configPath string) *Contract {
|
func CompileFile(t testing.TB, sender util.Uint160, srcPath string, configPath string) *Contract {
|
||||||
if c, ok := contracts[srcPath]; ok {
|
if c, ok := contracts[srcPath]; ok {
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
|
@ -162,7 +162,7 @@ func (m multiSigner) Single(n int) SingleSigner {
|
||||||
return NewSingleSigner(wallet.NewAccountFromPrivateKey(m.accounts[n].PrivateKey()))
|
return NewSingleSigner(wallet.NewAccountFromPrivateKey(m.accounts[n].PrivateKey()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkMultiSigner(t *testing.T, s Signer) {
|
func checkMultiSigner(t testing.TB, s Signer) {
|
||||||
ms, ok := s.(multiSigner)
|
ms, ok := s.(multiSigner)
|
||||||
require.True(t, ok, "expected to be a multi-signer")
|
require.True(t, ok, "expected to be a multi-signer")
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue