removed and tested unecessary gas cost

pull/1017/head
YZhenY 7 years ago
parent 78e39aa2ad
commit 054598ce7f
  1. 4
      contracts/mocks/ERC721TokenMock.sol
  2. 2
      contracts/token/ERC721/ERC721Token.sol
  3. 3372
      package-lock.json
  4. 26
      test/token/ERC721/ERC721Token.test.js

@ -24,4 +24,8 @@ contract ERC721TokenMock is ERC721Token {
function setTokenURI(uint256 _tokenId, string _uri) public {
super._setTokenURI(_tokenId, _uri);
}
function _removeTokenFrom(address _from, uint256 _tokenId) public {
super.removeTokenFrom(_from, _tokenId);
}
}

@ -161,7 +161,7 @@ contract ERC721Token is SupportsInterfaceWithLookup, ERC721BasicToken, ERC721 {
uint256 lastToken = ownedTokens[_from][lastTokenIndex];
ownedTokens[_from][tokenIndex] = lastToken;
ownedTokens[_from][lastTokenIndex] = 0;
// Note that this will handle single-element arrays. In that case, both tokenIndex and lastTokenIndex are going to
// be zero. Then we can make sure that we will remove _tokenId from the ownedTokens list since we are first swapping
// the lastToken to the first position, and then dropping the element placed in the last position of the list

3372
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -77,6 +77,32 @@ contract('ERC721Token', function (accounts) {
});
});
describe('removeTokenFrom', function () {
beforeEach(async function () {
await this.token._removeTokenFrom(creator, firstTokenId , {from:creator});
})
it('has been removed', async function () {
await assertRevert(this.token.tokenOfOwnerByIndex(creator, 1));
})
it('adjusts token list', async function () {
const token = await this.token.tokenOfOwnerByIndex(creator, 0);
token.toNumber().should.be.equal(secondTokenId);
})
it('adjusts owner count', async function () {
const count = await this.token.balanceOf(creator);
count.toNumber().should.be.equal(1);
})
it('doesnt adjust supply', async function () {
const total = await this.token.totalSupply();
total.toNumber().should.be.equal(2);
})
})
describe('metadata', function () {
const sampleUri = 'mock://mytoken';

Loading…
Cancel
Save