re-enabling safemath revert reasons in ERC20, ERC777 and ERC1155 (#2491)

* re-enabling safemath revert reasons in ERC20 and ERC1155

* adding revert messages to ERC777

* removing uncheck block
This commit is contained in:
Hadrien Croubois
2021-02-01 11:00:16 +01:00
committed by GitHub
parent 60205944bb
commit 5db7413827
11 changed files with 84 additions and 55 deletions

View File

@ -208,7 +208,7 @@ function shouldBehaveLikeERC1155 ([minter, firstTokenHolder, secondTokenHolder,
});
it('reverts when transferring more than balance', async function () {
await expectRevert.unspecified(
await expectRevert(
this.token.safeTransferFrom(
multiTokenHolder,
recipient,
@ -217,6 +217,7 @@ function shouldBehaveLikeERC1155 ([minter, firstTokenHolder, secondTokenHolder,
'0x',
{ from: multiTokenHolder },
),
'ERC1155: insufficient balance for transfer',
);
});
@ -463,13 +464,14 @@ function shouldBehaveLikeERC1155 ([minter, firstTokenHolder, secondTokenHolder,
});
it('reverts when transferring amount more than any of balances', async function () {
await expectRevert.unspecified(
await expectRevert(
this.token.safeBatchTransferFrom(
multiTokenHolder, recipient,
[firstTokenId, secondTokenId],
[firstAmount, secondAmount.addn(1)],
'0x', { from: multiTokenHolder },
),
'ERC1155: insufficient balance for transfer',
);
});

View File

@ -118,8 +118,9 @@ contract('ERC1155', function (accounts) {
});
it('reverts when burning a non-existent token id', async function () {
await expectRevert.unspecified(
await expectRevert(
this.token.burn(tokenHolder, tokenId, mintAmount),
'ERC1155: burn amount exceeds balance',
);
});
@ -132,8 +133,9 @@ contract('ERC1155', function (accounts) {
{ from: operator },
);
await expectRevert.unspecified(
await expectRevert(
this.token.burn(tokenHolder, tokenId, mintAmount.addn(1)),
'ERC1155: burn amount exceeds balance',
);
});
@ -188,8 +190,9 @@ contract('ERC1155', function (accounts) {
});
it('reverts when burning a non-existent token id', async function () {
await expectRevert.unspecified(
await expectRevert(
this.token.burnBatch(tokenBatchHolder, tokenBatchIds, burnAmounts),
'ERC1155: burn amount exceeds balance',
);
});

View File

@ -87,8 +87,8 @@ function shouldBehaveLikeERC20 (errorPrefix, initialSupply, initialHolder, recip
const amount = initialSupply.addn(1);
it('reverts', async function () {
await expectRevert.unspecified(this.token.transferFrom(
tokenOwner, to, amount, { from: spender }),
await expectRevert(this.token.transferFrom(
tokenOwner, to, amount, { from: spender }), `${errorPrefix}: transfer amount exceeds balance`,
);
});
});
@ -103,8 +103,8 @@ function shouldBehaveLikeERC20 (errorPrefix, initialSupply, initialHolder, recip
const amount = initialSupply;
it('reverts', async function () {
await expectRevert.unspecified(this.token.transferFrom(
tokenOwner, to, amount, { from: spender }),
await expectRevert(this.token.transferFrom(
tokenOwner, to, amount, { from: spender }), `${errorPrefix}: transfer amount exceeds allowance`,
);
});
});
@ -113,8 +113,8 @@ function shouldBehaveLikeERC20 (errorPrefix, initialSupply, initialHolder, recip
const amount = initialSupply.addn(1);
it('reverts', async function () {
await expectRevert.unspecified(this.token.transferFrom(
tokenOwner, to, amount, { from: spender }),
await expectRevert(this.token.transferFrom(
tokenOwner, to, amount, { from: spender }), `${errorPrefix}: transfer amount exceeds balance`,
);
});
});
@ -165,8 +165,8 @@ function shouldBehaveLikeERC20Transfer (errorPrefix, from, to, balance, transfer
const amount = balance.addn(1);
it('reverts', async function () {
await expectRevert.unspecified(transfer.call(this, from, to, amount),
await expectRevert(transfer.call(this, from, to, amount),
`${errorPrefix}: transfer amount exceeds balance`,
);
});
});

View File

@ -53,8 +53,8 @@ contract('ERC20', function (accounts) {
function shouldDecreaseApproval (amount) {
describe('when there was no approved amount before', function () {
it('reverts', async function () {
await expectRevert.unspecified(this.token.decreaseAllowance(
spender, amount, { from: initialHolder }),
await expectRevert(this.token.decreaseAllowance(
spender, amount, { from: initialHolder }), 'ERC20: decreased allowance below zero',
);
});
});
@ -88,9 +88,9 @@ contract('ERC20', function (accounts) {
});
it('reverts when more than the full allowance is removed', async function () {
await expectRevert.unspecified(
await expectRevert(
this.token.decreaseAllowance(spender, approvedAmount.addn(1), { from: initialHolder }),
'ERC20: decreased allowance below zero',
);
});
});
@ -114,8 +114,8 @@ contract('ERC20', function (accounts) {
const spender = ZERO_ADDRESS;
it('reverts', async function () {
await expectRevert.unspecified(this.token.decreaseAllowance(
spender, amount, { from: initialHolder }),
await expectRevert(this.token.decreaseAllowance(
spender, amount, { from: initialHolder }), 'ERC20: decreased allowance below zero',
);
});
});
@ -247,8 +247,8 @@ contract('ERC20', function (accounts) {
describe('for a non zero account', function () {
it('rejects burning more than balance', async function () {
await expectRevert.unspecified(this.token.burn(
initialHolder, initialSupply.addn(1)),
await expectRevert(this.token.burn(
initialHolder, initialSupply.addn(1)), 'ERC20: burn amount exceeds balance',
);
});

View File

@ -93,9 +93,9 @@ function shouldOnlyRevertOnErrors () {
});
it('reverts when decreasing the allowance', async function () {
await expectRevert.unspecified(
await expectRevert(
this.wrapper.decreaseAllowance(10),
'SafeERC20: decreased allowance below zero',
);
});
});
@ -125,8 +125,9 @@ function shouldOnlyRevertOnErrors () {
});
it('reverts when decreasing the allowance to a negative value', async function () {
await expectRevert.unspecified(
await expectRevert(
this.wrapper.decreaseAllowance(200),
'SafeERC20: decreased allowance below zero',
);
});
});

View File

@ -37,8 +37,8 @@ function shouldBehaveLikeERC20Burnable (owner, initialBalance, [burner]) {
const amount = initialBalance.addn(1);
it('reverts', async function () {
await expectRevert.unspecified(this.token.burn(amount, { from: owner }),
await expectRevert(this.token.burn(amount, { from: owner }),
'ERC20: burn amount exceeds balance',
);
});
});
@ -86,8 +86,8 @@ function shouldBehaveLikeERC20Burnable (owner, initialBalance, [burner]) {
it('reverts', async function () {
await this.token.approve(burner, amount, { from: owner });
await expectRevert.unspecified(this.token.burnFrom(owner, amount, { from: burner }),
await expectRevert(this.token.burnFrom(owner, amount, { from: burner }),
'ERC20: burn amount exceeds balance',
);
});
});
@ -97,8 +97,8 @@ function shouldBehaveLikeERC20Burnable (owner, initialBalance, [burner]) {
it('reverts', async function () {
await this.token.approve(burner, allowance, { from: owner });
await expectRevert.unspecified(this.token.burnFrom(owner, allowance.addn(1), { from: burner }),
await expectRevert(this.token.burnFrom(owner, allowance.addn(1), { from: burner }),
'ERC20: burn amount exceeds allowance',
);
});
});