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:
Balaji Pachai
2019-04-24 19:47:08 +05:30
committed by Nicolás Venturo
parent 4a0a67b04c
commit 3682c6575c
93 changed files with 769 additions and 423 deletions

View File

@ -20,21 +20,23 @@ contract('TokenVesting', function ([_, owner, beneficiary]) {
cliffDuration.should.be.bignumber.that.is.at.least(duration);
await shouldFail.reverting(
TokenVesting.new(beneficiary, this.start, cliffDuration, duration, true, { from: owner })
await shouldFail.reverting.withMessage(
TokenVesting.new(beneficiary, this.start, cliffDuration, duration, true, { from: owner }),
'TokenVesting: cliff is longer than duration'
);
});
it('reverts with a null beneficiary', async function () {
await shouldFail.reverting(
TokenVesting.new(ZERO_ADDRESS, this.start, this.cliffDuration, this.duration, true, { from: owner })
await shouldFail.reverting.withMessage(
TokenVesting.new(ZERO_ADDRESS, this.start, this.cliffDuration, this.duration, true, { from: owner }),
'TokenVesting: beneficiary is the zero address'
);
});
it('reverts with a null duration', async function () {
// cliffDuration should also be 0, since the duration must be larger than the cliff
await shouldFail.reverting(
TokenVesting.new(beneficiary, this.start, 0, 0, true, { from: owner })
await shouldFail.reverting.withMessage(
TokenVesting.new(beneficiary, this.start, 0, 0, true, { from: owner }), 'TokenVesting: duration is 0'
);
});
@ -42,8 +44,9 @@ contract('TokenVesting', function ([_, owner, beneficiary]) {
const now = await time.latest();
this.start = now.sub(this.duration).sub(time.duration.minutes(1));
await shouldFail.reverting(
TokenVesting.new(beneficiary, this.start, this.cliffDuration, this.duration, true, { from: owner })
await shouldFail.reverting.withMessage(
TokenVesting.new(beneficiary, this.start, this.cliffDuration, this.duration, true, { from: owner }),
'TokenVesting: final time is before current time'
);
});
@ -65,7 +68,9 @@ contract('TokenVesting', function ([_, owner, beneficiary]) {
});
it('cannot be released before cliff', async function () {
await shouldFail.reverting(this.vesting.release(this.token.address));
await shouldFail.reverting.withMessage(this.vesting.release(this.token.address),
'TokenVesting: no tokens are due'
);
});
it('can be released after cliff', async function () {
@ -121,7 +126,9 @@ contract('TokenVesting', function ([_, owner, beneficiary]) {
beneficiary, this.start, this.cliffDuration, this.duration, false, { from: owner }
);
await shouldFail.reverting(vesting.revoke(this.token.address, { from: owner }));
await shouldFail.reverting.withMessage(vesting.revoke(this.token.address, { from: owner }),
'TokenVesting: cannot revoke'
);
});
it('should return the non-vested tokens when revoked by owner', async function () {
@ -148,7 +155,9 @@ contract('TokenVesting', function ([_, owner, beneficiary]) {
it('should fail to be revoked a second time', async function () {
await this.vesting.revoke(this.token.address, { from: owner });
await shouldFail.reverting(this.vesting.revoke(this.token.address, { from: owner }));
await shouldFail.reverting.withMessage(this.vesting.revoke(this.token.address, { from: owner }),
'TokenVesting: token already revoked'
);
});
function vestedAmount (total, now, start, cliffDuration, duration) {