Files
openzeppelin-contracts/test/token/ERC721/ERC721MintBurn.behavior.js
Nicolás Venturo 3e82db2f6f Migration to truffle 5 (and web3 1.0 (and BN)) (#1601)
* Now compiling using truffle 5.

* Migrated some test files, missing BN scientific notation usage.

* Now using BN time values.

* Migrate ERC20 tests.

* Migrate all ERC20 tests.

* Migrate utils, payment and ownership tests.

* All tests save ERC721 migrated.

* Migrated ERC721 tests.

* Fix lint errors.

* Delete old test helpers.

* Fix remaining crowdsale tests.

* Fix signature bouncer tests.

* Update how constants is used.

* Compile script pre-removes the build dir.

* Fix SafeMath tests.

* Revert "Compile script pre-removes the build dir."

This reverts commit 247e745113.

* Fix linter errors.

* Upgrade openzeppelin-test-helpers dependency.

* Update openzeppelin-test-helpers dependency.

* Define math constants globally.

* Remove unnecessary ether unit.

* Roll back reduced ether amounts in tests.

* Remove unnecessary toNumber conversions.

* Delete compile script.

* Fixed failing test.
2019-01-14 19:11:55 -03:00

120 lines
3.8 KiB
JavaScript

const { BN, constants, expectEvent, shouldFail } = require('openzeppelin-test-helpers');
const { ZERO_ADDRESS } = constants;
function shouldBehaveLikeMintAndBurnERC721 (
creator,
minter,
[owner, newOwner, approved, anyone]
) {
const firstTokenId = new BN(1);
const secondTokenId = new BN(2);
const thirdTokenId = new BN(3);
const unknownTokenId = new BN(4);
const MOCK_URI = 'https://example.com';
describe('like a mintable and burnable ERC721', function () {
beforeEach(async function () {
await this.token.mint(owner, firstTokenId, { from: minter });
await this.token.mint(owner, secondTokenId, { from: minter });
});
describe('mint', function () {
let logs = null;
describe('when successful', function () {
beforeEach(async function () {
const result = await this.token.mint(newOwner, thirdTokenId, { from: minter });
logs = result.logs;
});
it('assigns the token to the new owner', async function () {
(await this.token.ownerOf(thirdTokenId)).should.be.equal(newOwner);
});
it('increases the balance of its owner', async function () {
(await this.token.balanceOf(newOwner)).should.be.bignumber.equal('1');
});
it('emits a transfer and minted event', async function () {
expectEvent.inLogs(logs, 'Transfer', {
from: ZERO_ADDRESS,
to: newOwner,
tokenId: thirdTokenId,
});
});
});
describe('when the given owner address is the zero address', function () {
it('reverts', async function () {
await shouldFail.reverting(this.token.mint(ZERO_ADDRESS, thirdTokenId, { from: minter }));
});
});
describe('when the given token ID was already tracked by this contract', function () {
it('reverts', async function () {
await shouldFail.reverting(this.token.mint(owner, firstTokenId, { from: minter }));
});
});
});
describe('mintWithTokenURI', function () {
it('can mint with a tokenUri', async function () {
await this.token.mintWithTokenURI(newOwner, thirdTokenId, MOCK_URI, {
from: minter,
});
});
});
describe('burn', function () {
const tokenId = firstTokenId;
let logs = null;
describe('when successful', function () {
beforeEach(async function () {
const result = await this.token.burn(tokenId, { from: owner });
logs = result.logs;
});
it('burns the given token ID and adjusts the balance of the owner', async function () {
await shouldFail.reverting(this.token.ownerOf(tokenId));
(await this.token.balanceOf(owner)).should.be.bignumber.equal('1');
});
it('emits a burn event', async function () {
expectEvent.inLogs(logs, 'Transfer', {
from: owner,
to: ZERO_ADDRESS,
tokenId: tokenId,
});
});
});
describe('when there is a previous approval burned', function () {
beforeEach(async function () {
await this.token.approve(approved, tokenId, { from: owner });
const result = await this.token.burn(tokenId, { from: owner });
logs = result.logs;
});
context('getApproved', function () {
it('reverts', async function () {
await shouldFail.reverting(this.token.getApproved(tokenId));
});
});
});
describe('when the given token ID was not tracked by this contract', function () {
it('reverts', async function () {
await shouldFail.reverting(
this.token.burn(unknownTokenId, { from: creator })
);
});
});
});
});
}
module.exports = {
shouldBehaveLikeMintAndBurnERC721,
};