2022-10-05 06:44:10 +00:00
|
|
|
/*
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
package testcli
|
2020-08-29 11:41:33 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"errors"
|
2022-04-26 09:32:06 +00:00
|
|
|
"fmt"
|
2020-08-29 11:41:33 +00:00
|
|
|
"io"
|
2020-11-13 13:54:38 +00:00
|
|
|
"math"
|
2022-10-05 06:44:10 +00:00
|
|
|
"path/filepath"
|
2020-09-01 13:24:01 +00:00
|
|
|
"strings"
|
2022-01-31 13:20:14 +00:00
|
|
|
"sync"
|
2020-08-29 11:41:33 +00:00
|
|
|
"testing"
|
2020-08-31 09:42:42 +00:00
|
|
|
"time"
|
2020-08-29 11:41:33 +00:00
|
|
|
|
2022-10-05 06:44:10 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/cli/app"
|
2020-08-29 11:41:33 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/cli/input"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/config"
|
2022-01-12 20:04:07 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/consensus"
|
2020-08-29 11:41:33 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/storage"
|
2020-08-31 09:42:42 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
2020-09-01 11:55:10 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
2020-08-29 11:41:33 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/network"
|
2022-07-21 13:21:44 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/services/rpcsrv"
|
2020-11-11 15:43:28 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger"
|
2020-08-31 09:42:42 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
2022-07-08 14:28:29 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/vm/vmstate"
|
2020-08-29 11:41:33 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2024-07-09 18:24:39 +00:00
|
|
|
"github.com/urfave/cli/v2"
|
2020-08-29 11:41:33 +00:00
|
|
|
"go.uber.org/zap"
|
|
|
|
"go.uber.org/zap/zaptest"
|
2021-02-10 08:53:01 +00:00
|
|
|
"golang.org/x/term"
|
2020-08-29 11:41:33 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2022-10-05 06:44:10 +00:00
|
|
|
ValidatorWIF = "KxyjQ8eUa4FHt3Gvioyt1Wz29cTUrE4eTqX3yFSk1YFCsPL8uNsY"
|
|
|
|
ValidatorAddr = "NfgHwwTi3wHAS8aFAN243C5vGbkYDpqLHP"
|
|
|
|
MultisigAddr = "NVTiAjNgagDkTr5HTzDmQP9kPwPHN5BgVq"
|
2020-08-29 11:41:33 +00:00
|
|
|
|
2022-10-05 06:44:10 +00:00
|
|
|
TestWalletPath = "../testdata/testwallet.json"
|
|
|
|
TestWalletAccount = "Nfyz4KcsgYepRJw1W5C2uKCi6QWKf7v6gG"
|
2021-08-02 08:19:30 +00:00
|
|
|
|
2024-02-29 20:48:10 +00:00
|
|
|
TestWalletMultiPath = "../testdata/testwallet_multi.json"
|
|
|
|
TestWalletMultiAccount1 = "NgHcPxgEKZQV4QBedzyASJrgiANhJqBVLw"
|
|
|
|
TestWalletMultiAccount2 = "NLvHRfKAifjio2z9HiwLo9ZnpRPHUbAHgH"
|
|
|
|
TestWalletMultiAccount3 = "NcDfG8foJx79XSihcDDrx1df7cHAoJBfXj"
|
|
|
|
|
2022-10-05 06:44:10 +00:00
|
|
|
ValidatorWallet = "../testdata/wallet1_solo.json"
|
|
|
|
ValidatorPass = "one"
|
2020-08-29 11:41:33 +00:00
|
|
|
)
|
|
|
|
|
2020-09-01 11:55:10 +00:00
|
|
|
var (
|
2022-10-05 06:44:10 +00:00
|
|
|
ValidatorHash, _ = address.StringToUint160(ValidatorAddr)
|
|
|
|
ValidatorPriv, _ = keys.NewPrivateKeyFromWIF(ValidatorWIF)
|
2024-02-29 20:48:10 +00:00
|
|
|
|
|
|
|
TestWalletMultiAccount1Hash, _ = address.StringToUint160(TestWalletMultiAccount1)
|
|
|
|
TestWalletMultiAccount2Hash, _ = address.StringToUint160(TestWalletMultiAccount2)
|
|
|
|
TestWalletMultiAccount3Hash, _ = address.StringToUint160(TestWalletMultiAccount3)
|
2020-09-01 11:55:10 +00:00
|
|
|
)
|
2020-08-29 11:41:33 +00:00
|
|
|
|
2022-10-05 06:44:10 +00:00
|
|
|
// Executor represents context for a test instance.
|
2020-08-29 11:41:33 +00:00
|
|
|
// It can be safely used in multiple tests, but not in parallel.
|
2022-10-05 06:44:10 +00:00
|
|
|
type Executor struct {
|
2020-08-29 11:41:33 +00:00
|
|
|
// 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).
|
2022-07-21 13:21:44 +00:00
|
|
|
RPC *rpcsrv.Server
|
2020-08-29 11:41:33 +00:00
|
|
|
// NetSrv is a network server (can be empty).
|
|
|
|
NetSrv *network.Server
|
|
|
|
// Out contains command output.
|
2022-01-31 13:20:14 +00:00
|
|
|
Out *ConcurrentBuffer
|
2020-08-29 11:41:33 +00:00
|
|
|
// Err contains command errors.
|
|
|
|
Err *bytes.Buffer
|
2020-08-31 09:42:42 +00:00
|
|
|
// In contains command input.
|
|
|
|
In *bytes.Buffer
|
2020-08-29 11:41:33 +00:00
|
|
|
}
|
|
|
|
|
2022-01-31 13:20:14 +00:00
|
|
|
// ConcurrentBuffer is a wrapper over Buffer with mutex.
|
|
|
|
type ConcurrentBuffer struct {
|
|
|
|
lock sync.RWMutex
|
|
|
|
buf *bytes.Buffer
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewConcurrentBuffer returns new ConcurrentBuffer with underlying buffer initialized.
|
|
|
|
func NewConcurrentBuffer() *ConcurrentBuffer {
|
|
|
|
return &ConcurrentBuffer{
|
|
|
|
buf: bytes.NewBuffer(nil),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write is a concurrent wrapper over the corresponding method of bytes.Buffer.
|
|
|
|
func (w *ConcurrentBuffer) Write(p []byte) (int, error) {
|
|
|
|
w.lock.Lock()
|
|
|
|
defer w.lock.Unlock()
|
|
|
|
|
|
|
|
return w.buf.Write(p)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ReadString is a concurrent wrapper over the corresponding method of bytes.Buffer.
|
|
|
|
func (w *ConcurrentBuffer) ReadString(delim byte) (string, error) {
|
|
|
|
w.lock.RLock()
|
|
|
|
defer w.lock.RUnlock()
|
|
|
|
|
|
|
|
return w.buf.ReadString(delim)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Bytes is a concurrent wrapper over the corresponding method of bytes.Buffer.
|
|
|
|
func (w *ConcurrentBuffer) Bytes() []byte {
|
|
|
|
w.lock.RLock()
|
|
|
|
defer w.lock.RUnlock()
|
|
|
|
|
|
|
|
return w.buf.Bytes()
|
|
|
|
}
|
|
|
|
|
|
|
|
// String is a concurrent wrapper over the corresponding method of bytes.Buffer.
|
|
|
|
func (w *ConcurrentBuffer) String() string {
|
|
|
|
w.lock.RLock()
|
|
|
|
defer w.lock.RUnlock()
|
|
|
|
|
|
|
|
return w.buf.String()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reset is a concurrent wrapper over the corresponding method of bytes.Buffer.
|
|
|
|
func (w *ConcurrentBuffer) Reset() {
|
|
|
|
w.lock.Lock()
|
|
|
|
defer w.lock.Unlock()
|
|
|
|
|
|
|
|
w.buf.Reset()
|
|
|
|
}
|
|
|
|
|
2022-10-05 06:44:10 +00:00
|
|
|
func NewTestChain(t *testing.T, f func(*config.Config), run bool) (*core.Blockchain, *rpcsrv.Server, *network.Server) {
|
|
|
|
configPath := "../../config/protocol.unit_testnet.single.yml"
|
2020-08-29 11:41:33 +00:00
|
|
|
cfg, err := config.LoadFile(configPath)
|
|
|
|
require.NoError(t, err, "could not load config")
|
2020-12-10 11:34:46 +00:00
|
|
|
if f != nil {
|
|
|
|
f(&cfg)
|
|
|
|
}
|
2020-08-29 11:41:33 +00:00
|
|
|
|
|
|
|
memoryStore := storage.NewMemoryStore()
|
|
|
|
logger := zaptest.NewLogger(t)
|
2022-12-06 13:34:38 +00:00
|
|
|
chain, err := core.NewBlockchain(memoryStore, cfg.Blockchain(), logger)
|
2020-08-29 11:41:33 +00:00
|
|
|
require.NoError(t, err, "could not create chain")
|
|
|
|
|
2021-07-16 14:47:40 +00:00
|
|
|
if run {
|
|
|
|
go chain.Run()
|
|
|
|
}
|
2020-08-29 11:41:33 +00:00
|
|
|
|
2022-11-29 14:43:08 +00:00
|
|
|
serverConfig, err := network.NewServerConfig(cfg)
|
|
|
|
require.NoError(t, err)
|
2022-04-26 09:32:06 +00:00
|
|
|
serverConfig.UserAgent = fmt.Sprintf(config.UserAgentFormat, "0.98.3-test")
|
2022-01-12 21:20:03 +00:00
|
|
|
netSrv, err := network.NewServer(serverConfig, chain, chain.GetStateSyncModule(), zap.NewNop())
|
2020-08-29 11:41:33 +00:00
|
|
|
require.NoError(t, err)
|
2022-01-12 20:04:07 +00:00
|
|
|
cons, err := consensus.NewService(consensus.Config{
|
|
|
|
Logger: zap.NewNop(),
|
|
|
|
Broadcast: netSrv.BroadcastExtensible,
|
|
|
|
Chain: chain,
|
2023-03-07 09:06:53 +00:00
|
|
|
BlockQueue: netSrv.GetBlockQueue(),
|
2022-12-06 13:34:38 +00:00
|
|
|
ProtocolConfiguration: cfg.ProtocolConfiguration,
|
2022-01-12 20:04:07 +00:00
|
|
|
RequestTx: netSrv.RequestTx,
|
2022-10-14 18:00:26 +00:00
|
|
|
StopTxFlow: netSrv.StopTxFlow,
|
2022-12-05 15:11:18 +00:00
|
|
|
Wallet: cfg.ApplicationConfiguration.Consensus.UnlockWallet,
|
2022-01-12 20:04:07 +00:00
|
|
|
TimePerBlock: serverConfig.TimePerBlock,
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
2022-07-28 15:30:14 +00:00
|
|
|
netSrv.AddConsensusService(cons, cons.OnPayload, cons.OnTransaction)
|
2024-02-21 15:07:28 +00:00
|
|
|
netSrv.Start()
|
2020-08-29 11:41:33 +00:00
|
|
|
errCh := make(chan error, 2)
|
2022-07-21 13:21:44 +00:00
|
|
|
rpcServer := rpcsrv.New(chain, cfg.ApplicationConfiguration.RPC, netSrv, nil, logger, errCh)
|
2022-04-22 07:49:06 +00:00
|
|
|
rpcServer.Start()
|
2020-08-29 11:41:33 +00:00
|
|
|
|
|
|
|
return chain, &rpcServer, netSrv
|
|
|
|
}
|
|
|
|
|
2022-10-05 06:44:10 +00:00
|
|
|
func NewExecutor(t *testing.T, needChain bool) *Executor {
|
|
|
|
return NewExecutorWithConfig(t, needChain, true, nil)
|
2021-07-16 14:47:40 +00:00
|
|
|
}
|
|
|
|
|
2022-10-05 06:44:10 +00:00
|
|
|
func NewExecutorSuspended(t *testing.T) *Executor {
|
|
|
|
return NewExecutorWithConfig(t, true, false, nil)
|
2020-12-10 11:34:46 +00:00
|
|
|
}
|
|
|
|
|
2022-10-05 06:44:10 +00:00
|
|
|
func NewExecutorWithConfig(t *testing.T, needChain, runChain bool, f func(*config.Config)) *Executor {
|
|
|
|
e := &Executor{
|
|
|
|
CLI: app.New(),
|
2022-01-31 13:20:14 +00:00
|
|
|
Out: NewConcurrentBuffer(),
|
2020-08-29 11:41:33 +00:00
|
|
|
Err: bytes.NewBuffer(nil),
|
2020-08-31 09:42:42 +00:00
|
|
|
In: bytes.NewBuffer(nil),
|
2020-08-29 11:41:33 +00:00
|
|
|
}
|
|
|
|
e.CLI.Writer = e.Out
|
|
|
|
e.CLI.ErrWriter = e.Err
|
|
|
|
if needChain {
|
2022-10-05 06:44:10 +00:00
|
|
|
e.Chain, e.RPC, e.NetSrv = NewTestChain(t, f, runChain)
|
2020-08-29 11:41:33 +00:00
|
|
|
}
|
2021-03-01 11:14:15 +00:00
|
|
|
t.Cleanup(func() {
|
|
|
|
e.Close(t)
|
|
|
|
})
|
2020-08-29 11:41:33 +00:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2022-10-05 06:44:10 +00:00
|
|
|
func (e *Executor) Close(t *testing.T) {
|
2020-08-29 11:41:33 +00:00
|
|
|
input.Terminal = nil
|
|
|
|
if e.RPC != nil {
|
2022-04-22 07:49:06 +00:00
|
|
|
e.RPC.Shutdown()
|
2020-08-29 11:41:33 +00:00
|
|
|
}
|
|
|
|
if e.NetSrv != nil {
|
|
|
|
e.NetSrv.Shutdown()
|
|
|
|
}
|
|
|
|
if e.Chain != nil {
|
|
|
|
e.Chain.Close()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-31 09:42:42 +00:00
|
|
|
// 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.
|
2022-10-05 06:44:10 +00:00
|
|
|
func (e *Executor) GetTransaction(t *testing.T, h util.Uint256) (*transaction.Transaction, uint32) {
|
2020-08-31 09:42:42 +00:00
|
|
|
var tx *transaction.Transaction
|
2020-09-02 08:43:25 +00:00
|
|
|
var height uint32
|
2020-08-31 09:42:42 +00:00
|
|
|
require.Eventually(t, func() bool {
|
|
|
|
var err error
|
|
|
|
tx, height, err = e.Chain.GetTransaction(h)
|
2020-11-13 13:54:38 +00:00
|
|
|
return err == nil && height != math.MaxUint32
|
2020-08-31 09:42:42 +00:00
|
|
|
}, time.Second*2, time.Millisecond*100, "too long time waiting for block")
|
2020-09-02 08:43:25 +00:00
|
|
|
return tx, height
|
2020-08-31 09:42:42 +00:00
|
|
|
}
|
|
|
|
|
2022-10-05 06:44:10 +00:00
|
|
|
func (e *Executor) GetNextLine(t *testing.T) string {
|
2020-08-29 11:41:33 +00:00
|
|
|
line, err := e.Out.ReadString('\n')
|
|
|
|
require.NoError(t, err)
|
2020-12-04 08:03:39 +00:00
|
|
|
return strings.TrimSuffix(line, "\n")
|
2020-09-28 14:24:21 +00:00
|
|
|
}
|
|
|
|
|
2022-10-05 06:44:10 +00:00
|
|
|
func (e *Executor) CheckNextLine(t *testing.T, expected string) {
|
|
|
|
line := e.GetNextLine(t)
|
|
|
|
e.CheckLine(t, line, expected)
|
2020-08-29 11:41:33 +00:00
|
|
|
}
|
|
|
|
|
2022-10-05 06:44:10 +00:00
|
|
|
func (e *Executor) CheckLine(t *testing.T, line, expected string) {
|
2020-08-29 11:41:33 +00:00
|
|
|
require.Regexp(t, expected, line)
|
|
|
|
}
|
|
|
|
|
2022-10-05 06:44:10 +00:00
|
|
|
func (e *Executor) CheckEOF(t *testing.T) {
|
2020-08-29 11:41:33 +00:00
|
|
|
_, err := e.Out.ReadString('\n')
|
|
|
|
require.True(t, errors.Is(err, io.EOF))
|
|
|
|
}
|
|
|
|
|
|
|
|
func setExitFunc() <-chan int {
|
|
|
|
ch := make(chan int, 1)
|
|
|
|
cli.OsExiter = func(code int) {
|
|
|
|
ch <- code
|
|
|
|
}
|
|
|
|
return ch
|
|
|
|
}
|
|
|
|
|
|
|
|
func checkExit(t *testing.T, ch <-chan int, code int) {
|
|
|
|
select {
|
|
|
|
case c := <-ch:
|
|
|
|
require.Equal(t, code, c)
|
|
|
|
default:
|
|
|
|
if code != 0 {
|
|
|
|
require.Fail(t, "no exit was called")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-04 22:34:40 +00:00
|
|
|
// RunWithError runs command and checks that is exits with error and exit code 1.
|
2022-10-05 06:44:10 +00:00
|
|
|
func (e *Executor) RunWithError(t *testing.T, args ...string) {
|
2020-08-29 11:41:33 +00:00
|
|
|
ch := setExitFunc()
|
|
|
|
require.Error(t, e.run(args...))
|
|
|
|
checkExit(t, ch, 1)
|
|
|
|
}
|
|
|
|
|
2024-07-04 22:34:40 +00:00
|
|
|
// RunWithErrorCheckExit runs command and checks that is exits with error and exit code 1.
|
|
|
|
func (e *Executor) RunWithErrorCheckExit(t *testing.T, msg string, args ...string) {
|
|
|
|
ch := setExitFunc()
|
|
|
|
require.ErrorContains(t, e.run(args...), msg)
|
|
|
|
checkExit(t, ch, 1)
|
|
|
|
}
|
|
|
|
|
|
|
|
// RunWithErrorCheck runs command and checks that there were errors with the specified message. Exit code is not checked.
|
|
|
|
func (e *Executor) RunWithErrorCheck(t *testing.T, msg string, args ...string) {
|
|
|
|
err := e.run(args...)
|
|
|
|
require.ErrorContains(t, err, msg)
|
|
|
|
}
|
|
|
|
|
2020-08-29 11:41:33 +00:00
|
|
|
// Run runs command and checks that there were no errors.
|
2022-10-05 06:44:10 +00:00
|
|
|
func (e *Executor) Run(t *testing.T, args ...string) {
|
2020-08-29 11:41:33 +00:00
|
|
|
ch := setExitFunc()
|
|
|
|
require.NoError(t, e.run(args...))
|
|
|
|
checkExit(t, ch, 0)
|
|
|
|
}
|
2024-04-01 17:51:33 +00:00
|
|
|
|
2024-04-03 13:40:11 +00:00
|
|
|
// 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 (e *Executor) RunUnchecked(t *testing.T, args ...string) error {
|
2024-04-01 17:51:33 +00:00
|
|
|
ch := setExitFunc()
|
|
|
|
err := e.run(args...)
|
|
|
|
if err != nil {
|
|
|
|
checkExit(t, ch, 1)
|
|
|
|
} else {
|
|
|
|
checkExit(t, ch, 0)
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-10-05 06:44:10 +00:00
|
|
|
func (e *Executor) run(args ...string) error {
|
2020-08-29 11:41:33 +00:00
|
|
|
e.Out.Reset()
|
|
|
|
e.Err.Reset()
|
2021-02-10 08:53:01 +00:00
|
|
|
input.Terminal = term.NewTerminal(input.ReadWriter{
|
|
|
|
Reader: e.In,
|
2022-02-22 16:27:32 +00:00
|
|
|
Writer: io.Discard,
|
2021-02-10 08:53:01 +00:00
|
|
|
}, "")
|
2020-12-03 14:25:17 +00:00
|
|
|
err := e.CLI.Run(args)
|
2021-02-10 08:53:01 +00:00
|
|
|
input.Terminal = nil
|
2020-12-03 14:25:17 +00:00
|
|
|
e.In.Reset()
|
|
|
|
return err
|
2020-08-29 11:41:33 +00:00
|
|
|
}
|
2020-09-01 13:24:01 +00:00
|
|
|
|
2022-10-05 06:44:10 +00:00
|
|
|
func (e *Executor) CheckTxPersisted(t *testing.T, prefix ...string) (*transaction.Transaction, uint32) {
|
2020-09-01 13:24:01 +00:00
|
|
|
line, err := e.Out.ReadString('\n')
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
line = strings.TrimSpace(line)
|
2020-10-02 11:16:25 +00:00
|
|
|
if len(prefix) > 0 {
|
|
|
|
line = strings.TrimPrefix(line, prefix[0])
|
|
|
|
}
|
2020-09-01 13:24:01 +00:00
|
|
|
h, err := util.Uint256DecodeStringLE(line)
|
|
|
|
require.NoError(t, err, "can't decode tx hash: %s", line)
|
|
|
|
|
2020-09-02 08:43:25 +00:00
|
|
|
tx, height := e.GetTransaction(t, h)
|
2020-11-11 15:43:28 +00:00
|
|
|
aer, err := e.Chain.GetAppExecResults(tx.Hash(), trigger.Application)
|
2020-09-01 13:24:01 +00:00
|
|
|
require.NoError(t, err)
|
2020-11-11 15:43:28 +00:00
|
|
|
require.Equal(t, 1, len(aer))
|
2022-07-08 14:28:29 +00:00
|
|
|
require.Equal(t, vmstate.Halt, aer[0].VMState)
|
2020-09-02 08:43:25 +00:00
|
|
|
return tx, height
|
2020-09-01 13:24:01 +00:00
|
|
|
}
|
|
|
|
|
2023-12-28 11:58:38 +00:00
|
|
|
func (e *Executor) CheckAwaitableTxPersisted(t *testing.T, prefix ...string) (*transaction.Transaction, uint32) {
|
|
|
|
tx, vub := e.CheckTxPersisted(t, prefix...)
|
|
|
|
e.CheckNextLine(t, "OnChain:\ttrue")
|
|
|
|
e.CheckNextLine(t, "VMState:\tHALT")
|
|
|
|
return tx, vub
|
|
|
|
}
|
|
|
|
|
2022-10-05 06:44:10 +00:00
|
|
|
func GenerateKeys(t *testing.T, n int) ([]*keys.PrivateKey, keys.PublicKeys) {
|
2020-09-01 13:24:01 +00:00
|
|
|
privs := make([]*keys.PrivateKey, n)
|
|
|
|
pubs := make(keys.PublicKeys, n)
|
|
|
|
for i := range privs {
|
|
|
|
var err error
|
|
|
|
privs[i], err = keys.NewPrivateKey()
|
|
|
|
require.NoError(t, err)
|
|
|
|
pubs[i] = privs[i].PublicKey()
|
|
|
|
}
|
|
|
|
return privs, pubs
|
|
|
|
}
|
2022-10-05 06:44:10 +00:00
|
|
|
|
|
|
|
func (e *Executor) CheckTxTestInvokeOutput(t *testing.T, scriptSize int) {
|
|
|
|
e.CheckNextLine(t, `Hash:\s+`)
|
|
|
|
e.CheckNextLine(t, `OnChain:\s+false`)
|
|
|
|
e.CheckNextLine(t, `ValidUntil:\s+\d+`)
|
|
|
|
e.CheckNextLine(t, `Signer:\s+\w+`)
|
|
|
|
e.CheckNextLine(t, `SystemFee:\s+(\d|\.)+`)
|
|
|
|
e.CheckNextLine(t, `NetworkFee:\s+(\d|\.)+`)
|
|
|
|
e.CheckNextLine(t, `Script:\s+\w+`)
|
|
|
|
e.CheckScriptDump(t, scriptSize)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *Executor) CheckScriptDump(t *testing.T, scriptSize int) {
|
|
|
|
e.CheckNextLine(t, `INDEX\s+`)
|
2024-08-30 18:41:02 +00:00
|
|
|
for range scriptSize {
|
2022-10-05 06:44:10 +00:00
|
|
|
e.CheckNextLine(t, `\d+\s+\w+`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func DeployContract(t *testing.T, e *Executor, inPath, configPath, wallet, address, pass string) util.Uint160 {
|
|
|
|
tmpDir := t.TempDir()
|
|
|
|
nefName := filepath.Join(tmpDir, "contract.nef")
|
|
|
|
manifestName := filepath.Join(tmpDir, "contract.manifest.json")
|
|
|
|
e.Run(t, "neo-go", "contract", "compile",
|
|
|
|
"--in", inPath,
|
|
|
|
"--config", configPath,
|
|
|
|
"--out", nefName, "--manifest", manifestName)
|
|
|
|
e.In.WriteString(pass + "\r")
|
|
|
|
e.Run(t, "neo-go", "contract", "deploy",
|
2022-11-25 10:20:53 +00:00
|
|
|
"--rpc-endpoint", "http://"+e.RPC.Addresses()[0],
|
2022-10-05 06:44:10 +00:00
|
|
|
"--wallet", wallet, "--address", address,
|
|
|
|
"--force",
|
|
|
|
"--in", nefName, "--manifest", manifestName)
|
|
|
|
e.CheckTxPersisted(t, "Sent invocation transaction ")
|
|
|
|
line, err := e.Out.ReadString('\n')
|
|
|
|
require.NoError(t, err)
|
|
|
|
line = strings.TrimSpace(strings.TrimPrefix(line, "Contract: "))
|
|
|
|
h, err := util.Uint160DecodeStringLE(line)
|
|
|
|
require.NoError(t, err)
|
|
|
|
return h
|
|
|
|
}
|