Commit 616124e3 by Leo Arias Committed by Francisco Giordano

Update modifiers to call public view functions (#1277)

* Update modifiers to call public view functions.

Fixes #1179.

* remove isMinter

* fix is owner call

* fix isOpen

* Remove unnecessary solium disable
parent b8a70f0e
...@@ -18,8 +18,7 @@ contract TimedCrowdsale is Crowdsale { ...@@ -18,8 +18,7 @@ contract TimedCrowdsale is Crowdsale {
* @dev Reverts if not in crowdsale time range. * @dev Reverts if not in crowdsale time range.
*/ */
modifier onlyWhileOpen { modifier onlyWhileOpen {
// solium-disable-next-line security/no-block-members require(isOpen());
require(block.timestamp >= openingTime && block.timestamp <= closingTime);
_; _;
} }
...@@ -38,6 +37,14 @@ contract TimedCrowdsale is Crowdsale { ...@@ -38,6 +37,14 @@ contract TimedCrowdsale is Crowdsale {
} }
/** /**
* @return true if the crowdsale is open, false otherwise.
*/
function isOpen() public view returns (bool) {
// solium-disable-next-line security/no-block-members
return block.timestamp >= openingTime && block.timestamp <= closingTime;
}
/**
* @dev Checks whether the period in which the crowdsale is open has already elapsed. * @dev Checks whether the period in which the crowdsale is open has already elapsed.
* @return Whether crowdsale period has elapsed * @return Whether crowdsale period has elapsed
*/ */
......
...@@ -36,11 +36,18 @@ contract Ownable { ...@@ -36,11 +36,18 @@ contract Ownable {
* @dev Throws if called by any account other than the owner. * @dev Throws if called by any account other than the owner.
*/ */
modifier onlyOwner() { modifier onlyOwner() {
require(msg.sender == owner_); require(isOwner());
_; _;
} }
/** /**
* @return true if `msg.sender` is the owner of the contract.
*/
function isOwner() public view returns(bool) {
return msg.sender == owner_;
}
/**
* @dev Allows the current owner to relinquish control of the contract. * @dev Allows the current owner to relinquish control of the contract.
* @notice Renouncing to ownership will leave the contract without an owner. * @notice Renouncing to ownership will leave the contract without an owner.
* It will not be possible to call the functions with the `onlyOwner` * It will not be possible to call the functions with the `onlyOwner`
......
...@@ -16,13 +16,13 @@ contract ERC20Mintable is ERC20, Ownable { ...@@ -16,13 +16,13 @@ contract ERC20Mintable is ERC20, Ownable {
bool private mintingFinished_ = false; bool private mintingFinished_ = false;
modifier canMint() { modifier onlyBeforeMintingFinished() {
require(!mintingFinished_); require(!mintingFinished_);
_; _;
} }
modifier hasMintPermission() { modifier onlyMinter() {
require(msg.sender == owner()); require(isOwner());
_; _;
} }
...@@ -44,8 +44,8 @@ contract ERC20Mintable is ERC20, Ownable { ...@@ -44,8 +44,8 @@ contract ERC20Mintable is ERC20, Ownable {
uint256 _amount uint256 _amount
) )
public public
hasMintPermission onlyMinter
canMint onlyBeforeMintingFinished
returns (bool) returns (bool)
{ {
_mint(_to, _amount); _mint(_to, _amount);
...@@ -57,7 +57,12 @@ contract ERC20Mintable is ERC20, Ownable { ...@@ -57,7 +57,12 @@ contract ERC20Mintable is ERC20, Ownable {
* @dev Function to stop minting new tokens. * @dev Function to stop minting new tokens.
* @return True if the operation was successful. * @return True if the operation was successful.
*/ */
function finishMinting() public onlyOwner canMint returns (bool) { function finishMinting()
public
onlyOwner
onlyBeforeMintingFinished
returns (bool)
{
mintingFinished_ = true; mintingFinished_ = true;
emit MintFinished(); emit MintFinished();
return true; return true;
......
...@@ -18,7 +18,7 @@ contract RBACMintableToken is ERC20Mintable, RBAC { ...@@ -18,7 +18,7 @@ contract RBACMintableToken is ERC20Mintable, RBAC {
/** /**
* @dev override the Mintable token modifier to add role based logic * @dev override the Mintable token modifier to add role based logic
*/ */
modifier hasMintPermission() { modifier onlyMinter() {
checkRole(msg.sender, ROLE_MINTER); checkRole(msg.sender, ROLE_MINTER);
_; _;
} }
......
...@@ -52,17 +52,20 @@ contract('TimedCrowdsale', function ([_, investor, wallet, purchaser]) { ...@@ -52,17 +52,20 @@ contract('TimedCrowdsale', function ([_, investor, wallet, purchaser]) {
it('should be ended only after end', async function () { it('should be ended only after end', async function () {
(await this.crowdsale.hasClosed()).should.equal(false); (await this.crowdsale.hasClosed()).should.equal(false);
await increaseTimeTo(this.afterClosingTime); await increaseTimeTo(this.afterClosingTime);
(await this.crowdsale.isOpen()).should.equal(false);
(await this.crowdsale.hasClosed()).should.equal(true); (await this.crowdsale.hasClosed()).should.equal(true);
}); });
describe('accepting payments', function () { describe('accepting payments', function () {
it('should reject payments before start', async function () { it('should reject payments before start', async function () {
(await this.crowdsale.isOpen()).should.equal(false);
await expectThrow(this.crowdsale.send(value), EVMRevert); await expectThrow(this.crowdsale.send(value), EVMRevert);
await expectThrow(this.crowdsale.buyTokens(investor, { from: purchaser, value: value }), EVMRevert); await expectThrow(this.crowdsale.buyTokens(investor, { from: purchaser, value: value }), EVMRevert);
}); });
it('should accept payments after start', async function () { it('should accept payments after start', async function () {
await increaseTimeTo(this.openingTime); await increaseTimeTo(this.openingTime);
(await this.crowdsale.isOpen()).should.equal(true);
await this.crowdsale.send(value); await this.crowdsale.send(value);
await this.crowdsale.buyTokens(investor, { value: value, from: purchaser }); await this.crowdsale.buyTokens(investor, { value: value, from: purchaser });
}); });
......
...@@ -13,8 +13,11 @@ function shouldBehaveLikeOwnable (owner, [anyone]) { ...@@ -13,8 +13,11 @@ function shouldBehaveLikeOwnable (owner, [anyone]) {
}); });
it('changes owner after transfer', async function () { it('changes owner after transfer', async function () {
(await this.ownable.isOwner({ from: anyone })).should.be.equal(false);
await this.ownable.transferOwnership(anyone, { from: owner }); await this.ownable.transferOwnership(anyone, { from: owner });
(await this.ownable.owner()).should.equal(anyone); (await this.ownable.owner()).should.equal(anyone);
(await this.ownable.isOwner({ from: anyone })).should.be.equal(true);
}); });
it('should prevent non-owners from transfering', async function () { it('should prevent non-owners from transfering', async function () {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment