Update ERC721 to latest 1.11.0 from OpenZeppelin-solidity (#11)
* Update ERC721 to latest 1.11.0 from OpenZeppelin-solidity * Hardcode supported interfaces instead of using lookup table. This avoids shifting storage when extending supports interface. * Update build artifacts * Fix linter errors
This commit is contained in:
committed by
GitHub
parent
8f4610e007
commit
c46f0353d1
21
test/helpers/makeInterfaceId.js
Normal file
21
test/helpers/makeInterfaceId.js
Normal file
@ -0,0 +1,21 @@
|
||||
import { soliditySha3 } from 'web3-utils';
|
||||
|
||||
const INTERFACE_ID_LENGTH = 4;
|
||||
|
||||
export default (interfaces = []) => {
|
||||
const interfaceIdBuffer = interfaces
|
||||
.map(methodSignature => soliditySha3(methodSignature)) // keccak256
|
||||
.map(h =>
|
||||
Buffer
|
||||
.from(h.substring(2), 'hex')
|
||||
.slice(0, 4) // bytes4()
|
||||
)
|
||||
.reduce((memo, bytes) => {
|
||||
for (let i = 0; i < INTERFACE_ID_LENGTH; i++) {
|
||||
memo[i] = memo[i] ^ bytes[i]; // xor
|
||||
}
|
||||
return memo;
|
||||
}, Buffer.alloc(INTERFACE_ID_LENGTH));
|
||||
|
||||
return `0x${interfaceIdBuffer.toString('hex')}`;
|
||||
};
|
||||
54
test/introspection/SupportsInterface.behavior.js
Normal file
54
test/introspection/SupportsInterface.behavior.js
Normal file
@ -0,0 +1,54 @@
|
||||
import makeInterfaceId from '../helpers/makeInterfaceId';
|
||||
|
||||
const INTERFACE_IDS = {
|
||||
ERC165: makeInterfaceId([
|
||||
'supportsInterface(bytes4)',
|
||||
]),
|
||||
ERC721: makeInterfaceId([
|
||||
'balanceOf(address)',
|
||||
'ownerOf(uint256)',
|
||||
'approve(address,uint256)',
|
||||
'getApproved(uint256)',
|
||||
'setApprovalForAll(address,bool)',
|
||||
'isApprovedForAll(address,address)',
|
||||
'transferFrom(address,address,uint256)',
|
||||
'safeTransferFrom(address,address,uint256)',
|
||||
'safeTransferFrom(address,address,uint256,bytes)',
|
||||
]),
|
||||
ERC721Enumerable: makeInterfaceId([
|
||||
'totalSupply()',
|
||||
'tokenOfOwnerByIndex(address,uint256)',
|
||||
'tokenByIndex(uint256)',
|
||||
]),
|
||||
ERC721Metadata: makeInterfaceId([
|
||||
'name()',
|
||||
'symbol()',
|
||||
'tokenURI(uint256)',
|
||||
]),
|
||||
ERC721Exists: makeInterfaceId([
|
||||
'exists(uint256)',
|
||||
]),
|
||||
};
|
||||
|
||||
export default function (interfaces = []) {
|
||||
describe('ERC165\'s supportsInterface(bytes4)', function () {
|
||||
beforeEach(function () {
|
||||
this.thing = this.mock || this.token;
|
||||
});
|
||||
|
||||
for (let k of interfaces) {
|
||||
const interfaceId = INTERFACE_IDS[k];
|
||||
describe(k, function () {
|
||||
it('should use less than 30k gas', async function () {
|
||||
const gasEstimate = await this.thing.supportsInterface.estimateGas(interfaceId);
|
||||
gasEstimate.should.be.lte(30000);
|
||||
});
|
||||
|
||||
it('is supported', async function () {
|
||||
const isSupported = await this.thing.supportsInterface(interfaceId);
|
||||
isSupported.should.eq(true);
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -1,3 +1,4 @@
|
||||
import shouldSupportInterfaces from '../../introspection/SupportsInterface.behavior';
|
||||
import assertRevert from '../../helpers/assertRevert';
|
||||
import decodeLogs from '../../helpers/decodeLogs';
|
||||
import sendTransaction from '../../helpers/sendTransaction';
|
||||
@ -17,30 +18,30 @@ export default function shouldBehaveLikeERC721BasicToken (accounts) {
|
||||
const unknownTokenId = 3;
|
||||
const creator = accounts[0];
|
||||
const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
|
||||
const RECEIVER_MAGIC_VALUE = '0xf0b9e5ba';
|
||||
const RECEIVER_MAGIC_VALUE = '0x150b7a02';
|
||||
|
||||
describe('like a ERC721BasicToken', function () {
|
||||
describe('like an ERC721BasicToken', function () {
|
||||
beforeEach(async function () {
|
||||
await this.token.mint(creator, firstTokenId, { from: creator });
|
||||
await this.token.mint(creator, secondTokenId, { from: creator });
|
||||
});
|
||||
|
||||
describe('balanceOf', function () {
|
||||
describe('when the given address owns some tokens', function () {
|
||||
context('when the given address owns some tokens', function () {
|
||||
it('returns the amount of tokens owned by the given address', async function () {
|
||||
const balance = await this.token.balanceOf(creator);
|
||||
balance.should.be.bignumber.equal(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the given address does not own any tokens', function () {
|
||||
context('when the given address does not own any tokens', function () {
|
||||
it('returns 0', async function () {
|
||||
const balance = await this.token.balanceOf(accounts[1]);
|
||||
balance.should.be.bignumber.equal(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when querying the zero address', function () {
|
||||
context('when querying the zero address', function () {
|
||||
it('throws', async function () {
|
||||
await assertRevert(this.token.balanceOf(0));
|
||||
});
|
||||
@ -48,7 +49,7 @@ export default function shouldBehaveLikeERC721BasicToken (accounts) {
|
||||
});
|
||||
|
||||
describe('exists', function () {
|
||||
describe('when the token exists', function () {
|
||||
context('when the token exists', function () {
|
||||
const tokenId = firstTokenId;
|
||||
|
||||
it('should return true', async function () {
|
||||
@ -57,7 +58,7 @@ export default function shouldBehaveLikeERC721BasicToken (accounts) {
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the token does not exist', function () {
|
||||
context('when the token does not exist', function () {
|
||||
const tokenId = unknownTokenId;
|
||||
|
||||
it('should return false', async function () {
|
||||
@ -68,7 +69,7 @@ export default function shouldBehaveLikeERC721BasicToken (accounts) {
|
||||
});
|
||||
|
||||
describe('ownerOf', function () {
|
||||
describe('when the given token ID was tracked by this token', function () {
|
||||
context('when the given token ID was tracked by this token', function () {
|
||||
const tokenId = firstTokenId;
|
||||
|
||||
it('returns the owner of the given token ID', async function () {
|
||||
@ -77,7 +78,7 @@ export default function shouldBehaveLikeERC721BasicToken (accounts) {
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the given token ID was not tracked by this token', function () {
|
||||
context('when the given token ID was not tracked by this token', function () {
|
||||
const tokenId = unknownTokenId;
|
||||
|
||||
it('reverts', async function () {
|
||||
@ -93,7 +94,7 @@ export default function shouldBehaveLikeERC721BasicToken (accounts) {
|
||||
const unauthorized = accounts[4];
|
||||
const tokenId = firstTokenId;
|
||||
const data = '0x42';
|
||||
|
||||
|
||||
let logs = null;
|
||||
|
||||
beforeEach(async function () {
|
||||
@ -114,17 +115,12 @@ export default function shouldBehaveLikeERC721BasicToken (accounts) {
|
||||
});
|
||||
|
||||
if (approved) {
|
||||
it('emits an approval and transfer events', async function () {
|
||||
logs.length.should.be.equal(2);
|
||||
logs[0].event.should.be.eq('Approval');
|
||||
logs[0].args._owner.should.be.equal(owner);
|
||||
logs[0].args._approved.should.be.equal(ZERO_ADDRESS);
|
||||
it('emit only a transfer event', async function () {
|
||||
logs.length.should.be.equal(1);
|
||||
logs[0].event.should.be.eq('Transfer');
|
||||
logs[0].args._from.should.be.equal(owner);
|
||||
logs[0].args._to.should.be.equal(this.to);
|
||||
logs[0].args._tokenId.should.be.bignumber.equal(tokenId);
|
||||
|
||||
logs[1].event.should.be.eq('Transfer');
|
||||
logs[1].args._from.should.be.equal(owner);
|
||||
logs[1].args._to.should.be.equal(this.to);
|
||||
logs[1].args._tokenId.should.be.bignumber.equal(tokenId);
|
||||
});
|
||||
} else {
|
||||
it('emits only a transfer event', async function () {
|
||||
@ -149,35 +145,35 @@ export default function shouldBehaveLikeERC721BasicToken (accounts) {
|
||||
|
||||
const newOwnerToken = await this.token.tokenOfOwnerByIndex(this.to, 0);
|
||||
newOwnerToken.toNumber().should.be.equal(tokenId);
|
||||
|
||||
|
||||
const previousOwnerToken = await this.token.tokenOfOwnerByIndex(owner, 0);
|
||||
previousOwnerToken.toNumber().should.not.be.equal(tokenId);
|
||||
});
|
||||
};
|
||||
|
||||
const shouldTransferTokensByUsers = function (transferFunction) {
|
||||
describe('when called by the owner', function () {
|
||||
context('when called by the owner', function () {
|
||||
beforeEach(async function () {
|
||||
({ logs } = await transferFunction.call(this, owner, this.to, tokenId, { from: owner }));
|
||||
});
|
||||
transferWasSuccessful({ owner, tokenId, approved });
|
||||
});
|
||||
|
||||
describe('when called by the approved individual', function () {
|
||||
context('when called by the approved individual', function () {
|
||||
beforeEach(async function () {
|
||||
({ logs } = await transferFunction.call(this, owner, this.to, tokenId, { from: approved }));
|
||||
});
|
||||
transferWasSuccessful({ owner, tokenId, approved });
|
||||
});
|
||||
|
||||
describe('when called by the operator', function () {
|
||||
context('when called by the operator', function () {
|
||||
beforeEach(async function () {
|
||||
({ logs } = await transferFunction.call(this, owner, this.to, tokenId, { from: operator }));
|
||||
});
|
||||
transferWasSuccessful({ owner, tokenId, approved });
|
||||
});
|
||||
|
||||
describe('when called by the owner without an approved user', function () {
|
||||
context('when called by the owner without an approved user', function () {
|
||||
beforeEach(async function () {
|
||||
await this.token.approve(ZERO_ADDRESS, tokenId, { from: owner });
|
||||
({ logs } = await transferFunction.call(this, owner, this.to, tokenId, { from: operator }));
|
||||
@ -185,7 +181,7 @@ export default function shouldBehaveLikeERC721BasicToken (accounts) {
|
||||
transferWasSuccessful({ owner, tokenId, approved: null });
|
||||
});
|
||||
|
||||
describe('when sent to the owner', function () {
|
||||
context('when sent to the owner', function () {
|
||||
beforeEach(async function () {
|
||||
({ logs } = await transferFunction.call(this, owner, owner, tokenId, { from: owner }));
|
||||
});
|
||||
@ -194,56 +190,51 @@ export default function shouldBehaveLikeERC721BasicToken (accounts) {
|
||||
const newOwner = await this.token.ownerOf(tokenId);
|
||||
newOwner.should.be.equal(owner);
|
||||
});
|
||||
|
||||
|
||||
it('clears the approval for the token ID', async function () {
|
||||
const approvedAccount = await this.token.getApproved(tokenId);
|
||||
approvedAccount.should.be.equal(ZERO_ADDRESS);
|
||||
});
|
||||
|
||||
it('emits an approval and transfer events', async function () {
|
||||
logs.length.should.be.equal(2);
|
||||
logs[0].event.should.be.eq('Approval');
|
||||
logs[0].args._owner.should.be.equal(owner);
|
||||
logs[0].args._approved.should.be.equal(ZERO_ADDRESS);
|
||||
|
||||
it('emits only a transfer event', async function () {
|
||||
logs.length.should.be.equal(1);
|
||||
logs[0].event.should.be.eq('Transfer');
|
||||
logs[0].args._from.should.be.equal(owner);
|
||||
logs[0].args._to.should.be.equal(owner);
|
||||
logs[0].args._tokenId.should.be.bignumber.equal(tokenId);
|
||||
|
||||
logs[1].event.should.be.eq('Transfer');
|
||||
logs[1].args._from.should.be.equal(owner);
|
||||
logs[1].args._to.should.be.equal(owner);
|
||||
logs[1].args._tokenId.should.be.bignumber.equal(tokenId);
|
||||
});
|
||||
|
||||
|
||||
it('keeps the owner balance', async function () {
|
||||
const ownerBalance = await this.token.balanceOf(owner);
|
||||
ownerBalance.should.be.bignumber.equal(2);
|
||||
});
|
||||
|
||||
|
||||
it('keeps same tokens by index', async function () {
|
||||
if (!this.token.tokenOfOwnerByIndex) return;
|
||||
const tokensListed = await Promise.all(_.range(2).map(i => this.token.tokenOfOwnerByIndex(owner, i)));
|
||||
tokensListed.map(t => t.toNumber()).should.have.members([firstTokenId, secondTokenId]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the address of the previous owner is incorrect', function () {
|
||||
|
||||
context('when the address of the previous owner is incorrect', function () {
|
||||
it('reverts', async function () {
|
||||
await assertRevert(transferFunction.call(this, unauthorized, this.to, tokenId, { from: owner }));
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the sender is not authorized for the token id', function () {
|
||||
context('when the sender is not authorized for the token id', function () {
|
||||
it('reverts', async function () {
|
||||
await assertRevert(transferFunction.call(this, owner, this.to, tokenId, { from: unauthorized }));
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the given token ID does not exist', function () {
|
||||
context('when the given token ID does not exist', function () {
|
||||
it('reverts', async function () {
|
||||
await assertRevert(transferFunction.call(this, owner, this.to, unknownTokenId, { from: owner }));
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the address to transfer the token to is the zero address', function () {
|
||||
context('when the address to transfer the token to is the zero address', function () {
|
||||
it('reverts', async function () {
|
||||
await assertRevert(transferFunction.call(this, owner, ZERO_ADDRESS, tokenId, { from: owner }));
|
||||
});
|
||||
@ -275,24 +266,50 @@ export default function shouldBehaveLikeERC721BasicToken (accounts) {
|
||||
describe('to a user account', function () {
|
||||
shouldTransferTokensByUsers(transferFun);
|
||||
});
|
||||
|
||||
|
||||
describe('to a valid receiver contract', function () {
|
||||
beforeEach(async function () {
|
||||
this.receiver = await ERC721Receiver.new(RECEIVER_MAGIC_VALUE, false);
|
||||
this.to = this.receiver.address;
|
||||
});
|
||||
|
||||
|
||||
shouldTransferTokensByUsers(transferFun);
|
||||
|
||||
|
||||
it('should call onERC721Received', async function () {
|
||||
const result = await transferFun.call(this, owner, this.to, tokenId, { from: owner });
|
||||
result.receipt.logs.length.should.be.equal(3);
|
||||
const [log] = decodeLogs([result.receipt.logs[2]], ERC721Receiver, this.receiver.address);
|
||||
result.receipt.logs.length.should.be.equal(2);
|
||||
const [log] = decodeLogs([result.receipt.logs[1]], ERC721Receiver, this.receiver.address);
|
||||
log.event.should.be.eq('Received');
|
||||
log.args._address.should.be.equal(owner);
|
||||
log.args._operator.should.be.equal(owner);
|
||||
log.args._from.should.be.equal(owner);
|
||||
log.args._tokenId.toNumber().should.be.equal(tokenId);
|
||||
log.args._data.should.be.equal(data);
|
||||
});
|
||||
|
||||
it('should call onERC721Received from approved', async function () {
|
||||
const result = await transferFun.call(this, owner, this.to, tokenId, { from: approved });
|
||||
result.receipt.logs.length.should.be.equal(2);
|
||||
const [log] = decodeLogs([result.receipt.logs[1]], ERC721Receiver, this.receiver.address);
|
||||
log.event.should.be.eq('Received');
|
||||
log.args._operator.should.be.equal(approved);
|
||||
log.args._from.should.be.equal(owner);
|
||||
log.args._tokenId.toNumber().should.be.equal(tokenId);
|
||||
log.args._data.should.be.equal(data);
|
||||
});
|
||||
|
||||
describe('with an invalid token id', function () {
|
||||
it('reverts', async function () {
|
||||
await assertRevert(
|
||||
transferFun.call(
|
||||
this,
|
||||
owner,
|
||||
this.to,
|
||||
unknownTokenId,
|
||||
{ from: owner },
|
||||
)
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
@ -357,21 +374,18 @@ export default function shouldBehaveLikeERC721BasicToken (accounts) {
|
||||
logs[0].args._tokenId.should.be.bignumber.equal(tokenId);
|
||||
});
|
||||
};
|
||||
|
||||
describe('when clearing approval', function () {
|
||||
describe('when there was no prior approval', function () {
|
||||
|
||||
context('when clearing approval', function () {
|
||||
context('when there was no prior approval', function () {
|
||||
beforeEach(async function () {
|
||||
({ logs } = await this.token.approve(ZERO_ADDRESS, tokenId, { from: sender }));
|
||||
});
|
||||
|
||||
itClearsApproval();
|
||||
|
||||
it('does not emit an approval event', async function () {
|
||||
logs.length.should.be.equal(0);
|
||||
});
|
||||
itEmitsApprovalEvent(ZERO_ADDRESS);
|
||||
});
|
||||
|
||||
describe('when there was a prior approval', function () {
|
||||
|
||||
context('when there was a prior approval', function () {
|
||||
beforeEach(async function () {
|
||||
await this.token.approve(to, tokenId, { from: sender });
|
||||
({ logs } = await this.token.approve(ZERO_ADDRESS, tokenId, { from: sender }));
|
||||
@ -382,8 +396,8 @@ export default function shouldBehaveLikeERC721BasicToken (accounts) {
|
||||
});
|
||||
});
|
||||
|
||||
describe('when approving a non-zero address', function () {
|
||||
describe('when there was no prior approval', function () {
|
||||
context('when approving a non-zero address', function () {
|
||||
context('when there was no prior approval', function () {
|
||||
beforeEach(async function () {
|
||||
({ logs } = await this.token.approve(to, tokenId, { from: sender }));
|
||||
});
|
||||
@ -392,7 +406,7 @@ export default function shouldBehaveLikeERC721BasicToken (accounts) {
|
||||
itEmitsApprovalEvent(to);
|
||||
});
|
||||
|
||||
describe('when there was a prior approval to the same address', function () {
|
||||
context('when there was a prior approval to the same address', function () {
|
||||
beforeEach(async function () {
|
||||
await this.token.approve(to, tokenId, { from: sender });
|
||||
({ logs } = await this.token.approve(to, tokenId, { from: sender }));
|
||||
@ -402,7 +416,7 @@ export default function shouldBehaveLikeERC721BasicToken (accounts) {
|
||||
itEmitsApprovalEvent(to);
|
||||
});
|
||||
|
||||
describe('when there was a prior approval to a different address', function () {
|
||||
context('when there was a prior approval to a different address', function () {
|
||||
beforeEach(async function () {
|
||||
await this.token.approve(accounts[2], tokenId, { from: sender });
|
||||
({ logs } = await this.token.approve(to, tokenId, { from: sender }));
|
||||
@ -413,26 +427,26 @@ export default function shouldBehaveLikeERC721BasicToken (accounts) {
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the address that receives the approval is the owner', function () {
|
||||
context('when the address that receives the approval is the owner', function () {
|
||||
it('reverts', async function () {
|
||||
await assertRevert(this.token.approve(sender, tokenId, { from: sender }));
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the sender does not own the given token ID', function () {
|
||||
|
||||
context('when the sender does not own the given token ID', function () {
|
||||
it('reverts', async function () {
|
||||
await assertRevert(this.token.approve(to, tokenId, { from: accounts[2] }));
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the sender is approved for the given token ID', function () {
|
||||
context('when the sender is approved for the given token ID', function () {
|
||||
it('reverts', async function () {
|
||||
await this.token.approve(accounts[2], tokenId, { from: sender });
|
||||
await assertRevert(this.token.approve(to, tokenId, { from: accounts[2] }));
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the sender is an operator', function () {
|
||||
context('when the sender is an operator', function () {
|
||||
const operator = accounts[2];
|
||||
beforeEach(async function () {
|
||||
await this.token.setApprovalForAll(operator, true, { from: sender });
|
||||
@ -443,7 +457,7 @@ export default function shouldBehaveLikeERC721BasicToken (accounts) {
|
||||
itEmitsApprovalEvent(to);
|
||||
});
|
||||
|
||||
describe('when the given token ID does not exist', function () {
|
||||
context('when the given token ID does not exist', function () {
|
||||
it('reverts', async function () {
|
||||
await assertRevert(this.token.approve(to, unknownTokenId, { from: sender }));
|
||||
});
|
||||
@ -453,10 +467,10 @@ export default function shouldBehaveLikeERC721BasicToken (accounts) {
|
||||
describe('setApprovalForAll', function () {
|
||||
const sender = creator;
|
||||
|
||||
describe('when the operator willing to approve is not the owner', function () {
|
||||
context('when the operator willing to approve is not the owner', function () {
|
||||
const operator = accounts[1];
|
||||
|
||||
describe('when there is no operator approval set by the sender', function () {
|
||||
context('when there is no operator approval set by the sender', function () {
|
||||
it('approves the operator', async function () {
|
||||
await this.token.setApprovalForAll(operator, true, { from: sender });
|
||||
|
||||
@ -475,7 +489,7 @@ export default function shouldBehaveLikeERC721BasicToken (accounts) {
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the operator was set as not approved', function () {
|
||||
context('when the operator was set as not approved', function () {
|
||||
beforeEach(async function () {
|
||||
await this.token.setApprovalForAll(operator, false, { from: sender });
|
||||
});
|
||||
@ -505,7 +519,7 @@ export default function shouldBehaveLikeERC721BasicToken (accounts) {
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the operator was already approved', function () {
|
||||
context('when the operator was already approved', function () {
|
||||
beforeEach(async function () {
|
||||
await this.token.setApprovalForAll(operator, true, { from: sender });
|
||||
});
|
||||
@ -529,7 +543,7 @@ export default function shouldBehaveLikeERC721BasicToken (accounts) {
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the operator is the owner', function () {
|
||||
context('when the operator is the owner', function () {
|
||||
const operator = creator;
|
||||
|
||||
it('reverts', async function () {
|
||||
@ -537,5 +551,11 @@ export default function shouldBehaveLikeERC721BasicToken (accounts) {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
shouldSupportInterfaces([
|
||||
'ERC165',
|
||||
'ERC721',
|
||||
'ERC721Exists',
|
||||
]);
|
||||
});
|
||||
};
|
||||
|
||||
@ -99,17 +99,6 @@ export default function shouldMintAndBurnERC721Token (accounts) {
|
||||
const approvedAccount = await this.token.getApproved(tokenId);
|
||||
approvedAccount.should.be.equal(ZERO_ADDRESS);
|
||||
});
|
||||
|
||||
it('emits an approval event', async function () {
|
||||
logs.length.should.be.equal(2);
|
||||
|
||||
logs[0].event.should.be.eq('Approval');
|
||||
logs[0].args._owner.should.be.equal(sender);
|
||||
logs[0].args._approved.should.be.equal(ZERO_ADDRESS);
|
||||
logs[0].args._tokenId.should.be.bignumber.equal(tokenId);
|
||||
|
||||
logs[1].event.should.be.eq('Transfer');
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the given token ID was not tracked by this contract', function () {
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import assertRevert from '../../helpers/assertRevert';
|
||||
import shouldBehaveLikeERC721BasicToken from './ERC721BasicToken.behaviour';
|
||||
import shouldMintAndBurnERC721Token from './ERC721MintBurn.behaviour';
|
||||
import shouldSupportInterfaces from '../../introspection/SupportsInterface.behavior';
|
||||
import _ from 'lodash';
|
||||
|
||||
const BigNumber = web3.BigNumber;
|
||||
@ -75,7 +76,7 @@ contract('ERC721Token', function (accounts) {
|
||||
await assertRevert(this.token.tokenByIndex(0));
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('metadata', function () {
|
||||
const sampleUri = 'mock://mytoken';
|
||||
|
||||
@ -122,7 +123,7 @@ contract('ERC721Token', function (accounts) {
|
||||
describe('tokenOfOwnerByIndex', function () {
|
||||
const owner = creator;
|
||||
const another = accounts[1];
|
||||
|
||||
|
||||
describe('when the given index is lower than the amount of tokens owned by the given address', function () {
|
||||
it('returns the token ID placed at the given index', async function () {
|
||||
const tokenId = await this.token.tokenOfOwnerByIndex(owner, 0);
|
||||
@ -178,14 +179,14 @@ contract('ERC721Token', function (accounts) {
|
||||
const owner = accounts[0];
|
||||
const newTokenId = 300;
|
||||
const anotherNewTokenId = 400;
|
||||
|
||||
|
||||
await this.token.burn(tokenId, { from: owner });
|
||||
await this.token.mint(owner, newTokenId, { from: owner });
|
||||
await this.token.mint(owner, anotherNewTokenId, { from: owner });
|
||||
|
||||
|
||||
const count = await this.token.totalSupply();
|
||||
count.toNumber().should.be.equal(3);
|
||||
|
||||
|
||||
const tokensListed = await Promise.all(_.range(3).map(i => this.token.tokenByIndex(i)));
|
||||
const expectedTokens = _.filter(
|
||||
[firstTokenId, secondTokenId, newTokenId, anotherNewTokenId],
|
||||
@ -196,4 +197,12 @@ contract('ERC721Token', function (accounts) {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
shouldSupportInterfaces([
|
||||
'ERC165',
|
||||
'ERC721',
|
||||
'ERC721Exists',
|
||||
'ERC721Enumerable',
|
||||
'ERC721Metadata',
|
||||
]);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user