* Now compiling using truffle 5.
* Migrated some test files, missing BN scientific notation usage.
* Now using BN time values.
* Migrate ERC20 tests.
* Migrate all ERC20 tests.
* Migrate utils, payment and ownership tests.
* All tests save ERC721 migrated.
* Migrated ERC721 tests.
* Fix lint errors.
* Delete old test helpers.
* Fix remaining crowdsale tests.
* Fix signature bouncer tests.
* Update how constants is used.
* Compile script pre-removes the build dir.
* Fix SafeMath tests.
* Revert "Compile script pre-removes the build dir."
This reverts commit 247e745113.
* Fix linter errors.
* Upgrade openzeppelin-test-helpers dependency.
* Update openzeppelin-test-helpers dependency.
* Define math constants globally.
* Remove unnecessary ether unit.
* Roll back reduced ether amounts in tests.
* Remove unnecessary toNumber conversions.
* Delete compile script.
* Fixed failing test.
92 lines
3.1 KiB
JavaScript
92 lines
3.1 KiB
JavaScript
const { shouldFail } = require('openzeppelin-test-helpers');
|
|
|
|
const SafeERC20Helper = artifacts.require('SafeERC20Helper');
|
|
|
|
contract('SafeERC20', function () {
|
|
beforeEach(async function () {
|
|
this.helper = await SafeERC20Helper.new();
|
|
});
|
|
|
|
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());
|
|
});
|
|
});
|
|
|
|
describe('with token that returns true on all calls', function () {
|
|
it('doesn\'t revert on transfer', async function () {
|
|
await this.helper.doSucceedingTransfer();
|
|
});
|
|
|
|
it('doesn\'t revert on transferFrom', async function () {
|
|
await this.helper.doSucceedingTransferFrom();
|
|
});
|
|
|
|
describe('approvals', function () {
|
|
context('with zero allowance', function () {
|
|
beforeEach(async function () {
|
|
await this.helper.setAllowance(0);
|
|
});
|
|
|
|
it('doesn\'t revert when approving a non-zero allowance', async function () {
|
|
await this.helper.doSucceedingApprove(100);
|
|
});
|
|
|
|
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));
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|