From a7ee54e1991ea776625ba69bca5152f3e45d918c Mon Sep 17 00:00:00 2001 From: Bing Yi Date: Fri, 7 Sep 2018 06:43:48 +0800 Subject: [PATCH] getApproved require the given token ID exist (#1256) * getApproved require the given token ID exist * missing commit from merge * clarify the test descriptions --- contracts/token/ERC721/ERC721Basic.sol | 2 ++ test/token/ERC721/ERC721MintBurn.behavior.js | 8 +++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/contracts/token/ERC721/ERC721Basic.sol b/contracts/token/ERC721/ERC721Basic.sol index cf09e8178..866640a0f 100644 --- a/contracts/token/ERC721/ERC721Basic.sol +++ b/contracts/token/ERC721/ERC721Basic.sol @@ -93,10 +93,12 @@ contract ERC721Basic is ERC165, IERC721Basic { /** * @dev Gets the approved address for a token ID, or zero if no address set + * Reverts if the token ID does not exist. * @param _tokenId uint256 ID of the token to query the approval of * @return address currently approved for the given token ID */ function getApproved(uint256 _tokenId) public view returns (address) { + require(_exists(_tokenId)); return tokenApprovals_[_tokenId]; } diff --git a/test/token/ERC721/ERC721MintBurn.behavior.js b/test/token/ERC721/ERC721MintBurn.behavior.js index c165f1703..ad7d20736 100644 --- a/test/token/ERC721/ERC721MintBurn.behavior.js +++ b/test/token/ERC721/ERC721MintBurn.behavior.js @@ -84,15 +84,17 @@ function shouldBehaveLikeMintAndBurnERC721 (accounts) { }); }); - describe('when there is a previous approval', function () { + describe('when there is a previous approval burned', function () { beforeEach(async function () { await this.token.approve(accounts[1], tokenId, { from: sender }); const result = await this.token.burn(tokenId, { from: sender }); logs = result.logs; }); - it('clears the approval', async function () { - (await this.token.getApproved(tokenId)).should.be.equal(ZERO_ADDRESS); + context('getApproved', function () { + it('reverts', async function () { + await assertRevert(this.token.getApproved(tokenId)); + }); }); });