compiler: compile init even if there are no globals

`init` can be useful even if no globals are present,
e.g. we can use some syscall inside.
This commit is contained in:
Evgenii Stratonikov 2020-08-05 12:59:50 +03:00
parent 439d9ff94d
commit 4488f61777
3 changed files with 51 additions and 14 deletions

View file

@ -3,6 +3,8 @@ package compiler_test
import (
"math/big"
"testing"
"github.com/stretchr/testify/require"
)
func TestInit(t *testing.T) {
@ -88,3 +90,18 @@ func TestImportOrder(t *testing.T) {
eval(t, src, big.NewInt(3))
})
}
func TestInitWithNoGlobals(t *testing.T) {
src := `package foo
import "github.com/nspcc-dev/neo-go/pkg/interop/runtime"
func init() {
runtime.Notify("called in '_initialize'")
}
func Main() int {
return 42
}`
v, s := vmAndCompileInterop(t, src)
require.NoError(t, v.Run())
assertResult(t, v, big.NewInt(42))
require.True(t, len(s.events) == 1)
}