Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Aniket-Engg committed Nov 28, 2018
1 parent 7f9725e commit ac8c493
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
8 changes: 6 additions & 2 deletions contracts/mocks/ERC721FullMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import "../token/ERC721/ERC721Burnable.sol";

/**
* @title ERC721FullMock
* This mock just provides a public mint and burn functions for testing purposes,
* and a public setter for metadata URI
* This mock just provides public functions for setting metadata URI, getting all tokens of an owner,
* checking token existence, removal of a token from an address
*/
contract ERC721FullMock is ERC721Full, ERC721Mintable, ERC721MetadataMintable, ERC721Burnable {
constructor (string name, string symbol) public ERC721Mintable() ERC721Full(name, symbol) {}
Expand All @@ -17,6 +17,10 @@ contract ERC721FullMock is ERC721Full, ERC721Mintable, ERC721MetadataMintable, E
return _exists(tokenId);
}

function tokensOfOwner(address owner) public view returns (uint256[] memory) {
return _tokensOfOwner(owner);
}

function setTokenURI(uint256 tokenId, string uri) public {
_setTokenURI(tokenId, uri);
}
Expand Down
9 changes: 9 additions & 0 deletions contracts/token/ERC721/ERC721Enumerable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,13 @@ contract ERC721Enumerable is ERC165, ERC721, IERC721Enumerable {
_allTokensIndex[tokenId] = 0;
_allTokensIndex[lastToken] = tokenIndex;
}

/**
* @dev Gets the list of token IDs of the requested owner
* @param owner address owning the tokens
* @return uint256[] List of token IDs owned by the requested address
*/
function _tokensOfOwner(address owner) internal view returns (uint256[] storage) {
return _ownedTokens[owner];
}
}
8 changes: 8 additions & 0 deletions test/token/ERC721/ERC721Full.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,14 @@ contract('ERC721Full', function ([
});
});

describe('tokensOfOwner', function () {
it('returns total tokens of owner', async function () {
const tokenIds = await this.token.tokensOfOwner(owner);
tokenIds[0].should.be.bignumber.equal(firstTokenId);
tokenIds[1].should.be.bignumber.equal(secondTokenId);
});
});

describe('totalSupply', function () {
it('returns total token supply', async function () {
(await this.token.totalSupply()).should.be.bignumber.equal(2);
Expand Down

0 comments on commit ac8c493

Please sign in to comment.