compiler: reverse args in AppCall
Invoked contract is expecting first argument to be on top of the stack. Change test to use non-commutative operation to catch this behaviour.
This commit is contained in:
parent
52d8d58593
commit
895a8d9ebc
2 changed files with 15 additions and 13 deletions
|
@ -786,6 +786,9 @@ func (c *codegen) convertBuiltin(expr *ast.CallExpr) {
|
|||
case "VerifySignature":
|
||||
emit.Opcode(c.prog.BinWriter, opcode.VERIFY)
|
||||
case "AppCall":
|
||||
numArgs := len(expr.Args) - 1
|
||||
c.emitReverse(numArgs)
|
||||
|
||||
emit.Opcode(c.prog.BinWriter, opcode.APPCALL)
|
||||
buf := c.getByteArray(expr.Args[0])
|
||||
if len(buf) != 20 {
|
||||
|
|
|
@ -2,7 +2,6 @@ package compiler_test
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"math/big"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
|
@ -55,8 +54,8 @@ func TestFromAddress(t *testing.T) {
|
|||
func TestAppCall(t *testing.T) {
|
||||
srcInner := `
|
||||
package foo
|
||||
func Main(a int, b int) int {
|
||||
return a + b
|
||||
func Main(a []byte, b []byte) []byte {
|
||||
return append(a, b...)
|
||||
}
|
||||
`
|
||||
|
||||
|
@ -78,7 +77,7 @@ func TestAppCall(t *testing.T) {
|
|||
|
||||
require.NoError(t, v.Run())
|
||||
|
||||
assertResult(t, v, big.NewInt(42))
|
||||
assertResult(t, v, []byte{1, 2, 3, 4})
|
||||
})
|
||||
|
||||
t.Run("missing script", func(t *testing.T) {
|
||||
|
@ -104,11 +103,11 @@ func TestAppCall(t *testing.T) {
|
|||
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
|
||||
func Main() []byte {
|
||||
x := []byte{1, 2}
|
||||
y := []byte{3, 4}
|
||||
result := engine.AppCall([]byte(scriptHash), x, y)
|
||||
return result.(int)
|
||||
return result.([]byte)
|
||||
}
|
||||
`
|
||||
|
||||
|
@ -117,7 +116,7 @@ func TestAppCall(t *testing.T) {
|
|||
|
||||
require.NoError(t, v.Run())
|
||||
|
||||
assertResult(t, v, big.NewInt(42))
|
||||
assertResult(t, v, []byte{1, 2, 3, 4})
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -125,11 +124,11 @@ func getAppCallScript(h string) string {
|
|||
return `
|
||||
package foo
|
||||
import "github.com/CityOfZion/neo-go/pkg/interop/engine"
|
||||
func Main() int {
|
||||
x := 13
|
||||
y := 29
|
||||
func Main() []byte {
|
||||
x := []byte{1, 2}
|
||||
y := []byte{3, 4}
|
||||
result := engine.AppCall(` + h + `, x, y)
|
||||
return result.(int)
|
||||
return result.([]byte)
|
||||
}
|
||||
`
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue