From 56a5c9db116747c5975f0da78f793ad3fc82fee9 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Wed, 8 Jul 2020 17:37:42 +0300 Subject: [PATCH] compiler: compile appcall with dynamic argument Closes #1160 --- pkg/compiler/codegen.go | 2 +- pkg/compiler/interop_test.go | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/pkg/compiler/codegen.go b/pkg/compiler/codegen.go index 25aa5cb31..96c3aa68b 100644 --- a/pkg/compiler/codegen.go +++ b/pkg/compiler/codegen.go @@ -1216,7 +1216,7 @@ func (c *codegen) convertBuiltin(expr *ast.CallExpr) { case "AppCall": c.emitReverse(len(expr.Args)) buf := c.getByteArray(expr.Args[0]) - if len(buf) != 20 { + if buf != nil && len(buf) != 20 { c.prog.Err = errors.New("invalid script hash") } emit.Syscall(c.prog.BinWriter, "System.Contract.Call") diff --git a/pkg/compiler/interop_test.go b/pkg/compiler/interop_test.go index 7180b85bd..6a8308924 100644 --- a/pkg/compiler/interop_test.go +++ b/pkg/compiler/interop_test.go @@ -127,6 +127,25 @@ func TestAppCall(t *testing.T) { assertResult(t, v, []byte{1, 2, 3, 4}) }) + + t.Run("convert from var", func(t *testing.T) { + src := ` + package foo + import "github.com/nspcc-dev/neo-go/pkg/interop/engine" + func Main() []byte { + x := []byte{1, 2} + y := []byte{3, 4} + var addr = []byte(` + fmt.Sprintf("%#v", string(ih.BytesBE())) + `) + result := engine.AppCall(addr, x, y) + return result.([]byte) + } + ` + + v := spawnVM(t, ic, src) + require.NoError(t, v.Run()) + + assertResult(t, v, []byte{1, 2, 3, 4}) + }) } func getAppCallScript(h string) string {