Skip to content
Permalink
Browse files

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 <30843294+Aniket-Engg@users.noreply.github.com>
  • Loading branch information...
Aniket-Engg authored and frangio committed Dec 5, 2018
1 parent b7d56d5 commit 5caecf548c04c97955b8f0487ceb804fab0e2ca1
@@ -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) {}
@@ -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);
}
@@ -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];
}
}
@@ -138,6 +138,15 @@ contract('ERC721Full', function ([
});
});

describe('tokensOfOwner', function () {
it('returns total tokens of owner', async function () {
const tokenIds = await this.token.tokensOfOwner(owner);
tokenIds.length.should.equal(2);
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);

0 comments on commit 5caecf5

Please sign in to comment.
You can’t perform that action at this time.