-
Notifications
You must be signed in to change notification settings - Fork 12.4k
Add the missing test for ERC721Holder #1249
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
Merged
Merged
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| const ERC721Holder = artifacts.require('ERC721Holder.sol'); | ||
|
|
||
| require('chai') | ||
| .should(); | ||
|
|
||
| function shouldBehaveLikeERC721Holder (accounts) { | ||
| const tokenId = 1; | ||
| const creator = accounts[0]; | ||
|
||
|
|
||
| describe('like an ERC721Holder', function () { | ||
| it('safe transfers to a holder contract', async function () { | ||
| await this.token.mint(creator, tokenId, { from: creator }); | ||
| const receiver = await ERC721Holder.new(); | ||
| await this.token.approve(receiver.address, tokenId, { from: creator }); | ||
|
|
||
| await this.token.safeTransferFrom(creator, receiver.address, tokenId); | ||
|
|
||
| (await this.token.ownerOf(tokenId)).should.be.equal(receiver.address); | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| module.exports = { | ||
| shouldBehaveLikeERC721Holder, | ||
| }; | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I'm not sure this name is accurate: the token isn't behaving like an ERC721 Holder, it is instead interacting with one.
I think we should have a test for the receiver itself, that calls the function and checks the return value, and one for the token, checking that
safeTransferFromworks properly (i.e. rejects an invalid return value, accepts the correct one). @shrugs is the local ERC721 expert though, so I'll defer to his wisdom.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.
maybe I can rename it to: shouldWorkWithERC721Holder.
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.
I checked the tests in some more detail: we're already testing that
safeTransferFromin thedescribe('via safeTransferFrom')block, what we need to test is that the ERC721Holder works with a compliant ERC721 token (i.e. it returns the correct value). Does that make sense?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 does. But I think that the best way to test that the correct value is returned from the Holder contract is to check that safeTransferFrom succeeds. Just calling onReceived directly and verifying that a magic value is returned is too low level, IMO.
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.
My point was that it's not a token test, but a holder test - it belongs in a separate test file π
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.
Yes, that sounds right. I am just wondering if I should keep this style of tests/behavior, even if it's only one simple test.