Skip to content

Commit a7ee54e

Browse files
lamengaonventuro
authored andcommitted
getApproved require the given token ID exist (#1256)
* getApproved require the given token ID exist * missing commit from merge * clarify the test descriptions
1 parent 661e5d8 commit a7ee54e

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

contracts/token/ERC721/ERC721Basic.sol

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,12 @@ contract ERC721Basic is ERC165, IERC721Basic {
9393

9494
/**
9595
* @dev Gets the approved address for a token ID, or zero if no address set
96+
* Reverts if the token ID does not exist.
9697
* @param _tokenId uint256 ID of the token to query the approval of
9798
* @return address currently approved for the given token ID
9899
*/
99100
function getApproved(uint256 _tokenId) public view returns (address) {
101+
require(_exists(_tokenId));
100102
return tokenApprovals_[_tokenId];
101103
}
102104

test/token/ERC721/ERC721MintBurn.behavior.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,17 @@ function shouldBehaveLikeMintAndBurnERC721 (accounts) {
8484
});
8585
});
8686

87-
describe('when there is a previous approval', function () {
87+
describe('when there is a previous approval burned', function () {
8888
beforeEach(async function () {
8989
await this.token.approve(accounts[1], tokenId, { from: sender });
9090
const result = await this.token.burn(tokenId, { from: sender });
9191
logs = result.logs;
9292
});
9393

94-
it('clears the approval', async function () {
95-
(await this.token.getApproved(tokenId)).should.be.equal(ZERO_ADDRESS);
94+
context('getApproved', function () {
95+
it('reverts', async function () {
96+
await assertRevert(this.token.getApproved(tokenId));
97+
});
9698
});
9799
});
98100

0 commit comments

Comments
 (0)