-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,7 +127,7 @@ def mint(amount: int) -> bool: | |
:type amount: int | ||
:return: whether the mint was successful | ||
""" | ||
assert amount >= 0 | ||
assert amount >= 0, 'invalid amount' | ||
if not is_administrator(): | ||
return False | ||
|
||
|
@@ -157,8 +157,8 @@ def refund(address: UInt160, neo_amount: int, gas_amount: int) -> bool: | |
:type gas_amount: int | ||
:return: whether the refund was successful | ||
""" | ||
assert len(address) == 20 | ||
assert neo_amount > 0 or gas_amount > 0 | ||
assert len(address) == 20, 'invalid account length' | ||
assert neo_amount > 0 or gas_amount > 0, 'invalid amount' | ||
|
||
if not is_administrator(): | ||
return False | ||
|
@@ -168,11 +168,11 @@ def refund(address: UInt160, neo_amount: int, gas_amount: int) -> bool: | |
|
||
if neo_amount > 0: | ||
result = NEO_TOKEN.transfer(runtime.executing_script_hash, address, neo_amount) | ||
assert result | ||
assert result, 'NEO transfer failed' | ||
|
||
if gas_amount > 0: | ||
result = GAS_TOKEN.transfer(runtime.executing_script_hash, address, gas_amount) | ||
assert result | ||
assert result, 'GAS transfer failed' | ||
|
||
return True | ||
|
||
|
@@ -235,7 +235,7 @@ def balance_of(account: UInt160) -> int: | |
:return: the token balance of the `account` | ||
:raise AssertionError: raised if `account` length is not 20. | ||
""" | ||
assert len(account) == 20 | ||
assert len(account) == 20, 'invalid account length' | ||
return type_helper.to_int(storage.get(account)) | ||
|
||
|
||
|
@@ -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' | ||
# 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 commentThe reason will be displayed to describe this comment to others. Learn more. Consider checking if |
||
|
||
# The function should check whether the from address equals the caller contract hash. | ||
# If so, the transfer should be processed; | ||
|
@@ -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 commentThe 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 amount >= 0, 'invalid amount' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
||
if not runtime.check_witness(originator): | ||
return False | ||
|
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.