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 erc1155 #290

Closed
wants to merge 69 commits into from
Closed

Conversation

dewi-tim
Copy link
Contributor

@dewi-tim dewi-tim commented Apr 28, 2022

Fixes #273.

This PR implements the ERC1155 library contract and an ERC1155_Minable_Burnable implementation for testing purposes (to expose the internal _mint and _burn methods). It features a suite of tests which leverage the utils for caching and can be run in parallel. This work began at nethermind in Dec, was continued at Circularise and has roughly tracked the main repo since then. Sorry it took so long, and many thanks for your useful discussions @andrew-fleming.

Please let me know of any changes needed and I'll try to get them done much sooner

@martriay martriay changed the title Feature/erc1155 #118 Feature/erc1155 Apr 29, 2022
@martriay martriay changed the title Feature/erc1155 Add erc1155 Apr 29, 2022
@koloz193
Copy link
Contributor

koloz193 commented May 6, 2022

this should probably be updated to include the namespace changes. here's a good reference pr for the 721 namespace changes #296

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.

Hey, @dewi-tim! I know you've been working on this for a while, so it's great to see this here! It looks really good :) I left some comments, questions, and discussions if you don't mind taking a look. Thank you for doing this, sir 🙏

Comment on lines 13 to 22
def uint_array(arr):
return list(map(uint, arr))


def uarr2cd(arr):
acc = [len(arr)]
for lo, hi in arr:
acc.append(lo)
acc.append(hi)
return acc
Copy link
Collaborator

Choose a reason for hiding this comment

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

Good additions!

tests/token/erc1155/test_ERC1155_Mintable_Burnable.py Outdated Show resolved Hide resolved
tests/token/erc1155/test_ERC1155_Mintable_Burnable.py Outdated Show resolved Hide resolved
Comment on lines 1377 to 1379
#
# Unsafe recipients
#
Copy link
Collaborator

Choose a reason for hiding this comment

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

A couple of these tests (correctly) are for safe recipients. Maybe we should change this to Non-account recipients or something like that?

src/openzeppelin/token/erc1155/library.cairo Outdated Show resolved Hide resolved
Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>
@dewi-tim
Copy link
Contributor Author

Thanks for going over all this @andrew-fleming ! I'll get to fixing these

@andrew-fleming
Copy link
Collaborator

Hey @dewi-tim! Just checking in. I know I provided a ton of suggestions and questions (sorry! 😅), but no pressure! If it's too much and/or you're too busy, just let me know :)

@dewi-tim
Copy link
Contributor Author

dewi-tim commented Jun 7, 2022

Hey @andrew-fleming, things were busy, but I can resume work on this again soon, and the mountain of suggestions is nonetheless well appreciated!

Co-authored-by: Martín Triay <martriay@gmail.com>
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.

Very thorough test suite! Left some final comments on top of the last review.

I don't think this will make it to the upcoming release, but the next one ~2 weeks from now. Would you have an ETA for the changes? Thanks!

tests/token/erc1155/test_ERC1155MintableBurnable.py Outdated Show resolved Hide resolved
tests/token/erc1155/test_ERC1155MintableBurnable.py Outdated Show resolved Hide resolved
tests/token/erc1155/test_ERC1155MintableBurnable.py Outdated Show resolved Hide resolved
src/openzeppelin/token/erc1155/library.cairo Outdated Show resolved Hide resolved
pedersen_ptr: HashBuiltin*,
range_check_ptr
}(account: felt, id: Uint256) -> (balance: Uint256):
return ERC1155.balance_of(account, id)
Copy link
Contributor

Choose a reason for hiding this comment

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

i think so, yes

tests/token/erc1155/test_ERC1155MintableBurnable.py Outdated Show resolved Hide resolved
Comment on lines 937 to 952
@pytest.mark.asyncio
async def test_mint_batch_to_receiver(erc1155_factory):
erc1155, owner, _, receiver = erc1155_factory

recipient = receiver.contract_address

await signer.send_transaction(
owner, erc1155.contract_address, 'mintBatch',
[
recipient, *uarr2cd(TOKEN_IDS),
*uarr2cd(MINT_AMOUNTS), DATA
])

execution_info = await erc1155.balanceOfBatch(
[recipient]*3, TOKEN_IDS).invoke()
assert execution_info.result.balances == MINT_AMOUNTS
Copy link
Contributor

Choose a reason for hiding this comment

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

again, i don't see the difference with test_mint_batch 🤔 . I understand the spirit is to test the acceptance of the token but I consider it implied in the above one, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wouldn't have said it is implied. In the first instance it is accepted by virtue of supporting the account interface, whereas in this case it is explicitly accepted by an IERC1155Receiver implementer. I could have in principle messed up either case and testing for just one wouldn't uncover that.

tests/token/erc1155/test_ERC1155MintableBurnable.py Outdated Show resolved Hide resolved
@dewi-tim
Copy link
Contributor Author

dewi-tim commented Sep 1, 2022

Thanks for your very thorough review! Sorry for the delay, I have some other commitments at the moment but I'll make these fixes surely by the end of next week, plausibly before Wednesday.

@martriay
Copy link
Contributor

martriay commented Sep 7, 2022

Hey there! Considering how many and how breaking changes are in the upcoming bump to Cairo 0.10, I suggest you finish this PR with the old syntax and only then we migrate to the new one, so let's wait to agree on the PR being ready before doing so!

@martriay
Copy link
Contributor

martriay commented Oct 6, 2022

hey there @dewi-tim! what's the status on this? is this ready for review?

@dewi-tim
Copy link
Contributor Author

dewi-tim commented Oct 17, 2022

Hi, sorry to reply so late. I think it was close to being ready for review, I created a new branch in the repo here that doesn't use safemath and consequently does fewer range checks while having more informative error messages and better deduplication of code.

I'll give them both the once over today to check I haven't forgotten some whitespace/comment related things

@martriay
Copy link
Contributor

martriay commented Nov 24, 2022

hey @dewi-tim! thank you very much for all the effort invested here. we decided to pick this up ourselves for the sake of speeding things up to release it during the current milestone. don't worry, you will be properly attributed in a new PR as well as in the changelog once we release. thanks again :)

also, i wonder why you decided to drop safemath in the alternative PR

@martriay martriay mentioned this pull request Dec 2, 2022
@martriay martriay closed this Dec 26, 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.

Implement ERC1155
6 participants