Skip to content
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

Merged
merged 1 commit into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions boa3_test/examples/ico.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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))


Expand Down Expand Up @@ -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'

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'

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.


# The function should check whether the from address equals the caller contract hash.
# If so, the transfer should be processed;
Expand Down Expand Up @@ -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'

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 amount >= 0, 'invalid amount'

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.


if not runtime.check_witness(originator):
return False
Expand Down
Loading
Loading