mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-22 19:19:09 +00:00
compiler: do not log panic message
In NEO3 THROW accepts an argument and exceptions can be handled, so there is no need to log it.
This commit is contained in:
parent
04f5fdefa0
commit
14ea3c2228
2 changed files with 1 additions and 37 deletions
|
@ -12,7 +12,6 @@ import (
|
|||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/interop/interopnames"
|
||||
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm"
|
||||
|
@ -1464,17 +1463,7 @@ func (c *codegen) convertBuiltin(expr *ast.CallExpr) {
|
|||
}
|
||||
}
|
||||
case "panic":
|
||||
arg := expr.Args[0]
|
||||
if isExprNil(arg) {
|
||||
emit.Opcode(c.prog.BinWriter, opcode.DROP)
|
||||
emit.Opcode(c.prog.BinWriter, opcode.THROW)
|
||||
} else if isString(c.typeInfo.Types[arg].Type) {
|
||||
ast.Walk(c, arg)
|
||||
emit.Syscall(c.prog.BinWriter, interopnames.SystemRuntimeLog)
|
||||
emit.Opcode(c.prog.BinWriter, opcode.THROW)
|
||||
} else {
|
||||
c.prog.Err = errors.New("panic should have string or nil argument")
|
||||
}
|
||||
emit.Opcode(c.prog.BinWriter, opcode.THROW)
|
||||
case "ToInteger", "ToByteArray", "ToBool":
|
||||
typ := stackitem.IntegerT
|
||||
switch name {
|
||||
|
@ -1518,8 +1507,6 @@ func transformArgs(fun ast.Expr, args []ast.Expr) []ast.Expr {
|
|||
}
|
||||
case *ast.Ident:
|
||||
switch f.Name {
|
||||
case "panic":
|
||||
return args[1:]
|
||||
case "make", "copy":
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -1,13 +1,10 @@
|
|||
package compiler_test
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/big"
|
||||
"testing"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/interop/interopnames"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
|
@ -18,26 +15,19 @@ func TestPanic(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("panic with message", func(t *testing.T) {
|
||||
var logs []string
|
||||
src := getPanicSource(true, `"execution fault"`)
|
||||
v := vmAndCompile(t, src)
|
||||
v.SyscallHandler = getLogHandler(&logs)
|
||||
|
||||
require.Error(t, v.Run())
|
||||
require.True(t, v.HasFailed())
|
||||
require.Equal(t, 1, len(logs))
|
||||
require.Equal(t, "execution fault", logs[0])
|
||||
})
|
||||
|
||||
t.Run("panic with nil", func(t *testing.T) {
|
||||
var logs []string
|
||||
src := getPanicSource(true, `nil`)
|
||||
v := vmAndCompile(t, src)
|
||||
v.SyscallHandler = getLogHandler(&logs)
|
||||
|
||||
require.Error(t, v.Run())
|
||||
require.True(t, v.HasFailed())
|
||||
require.Equal(t, 0, len(logs))
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -54,16 +44,3 @@ func getPanicSource(need bool, message string) string {
|
|||
}
|
||||
`, need, message)
|
||||
}
|
||||
|
||||
func getLogHandler(logs *[]string) vm.SyscallHandler {
|
||||
logID := interopnames.ToID([]byte(interopnames.SystemRuntimeLog))
|
||||
return func(v *vm.VM, id uint32) error {
|
||||
if id != logID {
|
||||
return errors.New("syscall not found")
|
||||
}
|
||||
|
||||
msg := v.Estack().Pop().String()
|
||||
*logs = append(*logs, msg)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue