compiler: provide .go filename to Compile

First argument contains filename, thus we use '.go' suffix to
distinguish between directories and files.
Contract name should be provided in options.

Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgeniy Stratonikov 2021-12-02 16:36:29 +03:00
parent 8af9c870b1
commit e7a0ecb349
10 changed files with 35 additions and 28 deletions

View file

@ -302,7 +302,7 @@ func TestJumpOptimize(t *testing.T) {
func Main() int {
return Get3()
}`
b, di, err := compiler.CompileWithOptions("", strings.NewReader(src), nil)
b, di, err := compiler.CompileWithOptions("file.go", strings.NewReader(src), nil)
require.NoError(t, err)
require.Equal(t, 6, len(di.Methods))
for _, mi := range di.Methods {
@ -333,7 +333,7 @@ func TestUnusedFunctions(t *testing.T) {
return nestedcall.X
}`
b, err := compiler.Compile("foo", strings.NewReader(src))
b, err := compiler.Compile("foo.go", strings.NewReader(src))
require.NoError(t, err)
require.Equal(t, 3, len(b)) // PUSHINT8 (42) + RET
eval(t, src, big.NewInt(42))
@ -346,7 +346,7 @@ func TestUnusedFunctions(t *testing.T) {
return inner.N()
}`
_, err := compiler.Compile("foo", strings.NewReader(src))
_, err := compiler.Compile("foo.go", strings.NewReader(src))
require.NoError(t, err)
eval(t, src, big.NewInt(65))
})
@ -359,7 +359,7 @@ func TestUnusedFunctions(t *testing.T) {
return t.Method()
}`
_, err := compiler.Compile("foo", strings.NewReader(src))
_, err := compiler.Compile("foo.go", strings.NewReader(src))
require.NoError(t, err)
eval(t, src, big.NewInt(2231))
})