* rename ERC20 to IERC20 * move ERC20.sol to IERC20.sol * rename StandardToken to ERC20 * rename StandardTokenMock to ERC20Mock * move StandardToken.sol to ERC20.sol, likewise test and mock files * rename MintableToken to ERC20Mintable * move MintableToken.sol to ERC20Mintable.sol, likewise test and mock files * rename BurnableToken to ERC20Burnable * move BurnableToken.sol to ERC20Burnable.sol, likewise for related files * rename CappedToken to ERC20Capped * move CappedToken.sol to ERC20Capped.sol, likewise for related files * rename PausableToken to ERC20Pausable * move PausableToken.sol to ERC20Pausable.sol, likewise for related files * rename DetailedERC20 to ERC20Detailed * move DetailedERC20.sol to ERC20Detailed.sol, likewise for related files * rename ERC721 to IERC721, and likewise for other related interfaces * move ERC721.sol to IERC721.sol, likewise for other 721 interfaces * rename ERC721Token to ERC721 * move ERC721Token.sol to ERC721.sol, likewise for related files * rename ERC721BasicToken to ERC721Basic * move ERC721BasicToken.sol to ERC721Basic.sol, likewise for related files * rename ERC721PausableToken to ERC721Pausable * move ERC721PausableToken.sol to ERC721Pausable.sol * rename ERC165 to IERC165 * move ERC165.sol to IERC165.sol * amend comment that ERC20 is based on FirstBlood * fix comments mentioning IERC721Receiver
111 lines
3.7 KiB
JavaScript
111 lines
3.7 KiB
JavaScript
const { assertRevert } = require('../../helpers/assertRevert');
|
|
const BigNumber = web3.BigNumber;
|
|
|
|
require('chai')
|
|
.use(require('chai-bignumber')(BigNumber))
|
|
.should();
|
|
|
|
function shouldBehaveLikeMintAndBurnERC721 (accounts) {
|
|
const firstTokenId = 1;
|
|
const secondTokenId = 2;
|
|
const unknownTokenId = 3;
|
|
const creator = accounts[0];
|
|
const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
|
|
|
|
describe('like a mintable and burnable ERC721', function () {
|
|
beforeEach(async function () {
|
|
await this.token.mint(creator, firstTokenId, { from: creator });
|
|
await this.token.mint(creator, secondTokenId, { from: creator });
|
|
});
|
|
|
|
describe('mint', function () {
|
|
const to = accounts[1];
|
|
const tokenId = unknownTokenId;
|
|
let logs = null;
|
|
|
|
describe('when successful', function () {
|
|
beforeEach(async function () {
|
|
const result = await this.token.mint(to, tokenId);
|
|
logs = result.logs;
|
|
});
|
|
|
|
it('assigns the token to the new owner', async function () {
|
|
(await this.token.ownerOf(tokenId)).should.be.equal(to);
|
|
});
|
|
|
|
it('increases the balance of its owner', async function () {
|
|
(await this.token.balanceOf(to)).should.be.bignumber.equal(1);
|
|
});
|
|
|
|
it('emits a transfer event', async function () {
|
|
logs.length.should.be.equal(1);
|
|
logs[0].event.should.be.equal('Transfer');
|
|
logs[0].args._from.should.be.equal(ZERO_ADDRESS);
|
|
logs[0].args._to.should.be.equal(to);
|
|
logs[0].args._tokenId.should.be.bignumber.equal(tokenId);
|
|
});
|
|
});
|
|
|
|
describe('when the given owner address is the zero address', function () {
|
|
it('reverts', async function () {
|
|
await assertRevert(this.token.mint(ZERO_ADDRESS, tokenId));
|
|
});
|
|
});
|
|
|
|
describe('when the given token ID was already tracked by this contract', function () {
|
|
it('reverts', async function () {
|
|
await assertRevert(this.token.mint(accounts[1], firstTokenId));
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('burn', function () {
|
|
const tokenId = firstTokenId;
|
|
const sender = creator;
|
|
let logs = null;
|
|
|
|
describe('when successful', function () {
|
|
beforeEach(async function () {
|
|
const result = await this.token.burn(tokenId, { from: sender });
|
|
logs = result.logs;
|
|
});
|
|
|
|
it('burns the given token ID and adjusts the balance of the owner', async function () {
|
|
await assertRevert(this.token.ownerOf(tokenId));
|
|
(await this.token.balanceOf(sender)).should.be.bignumber.equal(1);
|
|
});
|
|
|
|
it('emits a burn event', async function () {
|
|
logs.length.should.be.equal(1);
|
|
logs[0].event.should.be.equal('Transfer');
|
|
logs[0].args._from.should.be.equal(sender);
|
|
logs[0].args._to.should.be.equal(ZERO_ADDRESS);
|
|
logs[0].args._tokenId.should.be.bignumber.equal(tokenId);
|
|
});
|
|
});
|
|
|
|
describe('when there is a previous approval', function () {
|
|
beforeEach(async function () {
|
|
await this.token.approve(accounts[1], tokenId, { from: sender });
|
|
const result = await this.token.burn(tokenId, { from: sender });
|
|
logs = result.logs;
|
|
});
|
|
|
|
it('clears the approval', async function () {
|
|
(await this.token.getApproved(tokenId)).should.be.equal(ZERO_ADDRESS);
|
|
});
|
|
});
|
|
|
|
describe('when the given token ID was not tracked by this contract', function () {
|
|
it('reverts', async function () {
|
|
await assertRevert(this.token.burn(unknownTokenId, { from: creator }));
|
|
});
|
|
});
|
|
});
|
|
});
|
|
}
|
|
|
|
module.exports = {
|
|
shouldBehaveLikeMintAndBurnERC721,
|
|
};
|