Skip to content

Commit 5caecf5

Browse files
Aniket-Enggfrangio
authored andcommitted
getter added for an array of tokens held by an owner (#1522)
* signing prefix added * Minor improvement * Tests changed * Successfully tested * Minor improvements * Minor improvements * Revert "Dangling commas are now required. (#1359)" This reverts commit a688977. * updates * fixes #1404 * approve failing test * suggested changes done * ISafeERC20 removed * conflict fixes * fixes #1512 * Update test/token/ERC721/ERC721Full.test.js Co-Authored-By: Aniket-Engg <[email protected]>
1 parent b7d56d5 commit 5caecf5

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

contracts/mocks/ERC721FullMock.sol

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import "../token/ERC721/ERC721Burnable.sol";
77

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

20+
function tokensOfOwner(address owner) public view returns (uint256[] memory) {
21+
return _tokensOfOwner(owner);
22+
}
23+
2024
function setTokenURI(uint256 tokenId, string uri) public {
2125
_setTokenURI(tokenId, uri);
2226
}

contracts/token/ERC721/ERC721Enumerable.sol

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,13 @@ contract ERC721Enumerable is ERC165, ERC721, IERC721Enumerable {
144144
_allTokensIndex[tokenId] = 0;
145145
_allTokensIndex[lastToken] = tokenIndex;
146146
}
147+
148+
/**
149+
* @dev Gets the list of token IDs of the requested owner
150+
* @param owner address owning the tokens
151+
* @return uint256[] List of token IDs owned by the requested address
152+
*/
153+
function _tokensOfOwner(address owner) internal view returns (uint256[] storage) {
154+
return _ownedTokens[owner];
155+
}
147156
}

test/token/ERC721/ERC721Full.test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,15 @@ contract('ERC721Full', function ([
138138
});
139139
});
140140

141+
describe('tokensOfOwner', function () {
142+
it('returns total tokens of owner', async function () {
143+
const tokenIds = await this.token.tokensOfOwner(owner);
144+
tokenIds.length.should.equal(2);
145+
tokenIds[0].should.be.bignumber.equal(firstTokenId);
146+
tokenIds[1].should.be.bignumber.equal(secondTokenId);
147+
});
148+
});
149+
141150
describe('totalSupply', function () {
142151
it('returns total token supply', async function () {
143152
(await this.token.totalSupply()).should.be.bignumber.equal(2);

0 commit comments

Comments
 (0)