Fix ERC20._update (#3921)
Co-authored-by: Francisco <frangio.1@gmail.com> Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com>
This commit is contained in:
@ -250,7 +250,7 @@ contract('ERC20', function (accounts) {
|
||||
describe('for a non zero account', function () {
|
||||
it('rejects burning more than balance', async function () {
|
||||
await expectRevert(this.token.burn(
|
||||
initialHolder, initialSupply.addn(1)), 'ERC20: burn amount exceeds balance',
|
||||
initialHolder, initialSupply.addn(1)), 'ERC20: transfer amount exceeds balance',
|
||||
);
|
||||
});
|
||||
|
||||
@ -287,6 +287,49 @@ contract('ERC20', function (accounts) {
|
||||
});
|
||||
});
|
||||
|
||||
describe('_update', function () {
|
||||
const amount = new BN(1);
|
||||
|
||||
it('from is the zero address', async function () {
|
||||
const balanceBefore = await this.token.balanceOf(initialHolder);
|
||||
const totalSupply = await this.token.totalSupply();
|
||||
|
||||
expectEvent(
|
||||
await this.token.update(ZERO_ADDRESS, initialHolder, amount),
|
||||
'Transfer',
|
||||
{ from: ZERO_ADDRESS, to: initialHolder, value: amount },
|
||||
);
|
||||
expect(await this.token.totalSupply()).to.be.bignumber.equal(totalSupply.add(amount));
|
||||
expect(await this.token.balanceOf(initialHolder)).to.be.bignumber.equal(balanceBefore.add(amount));
|
||||
});
|
||||
|
||||
it('to is the zero address', async function () {
|
||||
const balanceBefore = await this.token.balanceOf(initialHolder);
|
||||
const totalSupply = await this.token.totalSupply();
|
||||
|
||||
expectEvent(
|
||||
await this.token.update(initialHolder, ZERO_ADDRESS, amount),
|
||||
'Transfer',
|
||||
{ from: initialHolder, to: ZERO_ADDRESS, value: amount },
|
||||
);
|
||||
expect(await this.token.totalSupply()).to.be.bignumber.equal(totalSupply.sub(amount));
|
||||
expect(await this.token.balanceOf(initialHolder)).to.be.bignumber.equal(balanceBefore.sub(amount));
|
||||
});
|
||||
|
||||
it('from and to are the zero address', async function () {
|
||||
const totalSupply = await this.token.totalSupply();
|
||||
|
||||
await this.token.update(ZERO_ADDRESS, ZERO_ADDRESS, amount);
|
||||
|
||||
expect(await this.token.totalSupply()).to.be.bignumber.equal(totalSupply);
|
||||
expectEvent(
|
||||
await this.token.update(ZERO_ADDRESS, ZERO_ADDRESS, amount),
|
||||
'Transfer',
|
||||
{ from: ZERO_ADDRESS, to: ZERO_ADDRESS, value: amount },
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('_transfer', function () {
|
||||
shouldBehaveLikeERC20Transfer('ERC20', initialHolder, recipient, initialSupply, function (from, to, amount) {
|
||||
return this.token.transferInternal(from, to, amount);
|
||||
|
||||
@ -38,7 +38,7 @@ function shouldBehaveLikeERC20Burnable (owner, initialBalance, [burner]) {
|
||||
|
||||
it('reverts', async function () {
|
||||
await expectRevert(this.token.burn(amount, { from: owner }),
|
||||
'ERC20: burn amount exceeds balance',
|
||||
'ERC20: transfer amount exceeds balance',
|
||||
);
|
||||
});
|
||||
});
|
||||
@ -86,7 +86,7 @@ function shouldBehaveLikeERC20Burnable (owner, initialBalance, [burner]) {
|
||||
it('reverts', async function () {
|
||||
await this.token.approve(burner, amount, { from: owner });
|
||||
await expectRevert(this.token.burnFrom(owner, amount, { from: burner }),
|
||||
'ERC20: burn amount exceeds balance',
|
||||
'ERC20: transfer amount exceeds balance',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@ -82,7 +82,7 @@ contract('ERC20FlashMint', function (accounts) {
|
||||
const data = this.token.contract.methods.transfer(other, 10).encodeABI();
|
||||
await expectRevert(
|
||||
this.token.flashLoan(receiver.address, this.token.address, loanAmount, data),
|
||||
'ERC20: burn amount exceeds balance',
|
||||
'ERC20: transfer amount exceeds balance',
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@ -105,7 +105,7 @@ contract('ERC20', function (accounts) {
|
||||
it('missing balance', async function () {
|
||||
await expectRevert(
|
||||
this.token.withdrawTo(initialHolder, MAX_UINT256, { from: initialHolder }),
|
||||
'ERC20: burn amount exceeds balance',
|
||||
'ERC20: transfer amount exceeds balance',
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user