Skip to content
This repository has been archived by the owner on Nov 15, 2021. It is now read-only.

Fix InputParser #959

Merged
merged 5 commits into from
Jun 20, 2019
Merged

Fix InputParser #959

merged 5 commits into from
Jun 20, 2019

Conversation

jseagrave21
Copy link
Contributor

@jseagrave21 jseagrave21 commented Jun 10, 2019

What current issue(s) does this address, or what feature is it adding?

How did you solve this problem?
trial and error

How did you make sure your solution works?
manual testing and make test

Are there any special changes in the code that we should be aware of?
no

Please check the following, if applicable:

  • Did you add any tests?
  • Did you run make lint?
  • Did you run make test?
  • Are you making a PR to a feature branch or development rather than master?
  • Did you add an entry to CHANGELOG.rst? (if not, please do)

@jseagrave21 jseagrave21 changed the title Fix inputparser Fix InputParser Jun 10, 2019
@coveralls
Copy link

coveralls commented Jun 10, 2019

Coverage Status

Coverage increased (+0.01%) to 85.917% when pulling ffa5a6e on jseagrave21:fix-inputparser into 4cff419 on CityOfZion:development.

Copy link
Member

@ixje ixje left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something is not completely working. I updated the sample contract from the issue to look like this

def main(cmd, args):
    print(args[0])
    if cmd == 1:
        return args[0] == 'aa'
    if cmd == 2:
        x = args[1]
        return x[0] == 'helloworld'
    if cmd == 3:
        lvl1 = args[1]
        lvl2 = lvl1[1]
        return lvl2[0] == 'helloworld'

invoke and results in

neo> sc build_run sc.py False False False 0210 01 3 ['notused',['notused',['helloworld']]]
Saved output to steven.avm
run `sc build_run help` to see supported queries

where I expect

Test deploy invoke successful
Used total of 61 operations
Result [{'type': 'Boolean', 'value': True}]
Invoke TX gas cost: 0.0001

@jseagrave21
Copy link
Contributor Author

@ixje I haven't been able to figure out the issue yet. If you run this test:

def test_nested_lists_3(self):
        command, arguments = self.input_parser.parse_input('sc build_run sc.py False False False 0210 01 3 ["notused",["notused",["helloworld"]]]')
        self.assertEqual(command, "sc")
        self.assertEqual(arguments, ['build_run', 'sc.py', 'False', 'False', 'False', '0210', '01', '3', '["notused",["notused",["helloworld"]]]'])

it passes.

This is the error that is causing the problem.

neo> sc build_run /mnt/c/users/jseag/neo/smartcontracts/ParseListTest.py False False False 0210 01 3 ["notused",["notused",["helloworld"]]]
Saved output to /mnt/c/users/jseag/neo/smartcontracts/ParseListTest.avm
Could not execute command: argument should be bytes, buffer or ASCII string, not 'list'
  File "/mnt/c/users/jseag/neo/neo-python-jseagrave21/venv/bin/np-prompt", line 11, in <module>
    load_entry_point('neo-python', 'console_scripts', 'np-prompt')()
  File "/mnt/c/users/jseag/neo/neo-python-jseagrave21/neo/bin/prompt.py", line 380, in main
    loop.run_forever()
  File "/usr/lib/python3.7/asyncio/base_events.py", line 521, in run_forever
    self._run_once()
  File "/usr/lib/python3.7/asyncio/base_events.py", line 1738, in _run_once
    handle._run()
  File "/usr/lib/python3.7/asyncio/events.py", line 88, in _run
    self._context.run(self._callback, *self._args)
  File "/mnt/c/users/jseag/neo/neo-python-jseagrave21/neo/bin/prompt.py", line 232, in run
    traceback.print_stack()
Traceback (most recent call last):
  File "/mnt/c/users/jseag/neo/neo-python-jseagrave21/neo/bin/prompt.py", line 218, in run
    cmd.execute(arguments)
  File "/mnt/c/users/jseag/neo/neo-python-jseagrave21/neo/Prompt/Commands/SC.py", line 44, in execute
    return self.execute_sub_command(item, arguments[1:])
  File "/mnt/c/users/jseag/neo/neo-python-jseagrave21/neo/Prompt/CommandBase.py", line 75, in execute_sub_command
    return self.__sub_commands[id].execute(arguments)
  File "/mnt/c/users/jseag/neo/neo-python-jseagrave21/neo/Prompt/Commands/SC.py", line 80, in execute
    tx, result, total_ops, engine = BuildAndRun(arguments, PromptData.Wallet)
  File "/mnt/c/users/jseag/neo/neo-python-jseagrave21/neo/Prompt/Commands/BuildNRun.py", line 72, in BuildAndRun
    debug_map=debug_map, invoke_attrs=invoke_attrs, owners=owners, enable_debugger=enable_debugger)
  File "/mnt/c/users/jseag/neo/neo-python-jseagrave21/neo/Prompt/Commands/BuildNRun.py", line 95, in DoRun
    invoke_attrs=invoke_attrs, owners=owners, enable_debugger=enable_debugger)
  File "/mnt/c/users/jseag/neo/neo-python-jseagrave21/neo/Prompt/Commands/Invoke.py", line 519, in test_deploy_and_invoke
    sb.push(subsub)
  File "/mnt/c/users/jseag/neo/neo-python-jseagrave21/neo/VM/ScriptBuilder.py", line 110, in push
    buf = binascii.unhexlify(data)
TypeError: argument should be bytes, buffer or ASCII string, not 'list'

Do you see what is wrong? I will keep working on it.

@ixje
Copy link
Member

ixje commented Jun 11, 2019

def push(self, data):

push() does not seem to know how to handle a list as its last resort is to treat it like a bytearray. Maybe there is a good reason for that, can't quickly tell. Try looking at C#'s ScriptBuilder and see what they do with arrays, perhaps they already have a way of dealing with them.

jseagrave21 added 2 commits June 15, 2019 23:15
- iterate using a single [new] function: process_params
- removed parse_params arg from TestInvokeContract to be able to reuse process_params
@jseagrave21
Copy link
Contributor Author

@ixje okay, how about now?

@ixje
Copy link
Member

ixje commented Jun 20, 2019

thanks!

@ixje ixje merged commit 1ba6f33 into CityOfZion:development Jun 20, 2019
@jseagrave21 jseagrave21 deleted the fix-inputparser branch June 20, 2019 10:29
@ixje ixje added this to Pending Distribution in Awards Distribution Jul 8, 2019
@ixje
Copy link
Member

ixje commented Jul 8, 2019

100 points

@lllwvlvwlll lllwvlvwlll moved this from Pending Distribution to In Progress in Awards Distribution Jul 17, 2019
@lllwvlvwlll
Copy link
Member

lllwvlvwlll commented Jul 18, 2019

@lllwvlvwlll lllwvlvwlll moved this from In Progress to Distributed in Awards Distribution Jul 18, 2019
@nimmortal
Copy link

Hello, when this fix will be available in master?

@ixje
Copy link
Member

ixje commented Aug 12, 2019

We are currently auditing the Mainnet to ensure correctness with the latest neo-cli version as used in the consensus nodes. Once that is done we will do a new master release. Unfortunately I can't give an exact time frame, but it's around 70% done.

@ixje
Copy link
Member

ixje commented Aug 12, 2019

In the meantime you could cherry pick this PR

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

None yet

5 participants