mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-11 15:30:07 +00:00
14ea3c2228
In NEO3 THROW accepts an argument and exceptions can be handled, so there is no need to log it.
46 lines
850 B
Go
46 lines
850 B
Go
package compiler_test
|
|
|
|
import (
|
|
"fmt"
|
|
"math/big"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestPanic(t *testing.T) {
|
|
t.Run("no panic", func(t *testing.T) {
|
|
src := getPanicSource(false, `"execution fault"`)
|
|
eval(t, src, big.NewInt(7))
|
|
})
|
|
|
|
t.Run("panic with message", func(t *testing.T) {
|
|
src := getPanicSource(true, `"execution fault"`)
|
|
v := vmAndCompile(t, src)
|
|
|
|
require.Error(t, v.Run())
|
|
require.True(t, v.HasFailed())
|
|
})
|
|
|
|
t.Run("panic with nil", func(t *testing.T) {
|
|
src := getPanicSource(true, `nil`)
|
|
v := vmAndCompile(t, src)
|
|
|
|
require.Error(t, v.Run())
|
|
require.True(t, v.HasFailed())
|
|
})
|
|
}
|
|
|
|
func getPanicSource(need bool, message string) string {
|
|
return fmt.Sprintf(`
|
|
package main
|
|
func Main() int {
|
|
needPanic := %#v
|
|
if needPanic {
|
|
panic(%s)
|
|
return 5
|
|
}
|
|
return 7
|
|
}
|
|
`, need, message)
|
|
}
|