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

Add ERC20Burnable preset #252

Merged
merged 13 commits into from
Aug 25, 2022
Merged

Conversation

koloz193
Copy link
Contributor

@koloz193 koloz193 commented Apr 1, 2022

Created an erc20 burnable preset from the mocked file and removed the mock since it's no longer needed.

Fixes #237

Depends on:

@andrew-fleming
Copy link
Collaborator

Hey @koloz193, thank you for submitting this PR! I know you're aware that we're considering some changes to the library (#267 and you mentioned in your comment^). Once we get this straightened out, we'll be able to review :)

@koloz193 koloz193 force-pushed the feature/erc_20_burnable branch from ddf927e to 80a904c Compare May 3, 2022 13:26
@koloz193
Copy link
Contributor Author

koloz193 commented May 3, 2022

@andrew-fleming makes sense. i ended up doing a fresh refactor based on the current state of main

@andrew-fleming
Copy link
Collaborator

@koloz193 ahh yeah, the rebasing conflicts must have looked like a nightmare

@koloz193
Copy link
Contributor Author

koloz193 commented May 4, 2022

@koloz193 ahh yeah, the rebasing conflicts must have looked like a nightmare

yup, once i saw like 10 different files i quickly decided against trying to attempt the rebase

@andrew-fleming
Copy link
Collaborator

@koloz193 Ownable is merged! I appreciate your patience, sir 🙏 at your leisure, would you mind updating your branch?

@koloz193
Copy link
Contributor Author

awesome! will merge in main and clean it up!

Copy link
Collaborator

@andrew-fleming andrew-fleming left a comment

Choose a reason for hiding this comment

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

This looks great, sir! Thanks again for doing this :) I left a couple of comments

Comment on lines 175 to 179
@view
func owner{
syscall_ptr: felt*,
pedersen_ptr: HashBuiltin*,
range_check_ptr
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we should move this up and keep it grouped with the Getters and maybe add an Externals comment to demarcate the @external methods for consistency

Comment on lines 157 to 160
new_balance = sub_uint(INIT_SUPPLY, AMOUNT)

execution_info = await erc20.balanceOf(account1.contract_address).invoke()
assert execution_info.result.balance == new_balance
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should check that account2's allowance is correctly subtracted here. Just to be thorough, I think we should include additional tests for:

  • burnFrom emits Transfer event
  • burnFrom reverts when burn amount exceeds balance
  • burnFrom reverts when account is the zero address (I believe spender as the zero address is indirectly covered with "insufficient allowance")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good call, ill add these tests in

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thank you, sir! I'm re-reviewing the enumerable PR as well, so hopefully we can get your contributions in soon!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@andrew-fleming added testing for the event. looks like burnFrom reverts when burn amount exceeds balance is covered by the following test and having account as the zero address results in an underflow error since the zero address cant give any approval

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah my mistake. Thank you for adding in the event test!

@koloz193 koloz193 requested a review from andrew-fleming June 24, 2022 19:32
Copy link
Collaborator

@andrew-fleming andrew-fleming left a comment

Choose a reason for hiding this comment

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

@koloz193 This looks excellent and good to go for me! Thank you so much :)

@koloz193
Copy link
Contributor Author

@andrew-fleming @martriay any update on this 😄

@martriay
Copy link
Contributor

This is currently on our project roadmap, just that it's prioritized as "Low". This means we will tackle it whenever we finish higher priority issues, or we reprioritize based on new information. Sorry it's taking so long 🙇.

Copy link
Contributor

@martriay martriay left a comment

Choose a reason for hiding this comment

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

@koloz193 sorry for taking so long! I updated the PR to match the latest directory structure (#350). I left a few comments but otherwise good to go!

):
ERC20.initializer(name, symbol, decimals)
ERC20._mint(recipient, initial_supply)
Ownable.initializer(owner)
Copy link
Contributor

Choose a reason for hiding this comment

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

why is it ownable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good call, removing ownable

Comment on lines 188 to 204
@external
func transferOwnership{
syscall_ptr: felt*,
pedersen_ptr: HashBuiltin*,
range_check_ptr
}(newOwner: felt):
Ownable.transfer_ownership(newOwner)
return ()
end

@external
func renounceOwnership{
syscall_ptr: felt*,
pedersen_ptr: HashBuiltin*,
range_check_ptr
}():
Ownable.renounce_ownership()
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure I get why are these needed

Comment on lines +158 to +167
assert_event_emitted(
tx_exec_info,
from_address=erc20.contract_address,
name='Transfer',
data=[
account1.contract_address,
ZERO_ADDRESS,
*AMOUNT
]
)
Copy link
Contributor

Choose a reason for hiding this comment

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

what do you think about splitting this into two different tests? that'd be consistent with burn whose storage effects and emitted events are tested separately

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yea easy enough

@martriay martriay changed the title ERC20_Burnable preset Add ERC20Burnable preset Jul 29, 2022
@martriay
Copy link
Contributor

martriay commented Aug 5, 2022

Hey @koloz193! Do you think you will be able to finish this one off or should we pick it up? Thanks :)

@koloz193
Copy link
Contributor Author

koloz193 commented Aug 5, 2022

@martriay yup I'll wrap it up this weekend!

@martriay
Copy link
Contributor

@koloz193 kind ping (:

@koloz193
Copy link
Contributor Author

@martriay just pushed the changes, sorry for the delay but ran the tests and it looks good

@koloz193 koloz193 requested a review from martriay August 16, 2022 14:09
Copy link
Contributor

@martriay martriay left a comment

Choose a reason for hiding this comment

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

Looking good! Requested small changes, plus resolving merge conflicts I think we're good! Thanks again :)

@@ -1,11 +1,12 @@
# SPDX-License-Identifier: MIT
# OpenZeppelin Cairo Contracts v0.2.1 (token/erc20/presets/ERC20Burnable.cairo)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# OpenZeppelin Cairo Contracts v0.2.1 (token/erc20/presets/ERC20Burnable.cairo)
# OpenZeppelin Cairo Contracts v0.3.1 (token/erc20/presets/ERC20Burnable.cairo)

I think we need to update this

@@ -19,7 +20,8 @@ func constructor{
symbol: felt,
decimals: felt,
initial_supply: Uint256,
recipient: felt
recipient: felt,
owner: felt
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
owner: felt

there's no owner anymore

@@ -42,29 +46,32 @@ async def erc20_init(contract_classes):
DECIMALS,
*INIT_SUPPLY,
account1.contract_address, # recipient
account1.contract_address, # owner
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
account1.contract_address, # owner

@koloz193 koloz193 requested a review from martriay August 18, 2022 13:47
@martriay
Copy link
Contributor

Amazing! Now there's only the merge conflicts left.

@koloz193
Copy link
Contributor Author

Amazing! Now there's only the merge conflicts left.

not anymore 😄

@martriay martriay merged commit 258a14f into OpenZeppelin:main Aug 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add ERC20 Burnable preset
3 participants