-
Notifications
You must be signed in to change notification settings - Fork 189
add --return-type to override test invoke return parameter type #913
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a great addition. Will the code support the string equivalents of the ParameterTypes? I ask because I know it is a goal for users to be able to specify the input and output types with their string equivalents (i.e. "Integer" is acceptable, not just "02")
See #781
for item in params: | ||
if '--return-type' in item: | ||
params.remove(item) | ||
return_type = item.replace('--return-type=', '') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recommend adding some logic here to ensure only acceptable ParameterTypes are allowed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I asked myself when adding this option, does it add more value to add some sort of input sanity check rather than just educating the user through hitting an exception when they enter a bad parameter type? This is for advanced users after all. Personally I like the feedback loop approach, it doesn't really have any negative impact and it cuts down on the amount of code that needs to be maintained.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While true that it reduces code maintenance, we put in a lot of effort to get rid of exception throwing due to user input errors when we refactored the cli. I personally don't think that an advanced option or tool justifies not handling exceptions. In this case it's also as simple as doing
try:
[ContractParameter.AsParameterType(ContractParameterType.FromString(return_type), item).ToJson() for item in results]
except ValueError:
# inform user
It does support using the string equivalents but I don't use those in the example because the deployment convention has always been hex notation, both in neo-gui and neo-python, and all the documented examples use the hex notation. Unless it changes everywhere users are still going to need to know the mapping between hex and string parameter notation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #913 (comment)
Please add exception handling and add a test case for coverage. Thanks!
Added exception handler and unit tests. |
Thanks! |
What current issue(s) does this address, or what feature is it adding?
Contract invocation results are displayed using the default return type of the contract, even though some operations will return different types than the default, requiring the user to manually convert results, e.g. from bytearray to integer
How did you solve this problem?
Added a --return-type argument to the
sc invoke
command to allow the user to override the contract's default return type during a test invokeHow did you make sure your solution works?
Manual testing
Are there any special changes in the code that we should be aware of?
No
Please check the following, if applicable:
make lint
?make test
?CHANGELOG.rst
? (if not, please do)