mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-26 19:42:23 +00:00
Merge pull request #1162 from nspcc-dev/neo3/compiler/dynamic_appcall
compiler: compile appcall with dynamic argument
This commit is contained in:
commit
f32920bf39
2 changed files with 20 additions and 1 deletions
|
@ -1216,7 +1216,7 @@ func (c *codegen) convertBuiltin(expr *ast.CallExpr) {
|
||||||
case "AppCall":
|
case "AppCall":
|
||||||
c.emitReverse(len(expr.Args))
|
c.emitReverse(len(expr.Args))
|
||||||
buf := c.getByteArray(expr.Args[0])
|
buf := c.getByteArray(expr.Args[0])
|
||||||
if len(buf) != 20 {
|
if buf != nil && len(buf) != 20 {
|
||||||
c.prog.Err = errors.New("invalid script hash")
|
c.prog.Err = errors.New("invalid script hash")
|
||||||
}
|
}
|
||||||
emit.Syscall(c.prog.BinWriter, "System.Contract.Call")
|
emit.Syscall(c.prog.BinWriter, "System.Contract.Call")
|
||||||
|
|
|
@ -127,6 +127,25 @@ func TestAppCall(t *testing.T) {
|
||||||
|
|
||||||
assertResult(t, v, []byte{1, 2, 3, 4})
|
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 {
|
func getAppCallScript(h string) string {
|
||||||
|
|
Loading…
Reference in a new issue