CityOfZion / neo-storm

Smart contract framework for the NEO smart economy written in the Go programming language.
MIT License
38 stars 10 forks source link

arguments fault when numArg of a function is more than 2 #57

Open ZhangTao1596 opened 5 years ago

ZhangTao1596 commented 5 years ago

Description of the issue

i build a function called Transfer with 4 args. but when i invoke the function, arguments' values in function are not the same as the input variables.

Type (put an x sign in the square brackets)

Checklist

Your environment

Expected behaviour

successlly transfer from fromHash to toHash with the amount

Actual behaviour

got wrong arguments

Steps to reproduce

  1. i write a contract named ICOTemplate.go, here: https://github.com/KickSeason/go-smart-contract-workshop/blob/dev/ICOTemplate/ICOTemplate.go
  2. i set up neo-privetnet using docker and neo-python using source code
  3. compile contract using: neo-storm compile -i ICOTemplate.go
  4. then i use neo-python deploy it and invoke deploy and balanceOf successfully
  5. problem happened when invoke transfer. you can see i write runtime.Notify at line 84-86 and line 150-153 of ICOTemplate.go to compare variables and args i got. but got different values.

before call transfer:

            runtime.Notify(args)
            fromHash := args[0].([]byte)
            toHash := args[1].([]byte)
            amount := args[2].(int)
            runtime.Notify(fromHash)
            runtime.Notify(toHash)
            runtime.Notify(amount)
            return I.Transfer(ctx, fromHash, toHash, amount)

during transfer:

func (I ICOSettings) Transfer(ctx storage.Context, fromHash []byte, toHash []byte, amount int) bool {
    runtime.Notify("transfer")
    runtime.Notify(fromHash)
    runtime.Notify(toHash)
    runtime.Notify(amount)

output: transfer toHash became InteropInterface amount disappears

Any extra info ( for eg. code snippet to reproduce, logs, etc. )

ZhangTao1596 commented 5 years ago

I think I make the stack full and cant push into more variables. So when I try getting the arg, I got the method receiver not the argument. I use function instead of method to avoid the problem now.

fyrchik commented 5 years ago

@KickSeason Hello! I've also run into similar problem and made a fix which worked for myself. https://github.com/CityOfZion/neo-storm/pull/51

There are, probably, more cases to consider there. Does always work as expected when you use function instead of method?