From 659fb89bebc8fbd170cab9ad51addf1b056f06c7 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Mon, 12 Oct 2020 12:45:38 +0300 Subject: [PATCH] cli: warn about bad VM state during invokefunction --- cli/smartcontract/smart_contract.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/cli/smartcontract/smart_contract.go b/cli/smartcontract/smart_contract.go index dcc4cf6d1..231b7bc59 100644 --- a/cli/smartcontract/smart_contract.go +++ b/cli/smartcontract/smart_contract.go @@ -55,6 +55,10 @@ var ( Name: "out", Usage: "file to put JSON transaction to", } + forceFlag = cli.StringFlag{ + Name: "force", + Usage: "force-push the transaction in case of bad VM state after test script invocation", + } ) const ( @@ -110,6 +114,7 @@ func NewCommands() []cli.Command { addressFlag, gasFlag, outFlag, + forceFlag, } invokeFunctionFlags = append(invokeFunctionFlags, options.RPC...) return []cli.Command{{ @@ -487,6 +492,13 @@ func invokeInternal(ctx *cli.Context, signAndPush bool) error { if err != nil { return cli.NewExitError(err, 1) } + if signAndPush && resp.State != "HALT" { + errText := fmt.Sprintf("Warning: %s VM state returned from the RPC node: %s\n", resp.State, resp.FaultException) + if ctx.String("force") == "" { + return cli.NewExitError(errText+". Use --force flag to send the transaction anyway.", 1) + } + fmt.Fprintln(ctx.App.Writer, errText+". Sending transaction...") + } if out := ctx.String("out"); out != "" { script, err := hex.DecodeString(resp.Script) if err != nil {