-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#86drpnd2j - Refactor example_tests/test_ico.py to use BoaConstructor #1228
Conversation
@@ -380,9 +380,9 @@ def transfer_from(originator: UInt160, from_address: UInt160, to_address: UInt16 | |||
:raise AssertionError: raised if `from_address` or `to_address` length is not 20 or if `amount` if less than zero. | |||
""" | |||
# the parameters from and to should be 20-byte addresses. If not, this method should throw an exception. | |||
assert len(originator) == 20 and len(from_address) == 20 and len(to_address) == 20 | |||
assert len(originator) == 20 and len(from_address) == 20 and len(to_address) == 20, 'invalid account length' |
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.
It would be more helpful to provide separate error messages for each condition in the assertion. This way, if the assertion fails, it will be easier to identify which condition was not met.
# the parameter amount must be greater than or equal to 0. If not, this method should throw an exception. | ||
assert amount >= 0 | ||
assert amount >= 0, 'invalid amount' |
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.
Consider checking if amount
is an integer before checking if it's greater than or equal to 0. This will prevent potential type errors.
@@ -440,8 +440,8 @@ def approve(originator: UInt160, to_address: UInt160, amount: int) -> bool: | |||
:return: whether the approval was successful | |||
:raise AssertionError: raised if `originator` or `to_address` length is not 20 or if `amount` if less than zero. | |||
""" | |||
assert len(originator) == 20 and len(to_address) == 20 | |||
assert amount >= 0 | |||
assert len(originator) == 20 and len(to_address) == 20, 'invalid account length' |
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.
Consider splitting the combined assertion into two separate assertions. This will make the code more readable and easier to debug, as you will know exactly which condition failed.
assert len(originator) == 20 and len(to_address) == 20 | ||
assert amount >= 0 | ||
assert len(originator) == 20 and len(to_address) == 20, 'invalid account length' | ||
assert amount >= 0, 'invalid amount' |
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.
Consider adding more context to the error message. For example, 'invalid amount: amount cannot be negative' would provide more information about why the error occurred.
Summary or solution description
Refactored
example_tests/test_ico.py
files to useBoaTestCase
in place ofBoaTest
for unit testing.