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 the missing test for ERC721Holder #1249

Merged
merged 4 commits into from
Sep 26, 2018

Conversation

come-maiz
Copy link
Contributor

This is one step towards #1147

πŸš€ Description

Add test coverage for ERC721Holder.

  • πŸ“˜ I've reviewed the OpenZeppelin Contributor Guidelines
  • βœ… I've added tests where applicable to test my new functionality.
  • πŸ“– I've made sure that my contracts are well-documented.
  • 🎨 I've run the JS/Solidity linters and fixed any issues (npm run lint:all:fix).


function shouldBehaveLikeERC721Holder (accounts) {
const tokenId = 1;
const creator = accounts[0];
Copy link
Contributor

Choose a reason for hiding this comment

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

😱

Consider destructuring the accounts array (e.g. change the function declaration to function shouldBehaveLikeERC721Holder ([creator])), see #1137 for reference πŸ˜…

require('chai')
.should();

function shouldBehaveLikeERC721Holder (accounts) {
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 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 safeTransferFrom works 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.

Copy link
Contributor Author

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.

Copy link
Contributor

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 safeTransferFrom in the describe('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?

Copy link
Contributor Author

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.

Copy link
Contributor

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 πŸ˜›

Copy link
Contributor Author

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.

@nventuro nventuro added kind:improvement tests Test suite and helpers. labels Aug 30, 2018
@nventuro nventuro added this to the v2.1 milestone Aug 30, 2018
@frangio frangio modified the milestones: v2.1, v2.0 Sep 24, 2018
@come-maiz
Copy link
Contributor Author

@nventuro one more time, please.

@nventuro nventuro merged commit 396680b into OpenZeppelin:master Sep 26, 2018
frangio pushed a commit that referenced this pull request Sep 26, 2018
* Add the missing test for ERC721Holder

* fix lint

* Move the holder test to a separate file

(cherry picked from commit 396680b)
@come-maiz come-maiz deleted the test/ERC721Holder branch September 26, 2018 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests Test suite and helpers.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants