From 7f34509a0461fc7681360e012cfdd08708561f58 Mon Sep 17 00:00:00 2001 From: Tal Ater Date: Thu, 22 Mar 2018 17:40:04 +0200 Subject: [PATCH 01/27] Added PausableCrowdsale contract --- contracts/crowdsale/PausableCrowdsale.sol | 21 +++ contracts/mocks/PausableCrowdsaleImpl.sol | 19 +++ test/crowdsale/PausableCrowdsale.test.js | 153 ++++++++++++++++++++++ 3 files changed, 193 insertions(+) create mode 100644 contracts/crowdsale/PausableCrowdsale.sol create mode 100644 contracts/mocks/PausableCrowdsaleImpl.sol create mode 100644 test/crowdsale/PausableCrowdsale.test.js diff --git a/contracts/crowdsale/PausableCrowdsale.sol b/contracts/crowdsale/PausableCrowdsale.sol new file mode 100644 index 00000000000..f1b3a4c4775 --- /dev/null +++ b/contracts/crowdsale/PausableCrowdsale.sol @@ -0,0 +1,21 @@ +pragma solidity ^0.4.18; + +import "./Crowdsale.sol"; +import "../lifecycle/Pausable.sol"; + + +/** + * @title PausableCrowdsale + * @dev Extension of Crowdsale contract that can be paused and unpaused by owner + */ +contract PausableCrowdsale is Crowdsale, Pausable { + + /** + * @dev Validation of an incoming purchase. Use require statements to revert state when conditions are not met. Use super to concatenate validations. + * @param _beneficiary Address performing the token purchase + * @param _weiAmount Value in wei involved in the purchase + */ + function _preValidatePurchase(address _beneficiary, uint256 _weiAmount) internal whenNotPaused { + return super._preValidatePurchase(_beneficiary, _weiAmount); + } +} diff --git a/contracts/mocks/PausableCrowdsaleImpl.sol b/contracts/mocks/PausableCrowdsaleImpl.sol new file mode 100644 index 00000000000..0f81b744f97 --- /dev/null +++ b/contracts/mocks/PausableCrowdsaleImpl.sol @@ -0,0 +1,19 @@ +pragma solidity ^0.4.18; + +import "../token/ERC20/ERC20.sol"; +import "../crowdsale/PausableCrowdsale.sol"; + + +contract PausableCrowdsaleImpl is PausableCrowdsale { + + function PausableCrowdsaleImpl ( + uint256 _rate, + address _wallet, + ERC20 _token + ) + public + Crowdsale(_rate, _wallet, _token) + { + } + +} diff --git a/test/crowdsale/PausableCrowdsale.test.js b/test/crowdsale/PausableCrowdsale.test.js new file mode 100644 index 00000000000..ccefb74a40d --- /dev/null +++ b/test/crowdsale/PausableCrowdsale.test.js @@ -0,0 +1,153 @@ +import assertRevert from '../helpers/assertRevert'; + +const PausableCrowdsale = artifacts.require('PausableCrowdsaleImpl'); +const SimpleToken = artifacts.require('SimpleToken'); + +require('chai') + .use(require('chai-as-promised')) + .should(); + +contract('PausableCrowdsale', function ([owner, wallet, stranger]) { + const rate = 1; + const value = 1; + + beforeEach(async function () { + this.token = await SimpleToken.new(); + this.crowdsale = await PausableCrowdsale.new(rate, wallet, this.token.address); + await this.token.transfer(this.crowdsale.address, value); + }); + + describe('pause()', function () { + describe('when the sender is the crowdsale owner', function () { + const from = owner; + + describe('when the crowdsale is unpaused', function () { + it('pauses the crowdsale', async function () { + await this.crowdsale.pause({ from }); + const paused = await this.crowdsale.paused(); + assert.equal(paused, true); + }); + + it('emits a Pause event', async function () { + const { logs } = await this.crowdsale.pause({ from }); + assert.equal(logs.length, 1); + assert.equal(logs[0].event, 'Pause'); + }); + }); + + describe('when the crowdsale is paused', function () { + beforeEach(async function () { + await this.crowdsale.pause({ from }); + }); + + it('reverts', async function () { + await assertRevert(this.crowdsale.pause({ from })); + }); + }); + }); + + describe('when the sender is not the crowdsale owner', function () { + const from = stranger; + + it('reverts', async function () { + await assertRevert(this.crowdsale.pause({ from })); + }); + }); + }); + + describe('unpause()', function () { + describe('when the sender is the crowdsale owner', function () { + const from = owner; + + describe('when the crowdsale is paused', function () { + beforeEach(async function () { + await this.crowdsale.pause({ from }); + }); + + it('unpauses the crowdsale', async function () { + await this.crowdsale.unpause({ from }); + const paused = await this.crowdsale.paused(); + assert.equal(paused, false); + }); + + it('emits an Unpause event', async function () { + const { logs } = await this.crowdsale.unpause({ from }); + assert.equal(logs.length, 1); + assert.equal(logs[0].event, 'Unpause'); + }); + }); + + describe('when the crowdsale is unpaused', function () { + it('reverts', async function () { + await assertRevert(this.crowdsale.unpause({ from })); + }); + }); + }); + + describe('when the sender is not the crowdsale owner', function () { + const from = stranger; + + it('reverts', async function () { + await assertRevert(this.crowdsale.unpause({ from })); + }); + }); + }); + + describe('paused', function () { + const from = owner; + + it('is not paused by default', async function () { + const paused = await this.crowdsale.paused({ from }); + assert.equal(paused, false); + }); + + it('is paused after being paused', async function () { + await this.crowdsale.pause({ from }); + const paused = await this.crowdsale.paused({ from }); + assert.equal(paused, true); + }); + + it('is not paused after being paused and then unpaused', async function () { + await this.crowdsale.pause({ from }); + await this.crowdsale.unpause({ from }); + const paused = await this.crowdsale.paused({ from }); + assert.equal(paused, false); + }); + }); + + describe('when the crowdsale is paused', function () { + const from = owner; + + beforeEach(async function () { + await this.crowdsale.pause({ from }); + }); + + describe('high-level purchase using fallback function', function () { + it('reverts', async function () { + await assertRevert(this.crowdsale.sendTransaction({ from, value })); + }); + }); + + describe('buyTokens()', function () { + it('reverts', async function () { + await assertRevert(this.crowdsale.buyTokens(from, { from, value })); + }); + }); + }); + + describe('when the crowdsale is unpaused', function () { + const from = owner; + + describe('high-level purchase using fallback function', function () { + it('should accept payments', async function () { + await this.crowdsale.sendTransaction({ from, value }).should.be.fulfilled; + }); + }); + + describe('buyTokens()', function () { + it('should accept payments', async function () { + await this.crowdsale.buyTokens(from, { from, value }).should.be.fulfilled; + }); + }); + }); +}); From 35e799cb3bfed32ff10f6fb9ea24a6d173cddfb4 Mon Sep 17 00:00:00 2001 From: Tal Ater Date: Sun, 2 Sep 2018 11:44:20 +0300 Subject: [PATCH 02/27] Changed inheritance order to prevent "Linearization of inheritance graph impossible" error --- contracts/crowdsale/PausableCrowdsale.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/crowdsale/PausableCrowdsale.sol b/contracts/crowdsale/PausableCrowdsale.sol index f1b3a4c4775..844f9e529fa 100644 --- a/contracts/crowdsale/PausableCrowdsale.sol +++ b/contracts/crowdsale/PausableCrowdsale.sol @@ -8,7 +8,7 @@ import "../lifecycle/Pausable.sol"; * @title PausableCrowdsale * @dev Extension of Crowdsale contract that can be paused and unpaused by owner */ -contract PausableCrowdsale is Crowdsale, Pausable { +contract PausableCrowdsale is Pausable, Crowdsale { /** * @dev Validation of an incoming purchase. Use require statements to revert state when conditions are not met. Use super to concatenate validations. From 0661e310b74a38d5a98ba0550b5a807ca79fb84c Mon Sep 17 00:00:00 2001 From: Tal Ater Date: Sun, 2 Sep 2018 15:22:28 +0300 Subject: [PATCH 03/27] Updated mock PausableCrowdsaleImpl to new constructor syntax --- contracts/mocks/PausableCrowdsaleImpl.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/mocks/PausableCrowdsaleImpl.sol b/contracts/mocks/PausableCrowdsaleImpl.sol index 0f81b744f97..857ea2362a1 100644 --- a/contracts/mocks/PausableCrowdsaleImpl.sol +++ b/contracts/mocks/PausableCrowdsaleImpl.sol @@ -6,7 +6,7 @@ import "../crowdsale/PausableCrowdsale.sol"; contract PausableCrowdsaleImpl is PausableCrowdsale { - function PausableCrowdsaleImpl ( + constructor ( uint256 _rate, address _wallet, ERC20 _token From 3d69c023d7a75e3b4d59127a23e1e0f31674af66 Mon Sep 17 00:00:00 2001 From: Tal Ater Date: Sun, 2 Sep 2018 15:25:37 +0300 Subject: [PATCH 04/27] Broke function definition to multiple lines Comply with new max line length --- contracts/crowdsale/PausableCrowdsale.sol | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/contracts/crowdsale/PausableCrowdsale.sol b/contracts/crowdsale/PausableCrowdsale.sol index 844f9e529fa..0f3c4937765 100644 --- a/contracts/crowdsale/PausableCrowdsale.sol +++ b/contracts/crowdsale/PausableCrowdsale.sol @@ -15,7 +15,10 @@ contract PausableCrowdsale is Pausable, Crowdsale { * @param _beneficiary Address performing the token purchase * @param _weiAmount Value in wei involved in the purchase */ - function _preValidatePurchase(address _beneficiary, uint256 _weiAmount) internal whenNotPaused { + function _preValidatePurchase(address _beneficiary, uint256 _weiAmount) + internal + whenNotPaused + { return super._preValidatePurchase(_beneficiary, _weiAmount); } } From aa4834614c26a11de01a6965bc7dc51e1f42e1a9 Mon Sep 17 00:00:00 2001 From: Tal Ater Date: Sun, 2 Sep 2018 16:57:37 +0300 Subject: [PATCH 05/27] Rename events to past-tense in PausableCrowdsale test --- test/crowdsale/PausableCrowdsale.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/crowdsale/PausableCrowdsale.test.js b/test/crowdsale/PausableCrowdsale.test.js index ccefb74a40d..5da5194011a 100644 --- a/test/crowdsale/PausableCrowdsale.test.js +++ b/test/crowdsale/PausableCrowdsale.test.js @@ -31,7 +31,7 @@ contract('PausableCrowdsale', function ([owner, wallet, stranger]) { it('emits a Pause event', async function () { const { logs } = await this.crowdsale.pause({ from }); assert.equal(logs.length, 1); - assert.equal(logs[0].event, 'Pause'); + assert.equal(logs[0].event, 'Paused'); }); }); @@ -73,7 +73,7 @@ contract('PausableCrowdsale', function ([owner, wallet, stranger]) { it('emits an Unpause event', async function () { const { logs } = await this.crowdsale.unpause({ from }); assert.equal(logs.length, 1); - assert.equal(logs[0].event, 'Unpause'); + assert.equal(logs[0].event, 'Unpaused'); }); }); From 4b9a631a336066bf8a35248f2fbe859c53f0c8c3 Mon Sep 17 00:00:00 2001 From: Tal Ater Date: Sun, 2 Sep 2018 17:00:16 +0300 Subject: [PATCH 06/27] Removed should.be.fullfilled from PausableCrowdsale tests --- test/crowdsale/PausableCrowdsale.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/crowdsale/PausableCrowdsale.test.js b/test/crowdsale/PausableCrowdsale.test.js index 5da5194011a..e2b84269bb7 100644 --- a/test/crowdsale/PausableCrowdsale.test.js +++ b/test/crowdsale/PausableCrowdsale.test.js @@ -140,13 +140,13 @@ contract('PausableCrowdsale', function ([owner, wallet, stranger]) { describe('high-level purchase using fallback function', function () { it('should accept payments', async function () { - await this.crowdsale.sendTransaction({ from, value }).should.be.fulfilled; + await this.crowdsale.sendTransaction({ from, value }); }); }); describe('buyTokens()', function () { it('should accept payments', async function () { - await this.crowdsale.buyTokens(from, { from, value }).should.be.fulfilled; + await this.crowdsale.buyTokens(from, { from, value }); }); }); }); From 19f8b75c4fbacf0ffec52c960601ad95f1ed15f6 Mon Sep 17 00:00:00 2001 From: Tal Ater Date: Sun, 2 Sep 2018 17:00:50 +0300 Subject: [PATCH 07/27] Change import assertRevert to require in PausableCrowdsale tests --- test/crowdsale/PausableCrowdsale.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/crowdsale/PausableCrowdsale.test.js b/test/crowdsale/PausableCrowdsale.test.js index e2b84269bb7..fc9a2aa2c78 100644 --- a/test/crowdsale/PausableCrowdsale.test.js +++ b/test/crowdsale/PausableCrowdsale.test.js @@ -1,4 +1,4 @@ -import assertRevert from '../helpers/assertRevert'; +const { assertRevert } = require('../helpers/assertRevert'); const PausableCrowdsale = artifacts.require('PausableCrowdsaleImpl'); const SimpleToken = artifacts.require('SimpleToken'); From e9181d7d6c03ed696c75c082bbe90f532869ed2f Mon Sep 17 00:00:00 2001 From: Tal Ater Date: Sun, 2 Sep 2018 17:01:38 +0300 Subject: [PATCH 08/27] Remove dependency on chai-as-promised and added BigNumber support in PausableCrowdsale tests --- test/crowdsale/PausableCrowdsale.test.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/crowdsale/PausableCrowdsale.test.js b/test/crowdsale/PausableCrowdsale.test.js index fc9a2aa2c78..c04a61b35df 100644 --- a/test/crowdsale/PausableCrowdsale.test.js +++ b/test/crowdsale/PausableCrowdsale.test.js @@ -3,8 +3,10 @@ const { assertRevert } = require('../helpers/assertRevert'); const PausableCrowdsale = artifacts.require('PausableCrowdsaleImpl'); const SimpleToken = artifacts.require('SimpleToken'); +const BigNumber = web3.BigNumber; + require('chai') - .use(require('chai-as-promised')) + .use(require('chai-bignumber')(BigNumber)) .should(); contract('PausableCrowdsale', function ([owner, wallet, stranger]) { From 547c7c53b84ec39da53197297ef9f3a3a93b13bc Mon Sep 17 00:00:00 2001 From: Francisco Giordano Date: Tue, 11 Dec 2018 18:26:04 -0300 Subject: [PATCH 09/27] reindent solidity with 4 spaces --- contracts/crowdsale/PausableCrowdsale.sol | 22 +++++++++++----------- contracts/mocks/PausableCrowdsaleImpl.sol | 18 +++++++++--------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/contracts/crowdsale/PausableCrowdsale.sol b/contracts/crowdsale/PausableCrowdsale.sol index 0f3c4937765..fa10af46a2a 100644 --- a/contracts/crowdsale/PausableCrowdsale.sol +++ b/contracts/crowdsale/PausableCrowdsale.sol @@ -10,15 +10,15 @@ import "../lifecycle/Pausable.sol"; */ contract PausableCrowdsale is Pausable, Crowdsale { - /** - * @dev Validation of an incoming purchase. Use require statements to revert state when conditions are not met. Use super to concatenate validations. - * @param _beneficiary Address performing the token purchase - * @param _weiAmount Value in wei involved in the purchase - */ - function _preValidatePurchase(address _beneficiary, uint256 _weiAmount) - internal - whenNotPaused - { - return super._preValidatePurchase(_beneficiary, _weiAmount); - } + /** + * @dev Validation of an incoming purchase. Use require statements to revert state when conditions are not met. Use super to concatenate validations. + * @param _beneficiary Address performing the token purchase + * @param _weiAmount Value in wei involved in the purchase + */ + function _preValidatePurchase(address _beneficiary, uint256 _weiAmount) + internal + whenNotPaused + { + return super._preValidatePurchase(_beneficiary, _weiAmount); + } } diff --git a/contracts/mocks/PausableCrowdsaleImpl.sol b/contracts/mocks/PausableCrowdsaleImpl.sol index 857ea2362a1..2277398a24f 100644 --- a/contracts/mocks/PausableCrowdsaleImpl.sol +++ b/contracts/mocks/PausableCrowdsaleImpl.sol @@ -6,14 +6,14 @@ import "../crowdsale/PausableCrowdsale.sol"; contract PausableCrowdsaleImpl is PausableCrowdsale { - constructor ( - uint256 _rate, - address _wallet, - ERC20 _token - ) - public - Crowdsale(_rate, _wallet, _token) - { - } + constructor ( + uint256 _rate, + address _wallet, + ERC20 _token + ) + public + Crowdsale(_rate, _wallet, _token) + { + } } From 35ade393e978cad4efc3e5f3bfae0d8e506afd28 Mon Sep 17 00:00:00 2001 From: Francisco Giordano Date: Tue, 11 Dec 2018 18:30:58 -0300 Subject: [PATCH 10/27] add missing view modifier in _preValidatePurchase --- contracts/crowdsale/PausableCrowdsale.sol | 1 + 1 file changed, 1 insertion(+) diff --git a/contracts/crowdsale/PausableCrowdsale.sol b/contracts/crowdsale/PausableCrowdsale.sol index fa10af46a2a..1166c0b20eb 100644 --- a/contracts/crowdsale/PausableCrowdsale.sol +++ b/contracts/crowdsale/PausableCrowdsale.sol @@ -17,6 +17,7 @@ contract PausableCrowdsale is Pausable, Crowdsale { */ function _preValidatePurchase(address _beneficiary, uint256 _weiAmount) internal + view whenNotPaused { return super._preValidatePurchase(_beneficiary, _weiAmount); From 5b74f79d4cda899be938be768882bbbe9e62e006 Mon Sep 17 00:00:00 2001 From: Francisco Giordano Date: Tue, 11 Dec 2018 18:31:23 -0300 Subject: [PATCH 11/27] convert assertRevert to new shoulFail helper --- test/crowdsale/PausableCrowdsale.test.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/test/crowdsale/PausableCrowdsale.test.js b/test/crowdsale/PausableCrowdsale.test.js index c04a61b35df..db245073028 100644 --- a/test/crowdsale/PausableCrowdsale.test.js +++ b/test/crowdsale/PausableCrowdsale.test.js @@ -1,4 +1,4 @@ -const { assertRevert } = require('../helpers/assertRevert'); +const shouldFail = require('../helpers/shouldFail'); const PausableCrowdsale = artifacts.require('PausableCrowdsaleImpl'); const SimpleToken = artifacts.require('SimpleToken'); @@ -43,7 +43,7 @@ contract('PausableCrowdsale', function ([owner, wallet, stranger]) { }); it('reverts', async function () { - await assertRevert(this.crowdsale.pause({ from })); + await shouldFail.reverting(this.crowdsale.pause({ from })); }); }); }); @@ -52,7 +52,7 @@ contract('PausableCrowdsale', function ([owner, wallet, stranger]) { const from = stranger; it('reverts', async function () { - await assertRevert(this.crowdsale.pause({ from })); + await shouldFail.reverting(this.crowdsale.pause({ from })); }); }); }); @@ -81,7 +81,7 @@ contract('PausableCrowdsale', function ([owner, wallet, stranger]) { describe('when the crowdsale is unpaused', function () { it('reverts', async function () { - await assertRevert(this.crowdsale.unpause({ from })); + await shouldFail.reverting(this.crowdsale.unpause({ from })); }); }); }); @@ -90,7 +90,7 @@ contract('PausableCrowdsale', function ([owner, wallet, stranger]) { const from = stranger; it('reverts', async function () { - await assertRevert(this.crowdsale.unpause({ from })); + await shouldFail.reverting(this.crowdsale.unpause({ from })); }); }); }); @@ -126,13 +126,13 @@ contract('PausableCrowdsale', function ([owner, wallet, stranger]) { describe('high-level purchase using fallback function', function () { it('reverts', async function () { - await assertRevert(this.crowdsale.sendTransaction({ from, value })); + await shouldFail.reverting(this.crowdsale.sendTransaction({ from, value })); }); }); describe('buyTokens()', function () { it('reverts', async function () { - await assertRevert(this.crowdsale.buyTokens(from, { from, value })); + await shouldFail.reverting(this.crowdsale.buyTokens(from, { from, value })); }); }); }); From 7f49a781b2ca7ae4c0e3e9756b22dede8f2c57fe Mon Sep 17 00:00:00 2001 From: Francisco Giordano Date: Tue, 11 Dec 2018 18:34:17 -0300 Subject: [PATCH 12/27] add new setup helper --- test/crowdsale/PausableCrowdsale.test.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/test/crowdsale/PausableCrowdsale.test.js b/test/crowdsale/PausableCrowdsale.test.js index db245073028..8719034581b 100644 --- a/test/crowdsale/PausableCrowdsale.test.js +++ b/test/crowdsale/PausableCrowdsale.test.js @@ -3,11 +3,7 @@ const shouldFail = require('../helpers/shouldFail'); const PausableCrowdsale = artifacts.require('PausableCrowdsaleImpl'); const SimpleToken = artifacts.require('SimpleToken'); -const BigNumber = web3.BigNumber; - -require('chai') - .use(require('chai-bignumber')(BigNumber)) - .should(); +require('../helpers/setup'); contract('PausableCrowdsale', function ([owner, wallet, stranger]) { const rate = 1; From 17474f1e624ddba0cefdd06350f681fa71d8eb54 Mon Sep 17 00:00:00 2001 From: Francisco Giordano Date: Tue, 11 Dec 2018 18:40:12 -0300 Subject: [PATCH 13/27] use expectEvent --- test/crowdsale/PausableCrowdsale.test.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/test/crowdsale/PausableCrowdsale.test.js b/test/crowdsale/PausableCrowdsale.test.js index 8719034581b..76b2df24c48 100644 --- a/test/crowdsale/PausableCrowdsale.test.js +++ b/test/crowdsale/PausableCrowdsale.test.js @@ -1,4 +1,5 @@ const shouldFail = require('../helpers/shouldFail'); +const expectEvent = require('../helpers/expectEvent'); const PausableCrowdsale = artifacts.require('PausableCrowdsaleImpl'); const SimpleToken = artifacts.require('SimpleToken'); @@ -28,8 +29,7 @@ contract('PausableCrowdsale', function ([owner, wallet, stranger]) { it('emits a Pause event', async function () { const { logs } = await this.crowdsale.pause({ from }); - assert.equal(logs.length, 1); - assert.equal(logs[0].event, 'Paused'); + expectEvent.inLogs(logs, 'Paused'); }); }); @@ -70,8 +70,7 @@ contract('PausableCrowdsale', function ([owner, wallet, stranger]) { it('emits an Unpause event', async function () { const { logs } = await this.crowdsale.unpause({ from }); - assert.equal(logs.length, 1); - assert.equal(logs[0].event, 'Unpaused'); + expectEvent.inLogs(logs, 'Unpaused'); }); }); From 775d8029610be5723501ff7e8848072293718259 Mon Sep 17 00:00:00 2001 From: Francisco Giordano Date: Tue, 11 Dec 2018 18:44:44 -0300 Subject: [PATCH 14/27] convert to assert to chai should style --- test/crowdsale/PausableCrowdsale.test.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/crowdsale/PausableCrowdsale.test.js b/test/crowdsale/PausableCrowdsale.test.js index 76b2df24c48..1dace835632 100644 --- a/test/crowdsale/PausableCrowdsale.test.js +++ b/test/crowdsale/PausableCrowdsale.test.js @@ -24,7 +24,7 @@ contract('PausableCrowdsale', function ([owner, wallet, stranger]) { it('pauses the crowdsale', async function () { await this.crowdsale.pause({ from }); const paused = await this.crowdsale.paused(); - assert.equal(paused, true); + paused.should.equal(true); }); it('emits a Pause event', async function () { @@ -65,7 +65,7 @@ contract('PausableCrowdsale', function ([owner, wallet, stranger]) { it('unpauses the crowdsale', async function () { await this.crowdsale.unpause({ from }); const paused = await this.crowdsale.paused(); - assert.equal(paused, false); + paused.should.equal(false); }); it('emits an Unpause event', async function () { @@ -95,20 +95,20 @@ contract('PausableCrowdsale', function ([owner, wallet, stranger]) { it('is not paused by default', async function () { const paused = await this.crowdsale.paused({ from }); - assert.equal(paused, false); + paused.should.equal(false); }); it('is paused after being paused', async function () { await this.crowdsale.pause({ from }); const paused = await this.crowdsale.paused({ from }); - assert.equal(paused, true); + paused.should.equal(true); }); it('is not paused after being paused and then unpaused', async function () { await this.crowdsale.pause({ from }); await this.crowdsale.unpause({ from }); const paused = await this.crowdsale.paused({ from }); - assert.equal(paused, false); + paused.should.equal(false); }); }); From f669ea6696a042b0b8fc75f3938effe896113443 Mon Sep 17 00:00:00 2001 From: Francisco Giordano Date: Tue, 11 Dec 2018 18:48:51 -0300 Subject: [PATCH 15/27] add description to beforeEach blocks --- test/crowdsale/PausableCrowdsale.test.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/crowdsale/PausableCrowdsale.test.js b/test/crowdsale/PausableCrowdsale.test.js index 1dace835632..f788ac0385f 100644 --- a/test/crowdsale/PausableCrowdsale.test.js +++ b/test/crowdsale/PausableCrowdsale.test.js @@ -10,7 +10,7 @@ contract('PausableCrowdsale', function ([owner, wallet, stranger]) { const rate = 1; const value = 1; - beforeEach(async function () { + beforeEach('setting up', async function () { this.token = await SimpleToken.new(); this.crowdsale = await PausableCrowdsale.new(rate, wallet, this.token.address); await this.token.transfer(this.crowdsale.address, value); @@ -34,7 +34,7 @@ contract('PausableCrowdsale', function ([owner, wallet, stranger]) { }); describe('when the crowdsale is paused', function () { - beforeEach(async function () { + beforeEach('pausing', async function () { await this.crowdsale.pause({ from }); }); @@ -115,7 +115,7 @@ contract('PausableCrowdsale', function ([owner, wallet, stranger]) { describe('when the crowdsale is paused', function () { const from = owner; - beforeEach(async function () { + beforeEach('pausing', async function () { await this.crowdsale.pause({ from }); }); From d2d1ca782fd6fccc2ae4d1ddad929b0ff1e31556 Mon Sep 17 00:00:00 2001 From: Francisco Giordano Date: Tue, 11 Dec 2018 18:49:21 -0300 Subject: [PATCH 16/27] extract common step to beforeEach --- test/crowdsale/PausableCrowdsale.test.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/test/crowdsale/PausableCrowdsale.test.js b/test/crowdsale/PausableCrowdsale.test.js index f788ac0385f..41f82264524 100644 --- a/test/crowdsale/PausableCrowdsale.test.js +++ b/test/crowdsale/PausableCrowdsale.test.js @@ -21,15 +21,18 @@ contract('PausableCrowdsale', function ([owner, wallet, stranger]) { const from = owner; describe('when the crowdsale is unpaused', function () { + beforeEach('pausing', async function () { + const { logs } = await this.crowdsale.pause({ from }); + this.logs = logs; + }); + it('pauses the crowdsale', async function () { - await this.crowdsale.pause({ from }); const paused = await this.crowdsale.paused(); paused.should.equal(true); }); - it('emits a Pause event', async function () { - const { logs } = await this.crowdsale.pause({ from }); - expectEvent.inLogs(logs, 'Paused'); + it('emits a Paused event', async function () { + expectEvent.inLogs(this.logs, 'Paused'); }); }); From f35c7e1766ae6631c274a97bb70693818073c900 Mon Sep 17 00:00:00 2001 From: Francisco Giordano Date: Tue, 11 Dec 2018 18:51:18 -0300 Subject: [PATCH 17/27] improve documentation --- contracts/crowdsale/PausableCrowdsale.sol | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/contracts/crowdsale/PausableCrowdsale.sol b/contracts/crowdsale/PausableCrowdsale.sol index 1166c0b20eb..c099dacfcc0 100644 --- a/contracts/crowdsale/PausableCrowdsale.sol +++ b/contracts/crowdsale/PausableCrowdsale.sol @@ -6,12 +6,13 @@ import "../lifecycle/Pausable.sol"; /** * @title PausableCrowdsale - * @dev Extension of Crowdsale contract that can be paused and unpaused by owner + * @dev Extension of Crowdsale contract that can be paused and unpaused by the pauser role. */ contract PausableCrowdsale is Pausable, Crowdsale { /** * @dev Validation of an incoming purchase. Use require statements to revert state when conditions are not met. Use super to concatenate validations. + * Adds the validation that the crowdsale must not be paused. * @param _beneficiary Address performing the token purchase * @param _weiAmount Value in wei involved in the purchase */ From 5f3e5d75a70b80f5906b22059e9fefed1a7d178a Mon Sep 17 00:00:00 2001 From: Francisco Giordano Date: Wed, 12 Dec 2018 16:00:37 -0300 Subject: [PATCH 18/27] revert inheritance error --- contracts/crowdsale/PausableCrowdsale.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/crowdsale/PausableCrowdsale.sol b/contracts/crowdsale/PausableCrowdsale.sol index c099dacfcc0..d322563593f 100644 --- a/contracts/crowdsale/PausableCrowdsale.sol +++ b/contracts/crowdsale/PausableCrowdsale.sol @@ -8,7 +8,7 @@ import "../lifecycle/Pausable.sol"; * @title PausableCrowdsale * @dev Extension of Crowdsale contract that can be paused and unpaused by the pauser role. */ -contract PausableCrowdsale is Pausable, Crowdsale { +contract PausableCrowdsale is Crowdsale, Pausable { /** * @dev Validation of an incoming purchase. Use require statements to revert state when conditions are not met. Use super to concatenate validations. From 10f93358fc48e752f54928c62a3e42f60539909c Mon Sep 17 00:00:00 2001 From: Francisco Giordano Date: Wed, 12 Dec 2018 16:01:48 -0300 Subject: [PATCH 19/27] move PausableCrowdsale into crowdsale/validation --- contracts/crowdsale/{ => validation}/PausableCrowdsale.sol | 4 ++-- contracts/mocks/PausableCrowdsaleImpl.sol | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) rename contracts/crowdsale/{ => validation}/PausableCrowdsale.sol (92%) diff --git a/contracts/crowdsale/PausableCrowdsale.sol b/contracts/crowdsale/validation/PausableCrowdsale.sol similarity index 92% rename from contracts/crowdsale/PausableCrowdsale.sol rename to contracts/crowdsale/validation/PausableCrowdsale.sol index d322563593f..b102816b18c 100644 --- a/contracts/crowdsale/PausableCrowdsale.sol +++ b/contracts/crowdsale/validation/PausableCrowdsale.sol @@ -1,7 +1,7 @@ pragma solidity ^0.4.18; -import "./Crowdsale.sol"; -import "../lifecycle/Pausable.sol"; +import "../Crowdsale.sol"; +import "../../lifecycle/Pausable.sol"; /** diff --git a/contracts/mocks/PausableCrowdsaleImpl.sol b/contracts/mocks/PausableCrowdsaleImpl.sol index 2277398a24f..27b99d5bc11 100644 --- a/contracts/mocks/PausableCrowdsaleImpl.sol +++ b/contracts/mocks/PausableCrowdsaleImpl.sol @@ -1,7 +1,7 @@ pragma solidity ^0.4.18; import "../token/ERC20/ERC20.sol"; -import "../crowdsale/PausableCrowdsale.sol"; +import "../crowdsale/validation/PausableCrowdsale.sol"; contract PausableCrowdsaleImpl is PausableCrowdsale { From 1d612fa0329f4676fad0521bcefbc32d4f3cae49 Mon Sep 17 00:00:00 2001 From: Francisco Giordano Date: Wed, 12 Dec 2018 16:05:22 -0300 Subject: [PATCH 20/27] make documentation more specific --- contracts/crowdsale/validation/PausableCrowdsale.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/crowdsale/validation/PausableCrowdsale.sol b/contracts/crowdsale/validation/PausableCrowdsale.sol index b102816b18c..ef6a67934f8 100644 --- a/contracts/crowdsale/validation/PausableCrowdsale.sol +++ b/contracts/crowdsale/validation/PausableCrowdsale.sol @@ -6,7 +6,7 @@ import "../../lifecycle/Pausable.sol"; /** * @title PausableCrowdsale - * @dev Extension of Crowdsale contract that can be paused and unpaused by the pauser role. + * @dev Extension of Crowdsale contract where purchases can be paused and unpaused by the pauser role. */ contract PausableCrowdsale is Crowdsale, Pausable { From 61b2e85df570c076f5689091c8df021512037d53 Mon Sep 17 00:00:00 2001 From: Francisco Giordano Date: Wed, 12 Dec 2018 16:05:45 -0300 Subject: [PATCH 21/27] put whitespace in line with convention --- contracts/crowdsale/validation/PausableCrowdsale.sol | 6 +----- contracts/mocks/PausableCrowdsaleImpl.sol | 12 +----------- 2 files changed, 2 insertions(+), 16 deletions(-) diff --git a/contracts/crowdsale/validation/PausableCrowdsale.sol b/contracts/crowdsale/validation/PausableCrowdsale.sol index ef6a67934f8..65fb0019fc8 100644 --- a/contracts/crowdsale/validation/PausableCrowdsale.sol +++ b/contracts/crowdsale/validation/PausableCrowdsale.sol @@ -16,11 +16,7 @@ contract PausableCrowdsale is Crowdsale, Pausable { * @param _beneficiary Address performing the token purchase * @param _weiAmount Value in wei involved in the purchase */ - function _preValidatePurchase(address _beneficiary, uint256 _weiAmount) - internal - view - whenNotPaused - { + function _preValidatePurchase(address _beneficiary, uint256 _weiAmount) internal view whenNotPaused { return super._preValidatePurchase(_beneficiary, _weiAmount); } } diff --git a/contracts/mocks/PausableCrowdsaleImpl.sol b/contracts/mocks/PausableCrowdsaleImpl.sol index 27b99d5bc11..64b4bc578d0 100644 --- a/contracts/mocks/PausableCrowdsaleImpl.sol +++ b/contracts/mocks/PausableCrowdsaleImpl.sol @@ -3,17 +3,7 @@ pragma solidity ^0.4.18; import "../token/ERC20/ERC20.sol"; import "../crowdsale/validation/PausableCrowdsale.sol"; - contract PausableCrowdsaleImpl is PausableCrowdsale { - - constructor ( - uint256 _rate, - address _wallet, - ERC20 _token - ) - public - Crowdsale(_rate, _wallet, _token) - { + constructor (uint256 _rate, address _wallet, ERC20 _token) public Crowdsale(_rate, _wallet, _token) { } - } From 1ea7a141665ef0406e3e4b88b4fe9e4be15a851f Mon Sep 17 00:00:00 2001 From: Francisco Giordano Date: Wed, 12 Dec 2018 16:08:03 -0300 Subject: [PATCH 22/27] improve test suite account names --- test/crowdsale/PausableCrowdsale.test.js | 32 +++++++++++++----------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/test/crowdsale/PausableCrowdsale.test.js b/test/crowdsale/PausableCrowdsale.test.js index 41f82264524..db880eae4ac 100644 --- a/test/crowdsale/PausableCrowdsale.test.js +++ b/test/crowdsale/PausableCrowdsale.test.js @@ -6,19 +6,21 @@ const SimpleToken = artifacts.require('SimpleToken'); require('../helpers/setup'); -contract('PausableCrowdsale', function ([owner, wallet, stranger]) { +contract('PausableCrowdsale', function ([_, pauser, wallet, anyone]) { const rate = 1; const value = 1; beforeEach('setting up', async function () { - this.token = await SimpleToken.new(); - this.crowdsale = await PausableCrowdsale.new(rate, wallet, this.token.address); - await this.token.transfer(this.crowdsale.address, value); + const from = pauser; + + this.token = await SimpleToken.new({ from }); + this.crowdsale = await PausableCrowdsale.new(rate, wallet, this.token.address, { from }); + await this.token.transfer(this.crowdsale.address, value, { from }); }); describe('pause()', function () { - describe('when the sender is the crowdsale owner', function () { - const from = owner; + describe('when the sender is the crowdsale pauser', function () { + const from = pauser; describe('when the crowdsale is unpaused', function () { beforeEach('pausing', async function () { @@ -47,8 +49,8 @@ contract('PausableCrowdsale', function ([owner, wallet, stranger]) { }); }); - describe('when the sender is not the crowdsale owner', function () { - const from = stranger; + describe('when the sender is not the crowdsale pauser', function () { + const from = anyone; it('reverts', async function () { await shouldFail.reverting(this.crowdsale.pause({ from })); @@ -57,8 +59,8 @@ contract('PausableCrowdsale', function ([owner, wallet, stranger]) { }); describe('unpause()', function () { - describe('when the sender is the crowdsale owner', function () { - const from = owner; + describe('when the sender is the crowdsale pauser', function () { + const from = pauser; describe('when the crowdsale is paused', function () { beforeEach(async function () { @@ -84,8 +86,8 @@ contract('PausableCrowdsale', function ([owner, wallet, stranger]) { }); }); - describe('when the sender is not the crowdsale owner', function () { - const from = stranger; + describe('when the sender is not the crowdsale pauser', function () { + const from = anyone; it('reverts', async function () { await shouldFail.reverting(this.crowdsale.unpause({ from })); @@ -94,7 +96,7 @@ contract('PausableCrowdsale', function ([owner, wallet, stranger]) { }); describe('paused', function () { - const from = owner; + const from = pauser; it('is not paused by default', async function () { const paused = await this.crowdsale.paused({ from }); @@ -116,7 +118,7 @@ contract('PausableCrowdsale', function ([owner, wallet, stranger]) { }); describe('when the crowdsale is paused', function () { - const from = owner; + const from = pauser; beforeEach('pausing', async function () { await this.crowdsale.pause({ from }); @@ -136,7 +138,7 @@ contract('PausableCrowdsale', function ([owner, wallet, stranger]) { }); describe('when the crowdsale is unpaused', function () { - const from = owner; + const from = pauser; describe('high-level purchase using fallback function', function () { it('should accept payments', async function () { From 7cf32870eff0cfbbfcafd20a9fcad6f5508ea15e Mon Sep 17 00:00:00 2001 From: Francisco Giordano Date: Wed, 12 Dec 2018 16:15:29 -0300 Subject: [PATCH 23/27] undo beforeEach descriptions --- test/crowdsale/PausableCrowdsale.test.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/crowdsale/PausableCrowdsale.test.js b/test/crowdsale/PausableCrowdsale.test.js index db880eae4ac..beddf032d9b 100644 --- a/test/crowdsale/PausableCrowdsale.test.js +++ b/test/crowdsale/PausableCrowdsale.test.js @@ -10,7 +10,7 @@ contract('PausableCrowdsale', function ([_, pauser, wallet, anyone]) { const rate = 1; const value = 1; - beforeEach('setting up', async function () { + beforeEach(async function () { const from = pauser; this.token = await SimpleToken.new({ from }); @@ -23,7 +23,7 @@ contract('PausableCrowdsale', function ([_, pauser, wallet, anyone]) { const from = pauser; describe('when the crowdsale is unpaused', function () { - beforeEach('pausing', async function () { + beforeEach(async function () { const { logs } = await this.crowdsale.pause({ from }); this.logs = logs; }); @@ -39,7 +39,7 @@ contract('PausableCrowdsale', function ([_, pauser, wallet, anyone]) { }); describe('when the crowdsale is paused', function () { - beforeEach('pausing', async function () { + beforeEach(async function () { await this.crowdsale.pause({ from }); }); @@ -120,7 +120,7 @@ contract('PausableCrowdsale', function ([_, pauser, wallet, anyone]) { describe('when the crowdsale is paused', function () { const from = pauser; - beforeEach('pausing', async function () { + beforeEach(async function () { await this.crowdsale.pause({ from }); }); From e6cbaf499eb234cec20a5766a4ed91f640c21716 Mon Sep 17 00:00:00 2001 From: Francisco Giordano Date: Wed, 12 Dec 2018 17:34:04 -0300 Subject: [PATCH 24/27] simplify tests --- test/crowdsale/PausableCrowdsale.test.js | 137 +++-------------------- 1 file changed, 14 insertions(+), 123 deletions(-) diff --git a/test/crowdsale/PausableCrowdsale.test.js b/test/crowdsale/PausableCrowdsale.test.js index beddf032d9b..3a4c32fbc11 100644 --- a/test/crowdsale/PausableCrowdsale.test.js +++ b/test/crowdsale/PausableCrowdsale.test.js @@ -1,5 +1,4 @@ const shouldFail = require('../helpers/shouldFail'); -const expectEvent = require('../helpers/expectEvent'); const PausableCrowdsale = artifacts.require('PausableCrowdsaleImpl'); const SimpleToken = artifacts.require('SimpleToken'); @@ -10,144 +9,36 @@ contract('PausableCrowdsale', function ([_, pauser, wallet, anyone]) { const rate = 1; const value = 1; - beforeEach(async function () { - const from = pauser; + const from = pauser; + beforeEach(async function () { this.token = await SimpleToken.new({ from }); this.crowdsale = await PausableCrowdsale.new(rate, wallet, this.token.address, { from }); - await this.token.transfer(this.crowdsale.address, value, { from }); + await this.token.transfer(this.crowdsale.address, 2 * value, { from }); }); - describe('pause()', function () { - describe('when the sender is the crowdsale pauser', function () { - const from = pauser; - - describe('when the crowdsale is unpaused', function () { - beforeEach(async function () { - const { logs } = await this.crowdsale.pause({ from }); - this.logs = logs; - }); - - it('pauses the crowdsale', async function () { - const paused = await this.crowdsale.paused(); - paused.should.equal(true); - }); - - it('emits a Paused event', async function () { - expectEvent.inLogs(this.logs, 'Paused'); - }); - }); - - describe('when the crowdsale is paused', function () { - beforeEach(async function () { - await this.crowdsale.pause({ from }); - }); - - it('reverts', async function () { - await shouldFail.reverting(this.crowdsale.pause({ from })); - }); - }); - }); - - describe('when the sender is not the crowdsale pauser', function () { - const from = anyone; - - it('reverts', async function () { - await shouldFail.reverting(this.crowdsale.pause({ from })); - }); - }); + it('purchases work', async function () { + await this.crowdsale.sendTransaction({ from, value }); + await this.crowdsale.buyTokens(from, { from, value }); }); - describe('unpause()', function () { - describe('when the sender is the crowdsale pauser', function () { - const from = pauser; - - describe('when the crowdsale is paused', function () { - beforeEach(async function () { - await this.crowdsale.pause({ from }); - }); - - it('unpauses the crowdsale', async function () { - await this.crowdsale.unpause({ from }); - const paused = await this.crowdsale.paused(); - paused.should.equal(false); - }); - - it('emits an Unpause event', async function () { - const { logs } = await this.crowdsale.unpause({ from }); - expectEvent.inLogs(logs, 'Unpaused'); - }); - }); - - describe('when the crowdsale is unpaused', function () { - it('reverts', async function () { - await shouldFail.reverting(this.crowdsale.unpause({ from })); - }); - }); - }); - - describe('when the sender is not the crowdsale pauser', function () { - const from = anyone; - - it('reverts', async function () { - await shouldFail.reverting(this.crowdsale.unpause({ from })); - }); - }); - }); - - describe('paused', function () { - const from = pauser; - - it('is not paused by default', async function () { - const paused = await this.crowdsale.paused({ from }); - paused.should.equal(false); - }); - - it('is paused after being paused', async function () { - await this.crowdsale.pause({ from }); - const paused = await this.crowdsale.paused({ from }); - paused.should.equal(true); - }); - - it('is not paused after being paused and then unpaused', async function () { - await this.crowdsale.pause({ from }); - await this.crowdsale.unpause({ from }); - const paused = await this.crowdsale.paused({ from }); - paused.should.equal(false); - }); - }); - - describe('when the crowdsale is paused', function () { - const from = pauser; - + context('after pause', function () { beforeEach(async function () { await this.crowdsale.pause({ from }); }); - describe('high-level purchase using fallback function', function () { - it('reverts', async function () { - await shouldFail.reverting(this.crowdsale.sendTransaction({ from, value })); - }); + it('purchases do not work', async function () { + await shouldFail.reverting(this.crowdsale.sendTransaction({ from, value })); + await shouldFail.reverting(this.crowdsale.buyTokens(from, { from, value })); }); - describe('buyTokens()', function () { - it('reverts', async function () { - await shouldFail.reverting(this.crowdsale.buyTokens(from, { from, value })); + context('after unpause', function () { + beforeEach(async function () { + await this.crowdsale.unpause({ from }); }); - }); - }); - - describe('when the crowdsale is unpaused', function () { - const from = pauser; - describe('high-level purchase using fallback function', function () { - it('should accept payments', async function () { + it('purchases work', async function () { await this.crowdsale.sendTransaction({ from, value }); - }); - }); - - describe('buyTokens()', function () { - it('should accept payments', async function () { await this.crowdsale.buyTokens(from, { from, value }); }); }); From 268182e7af397de66688b9d0c61c900e50d018c6 Mon Sep 17 00:00:00 2001 From: Francisco Giordano Date: Wed, 12 Dec 2018 18:25:37 -0300 Subject: [PATCH 25/27] fix transaction senders to be the anyone account --- test/crowdsale/PausableCrowdsale.test.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/test/crowdsale/PausableCrowdsale.test.js b/test/crowdsale/PausableCrowdsale.test.js index 3a4c32fbc11..702e0199ef9 100644 --- a/test/crowdsale/PausableCrowdsale.test.js +++ b/test/crowdsale/PausableCrowdsale.test.js @@ -9,35 +9,41 @@ contract('PausableCrowdsale', function ([_, pauser, wallet, anyone]) { const rate = 1; const value = 1; - const from = pauser; - beforeEach(async function () { + const from = pauser; + this.token = await SimpleToken.new({ from }); this.crowdsale = await PausableCrowdsale.new(rate, wallet, this.token.address, { from }); await this.token.transfer(this.crowdsale.address, 2 * value, { from }); }); it('purchases work', async function () { + const from = anyone; + await this.crowdsale.sendTransaction({ from, value }); await this.crowdsale.buyTokens(from, { from, value }); }); context('after pause', function () { beforeEach(async function () { - await this.crowdsale.pause({ from }); + await this.crowdsale.pause({ from: pauser }); }); it('purchases do not work', async function () { + const from = anyone; + await shouldFail.reverting(this.crowdsale.sendTransaction({ from, value })); await shouldFail.reverting(this.crowdsale.buyTokens(from, { from, value })); }); context('after unpause', function () { beforeEach(async function () { - await this.crowdsale.unpause({ from }); + await this.crowdsale.unpause({ from: pauser }); }); it('purchases work', async function () { + const from = anyone; + await this.crowdsale.sendTransaction({ from, value }); await this.crowdsale.buyTokens(from, { from, value }); }); From 1f2522e2efe5ef1fca05345e73b46b75b64e621f Mon Sep 17 00:00:00 2001 From: Francisco Giordano Date: Thu, 13 Dec 2018 10:48:59 -0300 Subject: [PATCH 26/27] make transaction senders more explicit --- test/crowdsale/PausableCrowdsale.test.js | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/test/crowdsale/PausableCrowdsale.test.js b/test/crowdsale/PausableCrowdsale.test.js index 702e0199ef9..8191cd1143e 100644 --- a/test/crowdsale/PausableCrowdsale.test.js +++ b/test/crowdsale/PausableCrowdsale.test.js @@ -5,7 +5,7 @@ const SimpleToken = artifacts.require('SimpleToken'); require('../helpers/setup'); -contract('PausableCrowdsale', function ([_, pauser, wallet, anyone]) { +contract.only('PausableCrowdsale', function ([_, pauser, wallet, anyone]) { const rate = 1; const value = 1; @@ -18,10 +18,8 @@ contract('PausableCrowdsale', function ([_, pauser, wallet, anyone]) { }); it('purchases work', async function () { - const from = anyone; - - await this.crowdsale.sendTransaction({ from, value }); - await this.crowdsale.buyTokens(from, { from, value }); + await this.crowdsale.sendTransaction({ from: anyone, value }); + await this.crowdsale.buyTokens(anyone, { from: anyone, value }); }); context('after pause', function () { @@ -30,10 +28,8 @@ contract('PausableCrowdsale', function ([_, pauser, wallet, anyone]) { }); it('purchases do not work', async function () { - const from = anyone; - - await shouldFail.reverting(this.crowdsale.sendTransaction({ from, value })); - await shouldFail.reverting(this.crowdsale.buyTokens(from, { from, value })); + await shouldFail.reverting(this.crowdsale.sendTransaction({ from: anyone, value })); + await shouldFail.reverting(this.crowdsale.buyTokens(anyone, { from: anyone, value })); }); context('after unpause', function () { @@ -42,10 +38,8 @@ contract('PausableCrowdsale', function ([_, pauser, wallet, anyone]) { }); it('purchases work', async function () { - const from = anyone; - - await this.crowdsale.sendTransaction({ from, value }); - await this.crowdsale.buyTokens(from, { from, value }); + await this.crowdsale.sendTransaction({ from: anyone, value }); + await this.crowdsale.buyTokens(anyone, { from: anyone, value }); }); }); }); From 955ac0fb0d5ba76136235fcb450d35a125915831 Mon Sep 17 00:00:00 2001 From: Francisco Giordano Date: Thu, 13 Dec 2018 13:41:24 -0300 Subject: [PATCH 27/27] remove mocha only --- test/crowdsale/PausableCrowdsale.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/crowdsale/PausableCrowdsale.test.js b/test/crowdsale/PausableCrowdsale.test.js index 8191cd1143e..2d0d0513d70 100644 --- a/test/crowdsale/PausableCrowdsale.test.js +++ b/test/crowdsale/PausableCrowdsale.test.js @@ -5,7 +5,7 @@ const SimpleToken = artifacts.require('SimpleToken'); require('../helpers/setup'); -contract.only('PausableCrowdsale', function ([_, pauser, wallet, anyone]) { +contract('PausableCrowdsale', function ([_, pauser, wallet, anyone]) { const rate = 1; const value = 1;