Improved SafeERC20 allowance handling (#1407)
* signing prefix added
* Minor improvement
* Tests changed
* Successfully tested
* Minor improvements
* Minor improvements
* Revert "Dangling commas are now required. (#1359)"
This reverts commit a6889776f4.
* updates
* fixes #1404
* approve failing test
* suggested changes done
* ISafeERC20 removed
* allowance methods in library
* Improved SafeERC20 tests.
* Fixed test coverage.
This commit is contained in:
@ -10,27 +10,85 @@ contract('SafeERC20', function () {
|
||||
this.helper = await SafeERC20Helper.new();
|
||||
});
|
||||
|
||||
it('should throw on failed transfer', async function () {
|
||||
await shouldFail.reverting(this.helper.doFailingTransfer());
|
||||
describe('with token that returns false on all calls', function () {
|
||||
it('reverts on transfer', async function () {
|
||||
await shouldFail.reverting(this.helper.doFailingTransfer());
|
||||
});
|
||||
|
||||
it('reverts on transferFrom', async function () {
|
||||
await shouldFail.reverting(this.helper.doFailingTransferFrom());
|
||||
});
|
||||
|
||||
it('reverts on approve', async function () {
|
||||
await shouldFail.reverting(this.helper.doFailingApprove());
|
||||
});
|
||||
|
||||
it('reverts on increaseAllowance', async function () {
|
||||
await shouldFail.reverting(this.helper.doFailingIncreaseAllowance());
|
||||
});
|
||||
|
||||
it('reverts on decreaseAllowance', async function () {
|
||||
await shouldFail.reverting(this.helper.doFailingDecreaseAllowance());
|
||||
});
|
||||
});
|
||||
|
||||
it('should throw on failed transferFrom', async function () {
|
||||
await shouldFail.reverting(this.helper.doFailingTransferFrom());
|
||||
});
|
||||
describe('with token that returns true on all calls', function () {
|
||||
it('doesn\'t revert on transfer', async function () {
|
||||
await this.helper.doSucceedingTransfer();
|
||||
});
|
||||
|
||||
it('should throw on failed approve', async function () {
|
||||
await shouldFail.reverting(this.helper.doFailingApprove());
|
||||
});
|
||||
it('doesn\'t revert on transferFrom', async function () {
|
||||
await this.helper.doSucceedingTransferFrom();
|
||||
});
|
||||
|
||||
it('should not throw on succeeding transfer', async function () {
|
||||
await this.helper.doSucceedingTransfer();
|
||||
});
|
||||
describe('approvals', function () {
|
||||
context('with zero allowance', function () {
|
||||
beforeEach(async function () {
|
||||
await this.helper.setAllowance(0);
|
||||
});
|
||||
|
||||
it('should not throw on succeeding transferFrom', async function () {
|
||||
await this.helper.doSucceedingTransferFrom();
|
||||
});
|
||||
it('doesn\'t revert when approving a non-zero allowance', async function () {
|
||||
await this.helper.doSucceedingApprove(100);
|
||||
});
|
||||
|
||||
it('should not throw on succeeding approve', async function () {
|
||||
await this.helper.doSucceedingApprove();
|
||||
it('doesn\'t revert when approving a zero allowance', async function () {
|
||||
await this.helper.doSucceedingApprove(0);
|
||||
});
|
||||
|
||||
it('doesn\'t revert when increasing the allowance', async function () {
|
||||
await this.helper.doSucceedingIncreaseAllowance(10);
|
||||
});
|
||||
|
||||
it('reverts when decreasing the allowance', async function () {
|
||||
await shouldFail.reverting(this.helper.doSucceedingDecreaseAllowance(10));
|
||||
});
|
||||
});
|
||||
|
||||
context('with non-zero allowance', function () {
|
||||
beforeEach(async function () {
|
||||
await this.helper.setAllowance(100);
|
||||
});
|
||||
|
||||
it('reverts when approving a non-zero allowance', async function () {
|
||||
await shouldFail.reverting(this.helper.doSucceedingApprove(20));
|
||||
});
|
||||
|
||||
it('doesn\'t revert when approving a zero allowance', async function () {
|
||||
await this.helper.doSucceedingApprove(0);
|
||||
});
|
||||
|
||||
it('doesn\'t revert when increasing the allowance', async function () {
|
||||
await this.helper.doSucceedingIncreaseAllowance(10);
|
||||
});
|
||||
|
||||
it('doesn\'t revert when decreasing the allowance to a positive value', async function () {
|
||||
await this.helper.doSucceedingDecreaseAllowance(50);
|
||||
});
|
||||
|
||||
it('reverts when decreasing the allowance to a negative value', async function () {
|
||||
await shouldFail.reverting(this.helper.doSucceedingDecreaseAllowance(200));
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user