CityOfZion / neo-python

Python Node and SDK for the NEO 2.x blockchain. For NEO 3.x go to our successor project neo-mamba
https://neo-python.readthedocs.io/en/latest/
MIT License
312 stars 188 forks source link

String concat and "build ... test ..." bugs #683

Closed nhannamsiu closed 6 years ago

nhannamsiu commented 6 years ago

Current behavior

Wrong behavior when concatenating string that is stored inside variable Cannot run the original build test command

Expected behavior

a = 'aaa'
b = 'bbb'
result = a + b 

result should be 'aaabbb', but the output is 12829635

How to reproduce

Source code:
def one():
    return ('aaa' + 'bbb')

def two():
    a = 'aaa'
    b = 'bbb'
    return (a+b)

def main(op):
    if (op=='one'):
        return one()
    elif (op=='two'):
        return two()

In terminal: source venv/bin/activate np-prompt open wallet ./mywallet build example.py test 07 07 False False one build example.py test 07 07 False False two

The above build test commands didn't work, but if I add something before the param list then it works: build example.py test 07 07 False False | two build example.py test 07 07 False False ? two
build example.py test 07 07 False False ./}{} two

Your environment

OS: MacOS Mojave neo-python: v0.8.1 Python: 3.7.0

ixje commented 6 years ago

concat: neo-python makes use of the neo-boa compiler link for handling the smartcontract to .avm format conversion. Smart contracts only support a subset of python. To my best knowledge at this point you'll need to use the concat function instead of a+b

from boa.builtins import concat
result = concat('aaa','bbb')

build: You are not specifying enough arguments. Your first attempts fail because you are not specifying the is_payable argument. See the help output: build {path/to/file.py} (test {params} {returntype} {needs_storage} {needs_dynamic_invoke} {is_payable} [{test_params} or --i])

nhannamsiu commented 6 years ago

Thank you, I need to inspect neo-boa more.

By the way, I was following the tutorial on build and test contract at https://neo-python.readthedocs.io/en/latest/neo/SmartContract/smartcontracts.html#build-and-test-your-contract. Which appreared to miss the {is_payable} argument. Not sure if you maintain this document, but I just bring this up so other ones who have the same problem can refer to.

ixje commented 6 years ago

thanks for pointing that out, will update.