|
@@ -42,167 +42,6 @@ contract('ERC20', function (accounts) {
|
|
|
expect(await this.token.decimals()).to.be.bignumber.equal('18');
|
|
|
});
|
|
|
|
|
|
- describe('decrease allowance', function () {
|
|
|
- describe('when the spender is not the zero address', function () {
|
|
|
- const spender = recipient;
|
|
|
-
|
|
|
- function shouldDecreaseApproval(value) {
|
|
|
- describe('when there was no approved value before', function () {
|
|
|
- it('reverts', async function () {
|
|
|
- const allowance = await this.token.allowance(initialHolder, spender);
|
|
|
- await expectRevertCustomError(
|
|
|
- this.token.decreaseAllowance(spender, value, { from: initialHolder }),
|
|
|
- 'ERC20FailedDecreaseAllowance',
|
|
|
- [spender, allowance, value],
|
|
|
- );
|
|
|
- });
|
|
|
- });
|
|
|
-
|
|
|
- describe('when the spender had an approved value', function () {
|
|
|
- const approvedValue = value;
|
|
|
-
|
|
|
- beforeEach(async function () {
|
|
|
- await this.token.approve(spender, approvedValue, { from: initialHolder });
|
|
|
- });
|
|
|
-
|
|
|
- it('emits an approval event', async function () {
|
|
|
- expectEvent(
|
|
|
- await this.token.decreaseAllowance(spender, approvedValue, { from: initialHolder }),
|
|
|
- 'Approval',
|
|
|
- { owner: initialHolder, spender: spender, value: new BN(0) },
|
|
|
- );
|
|
|
- });
|
|
|
-
|
|
|
- it('decreases the spender allowance subtracting the requested value', async function () {
|
|
|
- await this.token.decreaseAllowance(spender, approvedValue.subn(1), { from: initialHolder });
|
|
|
-
|
|
|
- expect(await this.token.allowance(initialHolder, spender)).to.be.bignumber.equal('1');
|
|
|
- });
|
|
|
-
|
|
|
- it('sets the allowance to zero when all allowance is removed', async function () {
|
|
|
- await this.token.decreaseAllowance(spender, approvedValue, { from: initialHolder });
|
|
|
- expect(await this.token.allowance(initialHolder, spender)).to.be.bignumber.equal('0');
|
|
|
- });
|
|
|
-
|
|
|
- it('reverts when more than the full allowance is removed', async function () {
|
|
|
- await expectRevertCustomError(
|
|
|
- this.token.decreaseAllowance(spender, approvedValue.addn(1), { from: initialHolder }),
|
|
|
- 'ERC20FailedDecreaseAllowance',
|
|
|
- [spender, approvedValue, approvedValue.addn(1)],
|
|
|
- );
|
|
|
- });
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- describe('when the sender has enough balance', function () {
|
|
|
- const value = initialSupply;
|
|
|
-
|
|
|
- shouldDecreaseApproval(value);
|
|
|
- });
|
|
|
-
|
|
|
- describe('when the sender does not have enough balance', function () {
|
|
|
- const value = initialSupply.addn(1);
|
|
|
-
|
|
|
- shouldDecreaseApproval(value);
|
|
|
- });
|
|
|
- });
|
|
|
-
|
|
|
- describe('when the spender is the zero address', function () {
|
|
|
- const value = initialSupply;
|
|
|
- const spender = ZERO_ADDRESS;
|
|
|
-
|
|
|
- it('reverts', async function () {
|
|
|
- await expectRevertCustomError(
|
|
|
- this.token.decreaseAllowance(spender, value, { from: initialHolder }),
|
|
|
- 'ERC20FailedDecreaseAllowance',
|
|
|
- [spender, 0, value],
|
|
|
- );
|
|
|
- });
|
|
|
- });
|
|
|
- });
|
|
|
-
|
|
|
- describe('increase allowance', function () {
|
|
|
- const value = initialSupply;
|
|
|
-
|
|
|
- describe('when the spender is not the zero address', function () {
|
|
|
- const spender = recipient;
|
|
|
-
|
|
|
- describe('when the sender has enough balance', function () {
|
|
|
- it('emits an approval event', async function () {
|
|
|
- expectEvent(await this.token.increaseAllowance(spender, value, { from: initialHolder }), 'Approval', {
|
|
|
- owner: initialHolder,
|
|
|
- spender: spender,
|
|
|
- value: value,
|
|
|
- });
|
|
|
- });
|
|
|
-
|
|
|
- describe('when there was no approved value before', function () {
|
|
|
- it('approves the requested value', async function () {
|
|
|
- await this.token.increaseAllowance(spender, value, { from: initialHolder });
|
|
|
-
|
|
|
- expect(await this.token.allowance(initialHolder, spender)).to.be.bignumber.equal(value);
|
|
|
- });
|
|
|
- });
|
|
|
-
|
|
|
- describe('when the spender had an approved value', function () {
|
|
|
- beforeEach(async function () {
|
|
|
- await this.token.approve(spender, new BN(1), { from: initialHolder });
|
|
|
- });
|
|
|
-
|
|
|
- it('increases the spender allowance adding the requested value', async function () {
|
|
|
- await this.token.increaseAllowance(spender, value, { from: initialHolder });
|
|
|
-
|
|
|
- expect(await this.token.allowance(initialHolder, spender)).to.be.bignumber.equal(value.addn(1));
|
|
|
- });
|
|
|
- });
|
|
|
- });
|
|
|
-
|
|
|
- describe('when the sender does not have enough balance', function () {
|
|
|
- const value = initialSupply.addn(1);
|
|
|
-
|
|
|
- it('emits an approval event', async function () {
|
|
|
- expectEvent(await this.token.increaseAllowance(spender, value, { from: initialHolder }), 'Approval', {
|
|
|
- owner: initialHolder,
|
|
|
- spender: spender,
|
|
|
- value: value,
|
|
|
- });
|
|
|
- });
|
|
|
-
|
|
|
- describe('when there was no approved value before', function () {
|
|
|
- it('approves the requested value', async function () {
|
|
|
- await this.token.increaseAllowance(spender, value, { from: initialHolder });
|
|
|
-
|
|
|
- expect(await this.token.allowance(initialHolder, spender)).to.be.bignumber.equal(value);
|
|
|
- });
|
|
|
- });
|
|
|
-
|
|
|
- describe('when the spender had an approved value', function () {
|
|
|
- beforeEach(async function () {
|
|
|
- await this.token.approve(spender, new BN(1), { from: initialHolder });
|
|
|
- });
|
|
|
-
|
|
|
- it('increases the spender allowance adding the requested value', async function () {
|
|
|
- await this.token.increaseAllowance(spender, value, { from: initialHolder });
|
|
|
-
|
|
|
- expect(await this.token.allowance(initialHolder, spender)).to.be.bignumber.equal(value.addn(1));
|
|
|
- });
|
|
|
- });
|
|
|
- });
|
|
|
- });
|
|
|
-
|
|
|
- describe('when the spender is the zero address', function () {
|
|
|
- const spender = ZERO_ADDRESS;
|
|
|
-
|
|
|
- it('reverts', async function () {
|
|
|
- await expectRevertCustomError(
|
|
|
- this.token.increaseAllowance(spender, value, { from: initialHolder }),
|
|
|
- 'ERC20InvalidSpender',
|
|
|
- [ZERO_ADDRESS],
|
|
|
- );
|
|
|
- });
|
|
|
- });
|
|
|
- });
|
|
|
-
|
|
|
describe('_mint', function () {
|
|
|
const value = new BN(50);
|
|
|
it('rejects a null account', async function () {
|