*: support _initialize
method in contracts
Invoke `_initialize` method on every call if present. In NEO3 there is no entrypoint and methods are invoked by offset, thus `Main` function is no longer required. We still have special `Main` method in tests to simplify them.
This commit is contained in:
parent
466af55dea
commit
685d44dbc1
9 changed files with 156 additions and 40 deletions
|
@ -3,7 +3,12 @@ package compiler_test
|
|||
import (
|
||||
"fmt"
|
||||
"math/big"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/compiler"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestChangeGlobal(t *testing.T) {
|
||||
|
@ -105,3 +110,20 @@ func TestArgumentLocal(t *testing.T) {
|
|||
eval(t, src, big.NewInt(40))
|
||||
})
|
||||
}
|
||||
|
||||
func TestContractWithNoMain(t *testing.T) {
|
||||
src := `package foo
|
||||
var someGlobal int = 1
|
||||
func Add3(a int) int {
|
||||
someLocal := 2
|
||||
return someGlobal + someLocal + a
|
||||
}`
|
||||
b, di, err := compiler.CompileWithDebugInfo(strings.NewReader(src))
|
||||
require.NoError(t, err)
|
||||
v := vm.New()
|
||||
invokeMethod(t, "Add3", b, v, di)
|
||||
v.Estack().PushVal(39)
|
||||
require.NoError(t, v.Run())
|
||||
require.Equal(t, 1, v.Estack().Len())
|
||||
require.Equal(t, big.NewInt(42), v.PopResult())
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue