compiler: convert AppCall parameter from string properly

This commit is contained in:
Evgenii Stratonikov 2020-01-27 15:30:36 +03:00
parent d65d6ab08d
commit 77f9a2ee26
2 changed files with 28 additions and 0 deletions

View file

@ -672,6 +672,13 @@ func (c *codegen) getByteArray(expr ast.Expr) []byte {
buf[i] = byte(val) buf[i] = byte(val)
} }
return buf return buf
case *ast.CallExpr:
if tv := c.typeInfo.Types[t.Args[0]]; tv.Value != nil {
val := constant.StringVal(tv.Value)
return []byte(val)
}
return nil
default: default:
return nil return nil
} }

View file

@ -100,6 +100,27 @@ func TestAppCall(t *testing.T) {
_, err := compiler.Compile(strings.NewReader(src)) _, err := compiler.Compile(strings.NewReader(src))
require.Error(t, err) require.Error(t, err)
}) })
t.Run("convert from string constant", func(t *testing.T) {
src := `
package foo
import "github.com/CityOfZion/neo-go/pkg/interop/engine"
const scriptHash = ` + fmt.Sprintf("%#v", string(ih.BytesBE())) + `
func Main() int {
x := 13
y := 29
result := engine.AppCall([]byte(scriptHash), []interface{}{x, y})
return result.(int)
}
`
v := vmAndCompile(t, src)
v.SetScriptGetter(getScript)
require.NoError(t, v.Run())
assertResult(t, v, big.NewInt(42))
})
} }
func getAppCallScript(h string) string { func getAppCallScript(h string) string {