mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-26 19:42:23 +00:00
compiler: convert AppCall parameter from string properly
This commit is contained in:
parent
d65d6ab08d
commit
77f9a2ee26
2 changed files with 28 additions and 0 deletions
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
Loading…
Reference in a new issue