Do not reduce approval on transferFrom if current allowance is type(uint256).max (#3085)

* add feature request #3084

* Update contracts/token/ERC20/ERC20.sol

Co-authored-by: Francisco Giordano <frangio.1@gmail.com>

* Add changelog note

* add documentation

* test unlimitted allowance and add ERC777 unlimitted allowance

* reference PR in changelog

* documentation IERC20 -> ERC20

* use asciidoc note syntax

* use asciidoc note syntax

* typo

* typos

Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com>
Co-authored-by: Francisco Giordano <frangio.1@gmail.com>
This commit is contained in:
0xclaudeshannon
2022-01-10 18:08:33 -05:00
committed by GitHub
parent fd7c4ba8f0
commit 80d8da0564
4 changed files with 45 additions and 6 deletions

View File

@ -1,6 +1,6 @@
const { BN, constants, expectEvent, expectRevert } = require('@openzeppelin/test-helpers');
const { expect } = require('chai');
const { ZERO_ADDRESS } = constants;
const { ZERO_ADDRESS, MAX_UINT256 } = constants;
function shouldBehaveLikeERC20 (errorPrefix, initialSupply, initialHolder, recipient, anotherAccount) {
describe('total supply', function () {
@ -128,6 +128,25 @@ function shouldBehaveLikeERC20 (errorPrefix, initialSupply, initialHolder, recip
});
});
});
describe('when the spender has unlimited allowance', function () {
beforeEach(async function () {
await this.token.approve(spender, MAX_UINT256, { from: initialHolder });
});
it('does not decrease the spender allowance', async function () {
await this.token.transferFrom(tokenOwner, to, 1, { from: spender });
expect(await this.token.allowance(tokenOwner, spender)).to.be.bignumber.equal(MAX_UINT256);
});
it('does not emit an approval event', async function () {
expectEvent.notEmitted(
await this.token.transferFrom(tokenOwner, to, 1, { from: spender }),
'Approval',
);
});
});
});
describe('when the recipient is the zero address', function () {