Files
openzeppelin-contracts/test/token/ERC721/extensions/ERC721Consecutive.test.js
ernestognw ba8e296915 ERC721 _update
commit 2897abccc9
Author: Hadrien Croubois <hadrien.croubois@gmail.com>
Date:   Fri Jul 14 15:31:29 2023 +0200

    Update ERC721.sol

commit e26d5c0951
Author: Hadrien Croubois <hadrien.croubois@gmail.com>
Date:   Fri Jul 14 08:46:48 2023 +0200

    Update IERC721.sol

commit a475ffae0a
Author: Hadrien Croubois <hadrien.croubois@gmail.com>
Date:   Fri Jul 14 08:45:25 2023 +0200

    Update ERC721.sol

commit 20bb47f439
Author: Hadrien Croubois <hadrien.croubois@gmail.com>
Date:   Fri Jul 14 08:43:14 2023 +0200

    Update contracts/token/ERC721/ERC721.sol

commit f404802d55
Author: Hadrien Croubois <hadrien.croubois@gmail.com>
Date:   Fri Jul 14 08:41:30 2023 +0200

    Update ERC721.sol

commit b982e2a808
Author: Hadrien Croubois <hadrien.croubois@gmail.com>
Date:   Fri Jul 14 08:38:46 2023 +0200

    Update ERC721.behavior.js

commit ca32b459ec
Author: Francisco Giordano <fg@frang.io>
Date:   Thu Jul 13 19:14:15 2023 -0300

    fix _safeTransfer docs

commit caabbf3c46
Author: Francisco Giordano <fg@frang.io>
Date:   Thu Jul 13 19:08:36 2023 -0300

    improve warnings and notes

commit a023cad591
Author: Francisco Giordano <fg@frang.io>
Date:   Thu Jul 13 18:21:27 2023 -0300

    wrap long line

commit 5ce49a45fd
Author: Francisco Giordano <fg@frang.io>
Date:   Thu Jul 13 18:19:30 2023 -0300

    remove unnecessary solhint annotation

commit d0375301f1
Author: Francisco <fg@frang.io>
Date:   Thu Jul 13 18:17:24 2023 -0300

    Apply suggestions from code review

    Co-authored-by: Ernesto García <ernestognw@gmail.com>

commit 81aca96467
Author: Francisco <fg@frang.io>
Date:   Thu Jul 13 18:16:42 2023 -0300

    Update CHANGELOG.md

    Co-authored-by: Ernesto García <ernestognw@gmail.com>

commit 12f63b3b1b
Author: Hadrien Croubois <hadrien.croubois@gmail.com>
Date:   Thu Jul 13 17:28:04 2023 +0200

    add test

commit 08da709ba7
Author: Hadrien Croubois <hadrien.croubois@gmail.com>
Date:   Thu Jul 13 16:45:30 2023 +0200

    refactor _checkAuhtorized

commit 328b16bf8c
Author: Hadrien Croubois <hadrien.croubois@gmail.com>
Date:   Thu Jul 13 16:29:05 2023 +0200

    Authorised → Authorized

commit b29e573383
Author: Hadrien Croubois <hadrien.croubois@gmail.com>
Date:   Thu Jul 13 16:14:57 2023 +0200

    rename from → previousOwner

commit e996ba49d8
Author: Hadrien Croubois <hadrien.croubois@gmail.com>
Date:   Thu Jul 13 16:00:38 2023 +0200

    add ERC721 specific details in the 'How to upgrade from 4.x' section of the CHANGELOG

commit 20048ca3b9
Author: Hadrien Croubois <hadrien.croubois@gmail.com>
Date:   Thu Jul 13 11:00:11 2023 +0200

    Changes suggested in the PR discussions

commit 4c25b48803
Merge: d7a6aaf4 fb4d9510
Author: Hadrien Croubois <hadrien.croubois@gmail.com>
Date:   Thu Jul 13 10:00:55 2023 +0200

    Merge branch 'refactor/erc721-update-fnPointer' of https://github.com/Amxx/openzeppelin-contracts into refactor/erc721-update-fnPointer

commit d7a6aaf41f
Author: Hadrien Croubois <hadrien.croubois@gmail.com>
Date:   Thu Jul 13 10:00:50 2023 +0200

    remove _exists

commit fb4d9510de
Author: Hadrien Croubois <hadrien.croubois@gmail.com>
Date:   Thu Jul 13 10:00:39 2023 +0200

    Apply suggestions from code review

    Co-authored-by: Francisco <fg@frang.io>
    Co-authored-by: Ernesto García <ernestognw@gmail.com>

commit 10815081f7
Author: ernestognw <ernestognw@gmail.com>
Date:   Wed Jul 12 21:09:18 2023 -0600

    Lint

commit 9ba012005f
Author: ernestognw <ernestognw@gmail.com>
Date:   Wed Jul 12 20:28:50 2023 -0600

    Format _increaseBalance NatSpec

commit 7c3f1615b0
Author: Francisco <fg@frang.io>
Date:   Wed Jul 12 20:29:11 2023 -0300

    Update .changeset/eighty-lemons-shake.md

    Co-authored-by: Ernesto García <ernestognw@gmail.com>

commit 4516803058
Author: Hadrien Croubois <hadrien.croubois@gmail.com>
Date:   Wed Jul 12 17:15:48 2023 +0200

    make the safe function without a data field non virtual

commit e4b0e725df
Author: Hadrien Croubois <hadrien.croubois@gmail.com>
Date:   Wed Jul 12 16:56:07 2023 +0200

    use whenNotPaused in ERC721Pausable

commit b973d985a4
Author: Hadrien Croubois <hadrien.croubois@gmail.com>
Date:   Wed Jul 12 14:11:59 2023 +0200

    changesets

commit 7121ff7c5f
Merge: 2558c8fa de570d0d
Author: Hadrien Croubois <hadrien.croubois@gmail.com>
Date:   Wed Jul 12 13:46:07 2023 +0200

    Merge branch 'erc721-approve-0' into refactor/erc721-update-fnPointer

commit de570d0d14
Author: Hadrien Croubois <hadrien.croubois@gmail.com>
Date:   Wed Jul 12 13:42:46 2023 +0200

    allow using approve/_approve to clean approval

commit 2558c8fac8
Author: Hadrien Croubois <hadrien.croubois@gmail.com>
Date:   Wed Jul 12 10:16:55 2023 +0200

    change _increaseBalance type to uint128

commit 16f2f15673
Author: Hadrien Croubois <hadrien.croubois@gmail.com>
Date:   Wed Jul 12 10:01:30 2023 +0200

    remove _isApproedOrOwner in favor of _isApproved + refactor _checkOnERC721Received

commit 7e9d024d08
Author: Hadrien Croubois <hadrien.croubois@gmail.com>
Date:   Wed Jul 12 09:31:18 2023 +0200

    Apply suggestions from code review

    Co-authored-by: Ernesto García <ernestognw@gmail.com>

commit 1a9552009b
Author: Hadrien Croubois <hadrien.croubois@gmail.com>
Date:   Tue Jul 11 21:47:23 2023 +0200

    replace constraints with a simple operator check

commit bd0c52e34a
Author: Hadrien Croubois <hadrien.croubois@gmail.com>
Date:   Tue Jul 11 18:06:29 2023 +0200

    refactor constraint into an optionalChecks bitmap

commit 5ab254cf95
Author: Hadrien Croubois <hadrien.croubois@gmail.com>
Date:   Fri Jul 7 16:13:17 2023 +0200

    lint

commit 0bb98cb8c6
Merge: 562ddf56 7ccea54d
Author: Hadrien Croubois <hadrien.croubois@gmail.com>
Date:   Fri Jul 7 16:11:40 2023 +0200

    Merge branch 'master' into feature/Governor-storage

commit 562ddf566a
Author: Hadrien Croubois <hadrien.croubois@gmail.com>
Date:   Wed Jul 5 18:45:42 2023 +0200

    implement hybrid _update

commit 54cb3ca05f
Merge: c7303ec2 bb644589
Author: Hadrien Croubois <hadrien.croubois@gmail.com>
Date:   Mon Jul 3 21:09:30 2023 +0200

    Merge branch 'master' into refactor/erc721-update-fnPointer

commit c7303ec2ae
Author: Hadrien Croubois <hadrien.croubois@gmail.com>
Date:   Mon Jul 3 09:37:53 2023 +0200

    fix lint

commit 1cc7f54ab5
Merge: 78c280b5 06861dce
Author: Hadrien Croubois <hadrien.croubois@gmail.com>
Date:   Mon Jul 3 09:35:35 2023 +0200

    Merge remote-tracking branch 'upstream' into refactor/erc721-update-fnPointer

commit 78c280b537
Merge: e2fdbacd 04342118
Author: Hadrien Croubois <hadrien.croubois@gmail.com>
Date:   Fri Jun 30 18:40:55 2023 +0200

    Merge branch 'master' into refactor/erc721-update-fnPointer

commit e9f03bd211
Author: Francisco Giordano <fg@frang.io>
Date:   Fri Jun 30 12:09:15 2023 -0300

    Exclude address(0) in ERC721._isApprovedOrOwner

commit e2fdbacd63
Author: Hadrien Croubois <hadrien.croubois@gmail.com>
Date:   Wed Jun 21 22:09:50 2023 +0200

    fix lint

commit 7ec34355ae
Author: Hadrien Croubois <hadrien.croubois@gmail.com>
Date:   Wed Jun 21 17:59:22 2023 +0200

    Apply suggestions from code review

commit 1ed8f9ef2c
Author: Hadrien Croubois <hadrien.croubois@gmail.com>
Date:   Wed Jun 21 17:56:00 2023 +0200

    use __unsafe_increaseBalance to react to batch minting

commit a3526acdf2
Author: Hadrien Croubois <hadrien.croubois@gmail.com>
Date:   Thu Apr 27 16:37:40 2023 +0200

    Rebase ERC721._update on top of next-v5
2023-07-19 13:11:33 -06:00

222 lines
7.9 KiB
JavaScript

const { constants, expectEvent } = require('@openzeppelin/test-helpers');
const { expect } = require('chai');
const { sum } = require('../../../helpers/math');
const { expectRevertCustomError } = require('../../../helpers/customError');
const { ZERO_ADDRESS } = require('@openzeppelin/test-helpers/src/constants');
const ERC721ConsecutiveMock = artifacts.require('$ERC721ConsecutiveMock');
const ERC721ConsecutiveEnumerableMock = artifacts.require('$ERC721ConsecutiveEnumerableMock');
const ERC721ConsecutiveNoConstructorMintMock = artifacts.require('$ERC721ConsecutiveNoConstructorMintMock');
contract('ERC721Consecutive', function (accounts) {
const [user1, user2, user3, receiver] = accounts;
const name = 'Non Fungible Token';
const symbol = 'NFT';
const batches = [
{ receiver: user1, amount: 0 },
{ receiver: user1, amount: 1 },
{ receiver: user1, amount: 2 },
{ receiver: user2, amount: 5 },
{ receiver: user3, amount: 0 },
{ receiver: user1, amount: 7 },
];
const delegates = [user1, user3];
for (const offset of [0, 1, 42]) {
describe(`with offset ${offset}`, function () {
beforeEach(async function () {
this.token = await ERC721ConsecutiveMock.new(
name,
symbol,
offset,
delegates,
batches.map(({ receiver }) => receiver),
batches.map(({ amount }) => amount),
);
});
describe('minting during construction', function () {
it('events are emitted at construction', async function () {
let first = offset;
for (const batch of batches) {
if (batch.amount > 0) {
await expectEvent.inConstruction(this.token, 'ConsecutiveTransfer', {
fromTokenId: web3.utils.toBN(first),
toTokenId: web3.utils.toBN(first + batch.amount - 1),
fromAddress: constants.ZERO_ADDRESS,
toAddress: batch.receiver,
});
} else {
// expectEvent.notEmitted.inConstruction only looks at event name, and doesn't check the parameters
}
first += batch.amount;
}
});
it('ownership is set', async function () {
const owners = [
...Array(offset).fill(constants.ZERO_ADDRESS),
...batches.flatMap(({ receiver, amount }) => Array(amount).fill(receiver)),
];
for (const tokenId in owners) {
if (owners[tokenId] != constants.ZERO_ADDRESS) {
expect(await this.token.ownerOf(tokenId)).to.be.equal(owners[tokenId]);
}
}
});
it('balance & voting power are set', async function () {
for (const account of accounts) {
const balance = sum(...batches.filter(({ receiver }) => receiver === account).map(({ amount }) => amount));
expect(await this.token.balanceOf(account)).to.be.bignumber.equal(web3.utils.toBN(balance));
// If not delegated at construction, check before + do delegation
if (!delegates.includes(account)) {
expect(await this.token.getVotes(account)).to.be.bignumber.equal(web3.utils.toBN(0));
await this.token.delegate(account, { from: account });
}
// At this point all accounts should have delegated
expect(await this.token.getVotes(account)).to.be.bignumber.equal(web3.utils.toBN(balance));
}
});
it('reverts on consecutive minting to the zero address', async function () {
await expectRevertCustomError(
ERC721ConsecutiveMock.new(name, symbol, offset, delegates, [ZERO_ADDRESS], [10]),
'ERC721InvalidReceiver',
[ZERO_ADDRESS],
);
});
});
describe('minting after construction', function () {
it('consecutive minting is not possible after construction', async function () {
await expectRevertCustomError(this.token.$_mintConsecutive(user1, 10), 'ERC721ForbiddenBatchMint', []);
});
it('simple minting is possible after construction', async function () {
const tokenId = sum(...batches.map(b => b.amount)) + offset;
await expectRevertCustomError(this.token.ownerOf(tokenId), 'ERC721NonexistentToken', [tokenId]);
expectEvent(await this.token.$_mint(user1, tokenId), 'Transfer', {
from: constants.ZERO_ADDRESS,
to: user1,
tokenId: tokenId.toString(),
});
});
it('cannot mint a token that has been batched minted', async function () {
const tokenId = sum(...batches.map(b => b.amount)) + offset - 1;
expect(await this.token.ownerOf(tokenId)).to.be.not.equal(constants.ZERO_ADDRESS);
await expectRevertCustomError(this.token.$_mint(user1, tokenId), 'ERC721InvalidSender', [ZERO_ADDRESS]);
});
});
describe('ERC721 behavior', function () {
const tokenId = web3.utils.toBN(offset + 1);
it('core takes over ownership on transfer', async function () {
await this.token.transferFrom(user1, receiver, tokenId, { from: user1 });
expect(await this.token.ownerOf(tokenId)).to.be.equal(receiver);
});
it('tokens can be burned and re-minted #1', async function () {
expectEvent(await this.token.$_burn(tokenId, { from: user1 }), 'Transfer', {
from: user1,
to: constants.ZERO_ADDRESS,
tokenId,
});
await expectRevertCustomError(this.token.ownerOf(tokenId), 'ERC721NonexistentToken', [tokenId]);
expectEvent(await this.token.$_mint(user2, tokenId), 'Transfer', {
from: constants.ZERO_ADDRESS,
to: user2,
tokenId,
});
expect(await this.token.ownerOf(tokenId)).to.be.equal(user2);
});
it('tokens can be burned and re-minted #2', async function () {
const tokenId = web3.utils.toBN(sum(...batches.map(({ amount }) => amount)) + offset);
await expectRevertCustomError(this.token.ownerOf(tokenId), 'ERC721NonexistentToken', [tokenId]);
// mint
await this.token.$_mint(user1, tokenId);
expect(await this.token.ownerOf(tokenId), user1);
// burn
expectEvent(await this.token.$_burn(tokenId, { from: user1 }), 'Transfer', {
from: user1,
to: constants.ZERO_ADDRESS,
tokenId,
});
await expectRevertCustomError(this.token.ownerOf(tokenId), 'ERC721NonexistentToken', [tokenId]);
// re-mint
expectEvent(await this.token.$_mint(user2, tokenId), 'Transfer', {
from: constants.ZERO_ADDRESS,
to: user2,
tokenId,
});
expect(await this.token.ownerOf(tokenId), user2);
});
});
});
}
describe('invalid use', function () {
it('cannot mint a batch larger than 5000', async function () {
await expectRevertCustomError(
ERC721ConsecutiveMock.new(name, symbol, 0, [], [user1], ['5001']),
'ERC721ExceededMaxBatchMint',
[5000, 5001],
);
});
it('cannot use single minting during construction', async function () {
await expectRevertCustomError(
ERC721ConsecutiveNoConstructorMintMock.new(name, symbol),
'ERC721ForbiddenMint',
[],
);
});
it('cannot use single minting during construction', async function () {
await expectRevertCustomError(
ERC721ConsecutiveNoConstructorMintMock.new(name, symbol),
'ERC721ForbiddenMint',
[],
);
});
it('consecutive mint not compatible with enumerability', async function () {
await expectRevertCustomError(
ERC721ConsecutiveEnumerableMock.new(
name,
symbol,
batches.map(({ receiver }) => receiver),
batches.map(({ amount }) => amount),
),
'ERC721EnumerableForbiddenBatchMint',
[],
);
});
});
});