cli/smartcontract: return error if deploy script failed to run

This commit is contained in:
Evgenii Stratonikov 2020-12-10 14:34:46 +03:00
parent d828096cbf
commit 1fee268f95
3 changed files with 42 additions and 2 deletions

View file

@ -10,6 +10,7 @@ import (
"testing"
"github.com/nspcc-dev/neo-go/pkg/config"
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
"github.com/nspcc-dev/neo-go/pkg/rpc/response/result"
"github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neo-go/pkg/vm"
@ -71,6 +72,35 @@ func TestContractInitAndCompile(t *testing.T) {
})
}
// Checks that error is returned if GAS available for test-invoke exceeds
// GAS needed to be consumed.
func TestDeployBigContract(t *testing.T) {
e := newExecutorWithConfig(t, true, func(c *config.Config) {
c.ApplicationConfiguration.RPC.MaxGasInvoke = fixedn.Fixed8(1)
})
defer e.Close(t)
// For proper nef generation.
config.Version = "0.90.0-test"
tmpDir := path.Join(os.TempDir(), "neogo.test.deployfail")
require.NoError(t, os.Mkdir(tmpDir, os.ModePerm))
defer os.RemoveAll(tmpDir)
nefName := path.Join(tmpDir, "deploy.nef")
manifestName := path.Join(tmpDir, "deploy.manifest.json")
e.Run(t, "neo-go", "contract", "compile",
"--in", "testdata/deploy/main.go", // compile single file
"--config", "testdata/deploy/neo-go.yml",
"--out", nefName, "--manifest", manifestName)
e.In.WriteString("one\r")
e.RunWithError(t, "neo-go", "contract", "deploy",
"--rpc-endpoint", "http://"+e.RPC.Addr,
"--wallet", validatorWallet, "--address", validatorAddr,
"--in", nefName, "--manifest", manifestName)
}
func TestComlileAndInvokeFunction(t *testing.T) {
e := newExecutor(t, true)
defer e.Close(t)

View file

@ -61,10 +61,13 @@ type executor struct {
In *bytes.Buffer
}
func newTestChain(t *testing.T) (*core.Blockchain, *server.Server, *network.Server) {
func newTestChain(t *testing.T, f func(*config.Config)) (*core.Blockchain, *server.Server, *network.Server) {
configPath := "../config/protocol.unit_testnet.single.yml"
cfg, err := config.LoadFile(configPath)
require.NoError(t, err, "could not load config")
if f != nil {
f(&cfg)
}
memoryStore := storage.NewMemoryStore()
logger := zaptest.NewLogger(t)
@ -85,6 +88,10 @@ func newTestChain(t *testing.T) (*core.Blockchain, *server.Server, *network.Serv
}
func newExecutor(t *testing.T, needChain bool) *executor {
return newExecutorWithConfig(t, needChain, nil)
}
func newExecutorWithConfig(t *testing.T, needChain bool, f func(*config.Config)) *executor {
e := &executor{
CLI: newApp(),
Out: bytes.NewBuffer(nil),
@ -97,7 +104,7 @@ func newExecutor(t *testing.T, needChain bool) *executor {
require.Nil(t, input.Terminal) // check that tests clean up properly
input.Terminal = terminal.NewTerminal(rw, "")
if needChain {
e.Chain, e.RPC, e.NetSrv = newTestChain(t)
e.Chain, e.RPC, e.NetSrv = newTestChain(t, f)
}
return e
}

View file

@ -773,6 +773,9 @@ func contractDeploy(ctx *cli.Context) error {
}
// It doesn't require any signers.
invRes, err := c.InvokeScript(txScript, nil)
if err == nil && invRes.FaultException != "" {
err = errors.New(invRes.FaultException)
}
if err != nil {
return cli.NewExitError(fmt.Errorf("failed to test-invoke deployment script: %w", err), 1)
}