Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Nov 15, 2022
1 parent 40bc5b0 commit f08d635
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
9 changes: 5 additions & 4 deletions contracts/ERC721AUpgradeable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -877,10 +877,11 @@ contract ERC721AUpgradeable is ERC721A__Initializable, IERC721AUpgradeable {
) internal virtual {
address owner = ownerOf(tokenId);

if (approvalCheck && _msgSenderERC721A() != owner)
if (!isApprovedForAll(owner, _msgSenderERC721A())) {
revert ApprovalCallerNotOwnerNorApproved();
}
if (approvalCheck)
if (_msgSenderERC721A() != owner)
if (!isApprovedForAll(owner, _msgSenderERC721A())) {
revert ApprovalCallerNotOwnerNorApproved();
}

ERC721AStorage.layout()._tokenApprovals[tokenId].value = to;
emit Approval(owner, to, tokenId);
Expand Down
4 changes: 4 additions & 0 deletions contracts/mocks/ERC721AMockUpgradeable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ contract ERC721AMockUpgradeable is ERC721A__Initializable, ERC721AUpgradeable {
_setAux(owner, aux);
}

function directApprove(address to, uint256 tokenId) public {
_approve(to, tokenId);
}

function baseURI() public view returns (string memory) {
return _baseURI();
}
Expand Down
6 changes: 6 additions & 0 deletions test/ERC721A.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,12 @@ const createTestSuite = ({ contract, constructorArgs }) =>
await this.erc721a.connect(this.addr1).transferFrom(this.addr1.address, this.addr2.address, this.tokenId);
expect(await this.erc721a.getApproved(this.tokenId)).to.not.equal(this.addr1.address);
});

it('direct approve works', async function () {
expect(await this.erc721a.getApproved(this.tokenId)).to.not.equal(this.addr1.address);
await this.erc721a.connect(this.addr2).directApprove(this.addr1.address, this.tokenId);
expect(await this.erc721a.getApproved(this.tokenId)).to.equal(this.addr1.address);
});
});

describe('setApprovalForAll', async function () {
Expand Down

0 comments on commit f08d635

Please sign in to comment.