From 36280b28665e2c1c8a99935e1b24ad3dd80ac2da Mon Sep 17 00:00:00 2001 From: bpachai Date: Fri, 19 May 2023 17:46:44 +0530 Subject: [PATCH 1/3] feat: removes zero address check from balanceOf * updates ERC1155 contract and tests --- contracts/token/ERC1155/ERC1155.sol | 1 - test/token/ERC1155/ERC1155.behavior.js | 21 ++++++++------------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/contracts/token/ERC1155/ERC1155.sol b/contracts/token/ERC1155/ERC1155.sol index b20b711d505..445c3179d97 100644 --- a/contracts/token/ERC1155/ERC1155.sol +++ b/contracts/token/ERC1155/ERC1155.sol @@ -68,7 +68,6 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI { * - `account` cannot be the zero address. */ function balanceOf(address account, uint256 id) public view virtual override returns (uint256) { - require(account != address(0), "ERC1155: address zero is not a valid owner"); return _balances[id][account]; } diff --git a/test/token/ERC1155/ERC1155.behavior.js b/test/token/ERC1155/ERC1155.behavior.js index 96d448a9e2c..165ebce0264 100644 --- a/test/token/ERC1155/ERC1155.behavior.js +++ b/test/token/ERC1155/ERC1155.behavior.js @@ -20,11 +20,8 @@ function shouldBehaveLikeERC1155([minter, firstTokenHolder, secondTokenHolder, m describe('like an ERC1155', function () { describe('balanceOf', function () { - it('reverts when queried about the zero address', async function () { - await expectRevert( - this.token.balanceOf(ZERO_ADDRESS, firstTokenId), - 'ERC1155: address zero is not a valid owner', - ); + it('should return 0 when queried about the zero address', async function () { + expect(await this.token.balanceOf(ZERO_ADDRESS, firstTokenId)).to.be.bignumber.equal('0'); }); context("when accounts don't own tokens", function () { @@ -76,14 +73,12 @@ function shouldBehaveLikeERC1155([minter, firstTokenHolder, secondTokenHolder, m ); }); - it('reverts when one of the addresses is the zero address', async function () { - await expectRevert( - this.token.balanceOfBatch( - [firstTokenHolder, secondTokenHolder, ZERO_ADDRESS], - [firstTokenId, secondTokenId, unknownTokenId], - ), - 'ERC1155: address zero is not a valid owner', - ); + it('should return 0 as the balance when one of the addresses is the zero address', async function () { + const result = await this.token.balanceOfBatch([firstTokenHolder, secondTokenHolder, ZERO_ADDRESS], [firstTokenId, secondTokenId, unknownTokenId]); + expect(result).to.be.an('array'); + expect(result[0]).to.be.a.bignumber.equal('0'); + expect(result[1]).to.be.a.bignumber.equal('0'); + expect(result[2]).to.be.a.bignumber.equal('0'); }); context("when accounts don't own tokens", function () { From fd9c76a738222a4a0316231636c21ebb5a5a220e Mon Sep 17 00:00:00 2001 From: bpachai Date: Fri, 19 May 2023 18:08:22 +0530 Subject: [PATCH 2/3] fix: fixes linting issues --- test/token/ERC1155/ERC1155.behavior.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/token/ERC1155/ERC1155.behavior.js b/test/token/ERC1155/ERC1155.behavior.js index 165ebce0264..c41c69c6255 100644 --- a/test/token/ERC1155/ERC1155.behavior.js +++ b/test/token/ERC1155/ERC1155.behavior.js @@ -74,7 +74,10 @@ function shouldBehaveLikeERC1155([minter, firstTokenHolder, secondTokenHolder, m }); it('should return 0 as the balance when one of the addresses is the zero address', async function () { - const result = await this.token.balanceOfBatch([firstTokenHolder, secondTokenHolder, ZERO_ADDRESS], [firstTokenId, secondTokenId, unknownTokenId]); + const result = await this.token.balanceOfBatch( + [firstTokenHolder, secondTokenHolder, ZERO_ADDRESS], + [firstTokenId, secondTokenId, unknownTokenId], + ); expect(result).to.be.an('array'); expect(result[0]).to.be.a.bignumber.equal('0'); expect(result[1]).to.be.a.bignumber.equal('0'); From 89c0646b1cf547b051c3c5b14a204fbe74022f4a Mon Sep 17 00:00:00 2001 From: Francisco Giordano Date: Tue, 23 May 2023 19:41:45 -0300 Subject: [PATCH 3/3] add changeset --- .changeset/smooth-books-wink.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/smooth-books-wink.md diff --git a/.changeset/smooth-books-wink.md b/.changeset/smooth-books-wink.md new file mode 100644 index 00000000000..e5eb3fbeba7 --- /dev/null +++ b/.changeset/smooth-books-wink.md @@ -0,0 +1,5 @@ +--- +'openzeppelin-solidity': major +--- + +`ERC1155`: Remove check for address zero in `balanceOf`.