Removes zero address check from balanceOf in ERC1155 (#4263)
Co-authored-by: bpachai <bpachai@v2soft.com> Co-authored-by: Francisco Giordano <fg@frang.io>
This commit is contained in:
committed by
GitHub
parent
7e814a3074
commit
cbc6145f5f
5
.changeset/smooth-books-wink.md
Normal file
5
.changeset/smooth-books-wink.md
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'openzeppelin-solidity': major
|
||||||
|
---
|
||||||
|
|
||||||
|
`ERC1155`: Remove check for address zero in `balanceOf`.
|
||||||
@ -68,7 +68,6 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
|
|||||||
* - `account` cannot be the zero address.
|
* - `account` cannot be the zero address.
|
||||||
*/
|
*/
|
||||||
function balanceOf(address account, uint256 id) public view virtual override returns (uint256) {
|
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];
|
return _balances[id][account];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -20,11 +20,8 @@ function shouldBehaveLikeERC1155([minter, firstTokenHolder, secondTokenHolder, m
|
|||||||
|
|
||||||
describe('like an ERC1155', function () {
|
describe('like an ERC1155', function () {
|
||||||
describe('balanceOf', function () {
|
describe('balanceOf', function () {
|
||||||
it('reverts when queried about the zero address', async function () {
|
it('should return 0 when queried about the zero address', async function () {
|
||||||
await expectRevert(
|
expect(await this.token.balanceOf(ZERO_ADDRESS, firstTokenId)).to.be.bignumber.equal('0');
|
||||||
this.token.balanceOf(ZERO_ADDRESS, firstTokenId),
|
|
||||||
'ERC1155: address zero is not a valid owner',
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
context("when accounts don't own tokens", function () {
|
context("when accounts don't own tokens", function () {
|
||||||
@ -76,14 +73,15 @@ function shouldBehaveLikeERC1155([minter, firstTokenHolder, secondTokenHolder, m
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('reverts when one of the addresses is the zero address', async function () {
|
it('should return 0 as the balance when one of the addresses is the zero address', async function () {
|
||||||
await expectRevert(
|
const result = await this.token.balanceOfBatch(
|
||||||
this.token.balanceOfBatch(
|
[firstTokenHolder, secondTokenHolder, ZERO_ADDRESS],
|
||||||
[firstTokenHolder, secondTokenHolder, ZERO_ADDRESS],
|
[firstTokenId, secondTokenId, unknownTokenId],
|
||||||
[firstTokenId, secondTokenId, unknownTokenId],
|
|
||||||
),
|
|
||||||
'ERC1155: address zero is not a valid owner',
|
|
||||||
);
|
);
|
||||||
|
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 () {
|
context("when accounts don't own tokens", function () {
|
||||||
|
|||||||
Reference in New Issue
Block a user