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
@ -11,7 +11,7 @@ contract('SafeERC20', function ([_, hasNoCode]) {
|
||||
this.wrapper = await SafeERC20Wrapper.new(hasNoCode);
|
||||
});
|
||||
|
||||
shouldRevertOnAllCalls();
|
||||
shouldRevertOnAllCalls('SafeERC20: call to non-contract');
|
||||
});
|
||||
|
||||
describe('with token that returns false on all calls', function () {
|
||||
@ -19,7 +19,7 @@ contract('SafeERC20', function ([_, hasNoCode]) {
|
||||
this.wrapper = await SafeERC20Wrapper.new((await ERC20ReturnFalseMock.new()).address);
|
||||
});
|
||||
|
||||
shouldRevertOnAllCalls();
|
||||
shouldRevertOnAllCalls('SafeERC20: ERC20 operation did not succeed');
|
||||
});
|
||||
|
||||
describe('with token that returns true on all calls', function () {
|
||||
@ -39,24 +39,26 @@ contract('SafeERC20', function ([_, hasNoCode]) {
|
||||
});
|
||||
});
|
||||
|
||||
function shouldRevertOnAllCalls () {
|
||||
function shouldRevertOnAllCalls (reason) {
|
||||
it('reverts on transfer', async function () {
|
||||
await shouldFail.reverting(this.wrapper.transfer());
|
||||
await shouldFail.reverting.withMessage(this.wrapper.transfer(), reason);
|
||||
});
|
||||
|
||||
it('reverts on transferFrom', async function () {
|
||||
await shouldFail.reverting(this.wrapper.transferFrom());
|
||||
await shouldFail.reverting.withMessage(this.wrapper.transferFrom(), reason);
|
||||
});
|
||||
|
||||
it('reverts on approve', async function () {
|
||||
await shouldFail.reverting(this.wrapper.approve(0));
|
||||
await shouldFail.reverting.withMessage(this.wrapper.approve(0), reason);
|
||||
});
|
||||
|
||||
it('reverts on increaseAllowance', async function () {
|
||||
// [TODO] make sure it's reverting for the right reason
|
||||
await shouldFail.reverting(this.wrapper.increaseAllowance(0));
|
||||
});
|
||||
|
||||
it('reverts on decreaseAllowance', async function () {
|
||||
// [TODO] make sure it's reverting for the right reason
|
||||
await shouldFail.reverting(this.wrapper.decreaseAllowance(0));
|
||||
});
|
||||
}
|
||||
@ -89,7 +91,10 @@ function shouldOnlyRevertOnErrors () {
|
||||
});
|
||||
|
||||
it('reverts when decreasing the allowance', async function () {
|
||||
await shouldFail.reverting(this.wrapper.decreaseAllowance(10));
|
||||
await shouldFail.reverting.withMessage(
|
||||
this.wrapper.decreaseAllowance(10),
|
||||
'SafeMath: subtraction overflow'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@ -99,7 +104,10 @@ function shouldOnlyRevertOnErrors () {
|
||||
});
|
||||
|
||||
it('reverts when approving a non-zero allowance', async function () {
|
||||
await shouldFail.reverting(this.wrapper.approve(20));
|
||||
await shouldFail.reverting.withMessage(
|
||||
this.wrapper.approve(20),
|
||||
'SafeERC20: approve from non-zero to non-zero allowance'
|
||||
);
|
||||
});
|
||||
|
||||
it('doesn\'t revert when approving a zero allowance', async function () {
|
||||
@ -115,7 +123,10 @@ function shouldOnlyRevertOnErrors () {
|
||||
});
|
||||
|
||||
it('reverts when decreasing the allowance to a negative value', async function () {
|
||||
await shouldFail.reverting(this.wrapper.decreaseAllowance(200));
|
||||
await shouldFail.reverting.withMessage(
|
||||
this.wrapper.decreaseAllowance(200),
|
||||
'SafeMath: subtraction overflow'
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user