mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2025-05-03 23:02:27 +00:00
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:
parent
439d9ff94d
commit
4488f61777
3 changed files with 51 additions and 14 deletions
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue