Added message string for require() (#1704)
* Error handling in ERC20 and ERC721 * Added message string for require. * Fixed solhint errors. * Updated PR as per issue #1709 * changes as per #1709 and openzeppelin forum. * Changes in require statement * Changes in require statement * build pipeline fix * Changes as per @nventuro's comment. * Update revert reason strings. * Fianal update of revert reason strings. * WIP: Updating reason strings in test cases * WIP: Added changes to ERC20 and ERC721 * Fixes linting errors in *.tes.js files * Achieved 100% code coverage * Updated the test cases with shouldFail.reverting.withMessage() * Fix package-lock. * address review comments * fix linter issues * fix remaining revert reasons
This commit is contained in:
committed by
Nicolás Venturo
parent
4a0a67b04c
commit
3682c6575c
@ -37,7 +37,9 @@ contract('ERC20', function ([_, initialHolder, recipient, anotherAccount]) {
|
||||
const amount = initialSupply.addn(1);
|
||||
|
||||
it('reverts', async function () {
|
||||
await shouldFail.reverting(this.token.transfer(to, amount, { from: initialHolder }));
|
||||
await shouldFail.reverting.withMessage(this.token.transfer(to, amount, { from: initialHolder }),
|
||||
'SafeMath: subtraction overflow'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@ -68,7 +70,9 @@ contract('ERC20', function ([_, initialHolder, recipient, anotherAccount]) {
|
||||
const to = ZERO_ADDRESS;
|
||||
|
||||
it('reverts', async function () {
|
||||
await shouldFail.reverting(this.token.transfer(to, initialSupply, { from: initialHolder }));
|
||||
await shouldFail.reverting.withMessage(this.token.transfer(to, initialSupply, { from: initialHolder }),
|
||||
'ERC20: transfer to the zero address'
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -126,7 +130,9 @@ contract('ERC20', function ([_, initialHolder, recipient, anotherAccount]) {
|
||||
const amount = initialSupply.addn(1);
|
||||
|
||||
it('reverts', async function () {
|
||||
await shouldFail.reverting(this.token.transferFrom(initialHolder, to, amount, { from: spender }));
|
||||
await shouldFail.reverting.withMessage(this.token.transferFrom(
|
||||
initialHolder, to, amount, { from: spender }), 'SafeMath: subtraction overflow'
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -140,7 +146,9 @@ contract('ERC20', function ([_, initialHolder, recipient, anotherAccount]) {
|
||||
const amount = initialSupply;
|
||||
|
||||
it('reverts', async function () {
|
||||
await shouldFail.reverting(this.token.transferFrom(initialHolder, to, amount, { from: spender }));
|
||||
await shouldFail.reverting.withMessage(this.token.transferFrom(
|
||||
initialHolder, to, amount, { from: spender }), 'SafeMath: subtraction overflow'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@ -148,7 +156,9 @@ contract('ERC20', function ([_, initialHolder, recipient, anotherAccount]) {
|
||||
const amount = initialSupply.addn(1);
|
||||
|
||||
it('reverts', async function () {
|
||||
await shouldFail.reverting(this.token.transferFrom(initialHolder, to, amount, { from: spender }));
|
||||
await shouldFail.reverting.withMessage(this.token.transferFrom(
|
||||
initialHolder, to, amount, { from: spender }), 'SafeMath: subtraction overflow'
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -163,7 +173,9 @@ contract('ERC20', function ([_, initialHolder, recipient, anotherAccount]) {
|
||||
});
|
||||
|
||||
it('reverts', async function () {
|
||||
await shouldFail.reverting(this.token.transferFrom(initialHolder, to, amount, { from: spender }));
|
||||
await shouldFail.reverting.withMessage(this.token.transferFrom(
|
||||
initialHolder, to, amount, { from: spender }), 'ERC20: transfer to the zero address'
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -175,7 +187,9 @@ contract('ERC20', function ([_, initialHolder, recipient, anotherAccount]) {
|
||||
function shouldDecreaseApproval (amount) {
|
||||
describe('when there was no approved amount before', function () {
|
||||
it('reverts', async function () {
|
||||
await shouldFail.reverting(this.token.decreaseAllowance(spender, amount, { from: initialHolder }));
|
||||
await shouldFail.reverting.withMessage(this.token.decreaseAllowance(
|
||||
spender, amount, { from: initialHolder }), 'SafeMath: subtraction overflow'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@ -208,8 +222,9 @@ contract('ERC20', function ([_, initialHolder, recipient, anotherAccount]) {
|
||||
});
|
||||
|
||||
it('reverts when more than the full allowance is removed', async function () {
|
||||
await shouldFail.reverting(
|
||||
this.token.decreaseAllowance(spender, approvedAmount.addn(1), { from: initialHolder })
|
||||
await shouldFail.reverting.withMessage(
|
||||
this.token.decreaseAllowance(spender, approvedAmount.addn(1), { from: initialHolder }),
|
||||
'SafeMath: subtraction overflow'
|
||||
);
|
||||
});
|
||||
});
|
||||
@ -233,7 +248,9 @@ contract('ERC20', function ([_, initialHolder, recipient, anotherAccount]) {
|
||||
const spender = ZERO_ADDRESS;
|
||||
|
||||
it('reverts', async function () {
|
||||
await shouldFail.reverting(this.token.decreaseAllowance(spender, amount, { from: initialHolder }));
|
||||
await shouldFail.reverting.withMessage(this.token.decreaseAllowance(
|
||||
spender, amount, { from: initialHolder }, 'ERC20: approve to the zero address')
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -315,16 +332,19 @@ contract('ERC20', function ([_, initialHolder, recipient, anotherAccount]) {
|
||||
const spender = ZERO_ADDRESS;
|
||||
|
||||
it('reverts', async function () {
|
||||
await shouldFail.reverting(this.token.increaseAllowance(spender, amount, { from: initialHolder }));
|
||||
await shouldFail.reverting.withMessage(
|
||||
this.token.increaseAllowance(spender, amount, { from: initialHolder }), 'ERC20: approve to the zero address'
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('_mint', function () {
|
||||
const amount = new BN(50);
|
||||
|
||||
it('rejects a zero account', async function () {
|
||||
await shouldFail.reverting(this.token.mint(ZERO_ADDRESS, amount));
|
||||
it('rejects a null account', async function () {
|
||||
await shouldFail.reverting.withMessage(
|
||||
this.token.mint(ZERO_ADDRESS, amount), 'ERC20: mint to the zero address'
|
||||
);
|
||||
});
|
||||
|
||||
describe('for a non zero account', function () {
|
||||
@ -354,13 +374,16 @@ contract('ERC20', function ([_, initialHolder, recipient, anotherAccount]) {
|
||||
});
|
||||
|
||||
describe('_burn', function () {
|
||||
it('rejects a zero account', async function () {
|
||||
await shouldFail.reverting(this.token.burn(ZERO_ADDRESS, new BN(1)));
|
||||
it('rejects a null account', async function () {
|
||||
await shouldFail.reverting.withMessage(this.token.burn(ZERO_ADDRESS, new BN(1)),
|
||||
'ERC20: burn from the zero address');
|
||||
});
|
||||
|
||||
describe('for a non zero account', function () {
|
||||
it('rejects burning more than balance', async function () {
|
||||
await shouldFail.reverting(this.token.burn(initialHolder, initialSupply.addn(1)));
|
||||
await shouldFail.reverting.withMessage(this.token.burn(
|
||||
initialHolder, initialSupply.addn(1)), 'SafeMath: subtraction overflow'
|
||||
);
|
||||
});
|
||||
|
||||
const describeBurn = function (description, amount) {
|
||||
@ -405,17 +428,23 @@ contract('ERC20', function ([_, initialHolder, recipient, anotherAccount]) {
|
||||
await this.token.approve(spender, allowance, { from: initialHolder });
|
||||
});
|
||||
|
||||
it('rejects a zero account', async function () {
|
||||
await shouldFail.reverting(this.token.burnFrom(ZERO_ADDRESS, new BN(1)));
|
||||
it('rejects a null account', async function () {
|
||||
await shouldFail.reverting.withMessage(this.token.burnFrom(ZERO_ADDRESS, new BN(1)),
|
||||
'ERC20: burn from the zero address'
|
||||
);
|
||||
});
|
||||
|
||||
describe('for a non zero account', function () {
|
||||
it('rejects burning more than allowance', async function () {
|
||||
await shouldFail.reverting(this.token.burnFrom(initialHolder, allowance.addn(1)));
|
||||
await shouldFail.reverting.withMessage(this.token.burnFrom(initialHolder, allowance.addn(1)),
|
||||
'SafeMath: subtraction overflow'
|
||||
);
|
||||
});
|
||||
|
||||
it('rejects burning more than balance', async function () {
|
||||
await shouldFail.reverting(this.token.burnFrom(initialHolder, initialSupply.addn(1)));
|
||||
await shouldFail.reverting.withMessage(this.token.burnFrom(initialHolder, initialSupply.addn(1)),
|
||||
'SafeMath: subtraction overflow'
|
||||
);
|
||||
});
|
||||
|
||||
const describeBurnFrom = function (description, amount) {
|
||||
@ -477,7 +506,9 @@ contract('ERC20', function ([_, initialHolder, recipient, anotherAccount]) {
|
||||
|
||||
describe('when the owner is the zero address', function () {
|
||||
it('reverts', async function () {
|
||||
await shouldFail.reverting(this.token.approveInternal(ZERO_ADDRESS, recipient, initialSupply));
|
||||
await shouldFail.reverting.withMessage(this.token.approveInternal(ZERO_ADDRESS, recipient, initialSupply),
|
||||
'ERC20: approve from the zero address'
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -555,7 +586,9 @@ contract('ERC20', function ([_, initialHolder, recipient, anotherAccount]) {
|
||||
|
||||
describe('when the spender is the zero address', function () {
|
||||
it('reverts', async function () {
|
||||
await shouldFail.reverting(approve.call(this, owner, ZERO_ADDRESS, supply));
|
||||
await shouldFail.reverting.withMessage(approve.call(this, owner, ZERO_ADDRESS, supply),
|
||||
'ERC20: approve to the zero address'
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user