Skip to content

Commit

Permalink
Merge branch 'master' into rbac-migration
Browse files Browse the repository at this point in the history
  • Loading branch information
come-maiz committed Sep 7, 2018
2 parents e9cc437 + bf95602 commit 436c89f
Show file tree
Hide file tree
Showing 18 changed files with 70 additions and 114 deletions.
4 changes: 2 additions & 2 deletions contracts/crowdsale/price/IncreasingPriceCrowdsale.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ contract IncreasingPriceCrowdsale is TimedCrowdsale {
*/
function getCurrentRate() public view returns (uint256) {
// solium-disable-next-line security/no-block-members
uint256 elapsedTime = block.timestamp.sub(openingTime);
uint256 timeRange = closingTime.sub(openingTime);
uint256 elapsedTime = block.timestamp.sub(openingTime());
uint256 timeRange = closingTime().sub(openingTime());
uint256 rateRange = initialRate_.sub(finalRate_);
return initialRate_.sub(elapsedTime.mul(rateRange).div(timeRange));
}
Expand Down
39 changes: 11 additions & 28 deletions contracts/crowdsale/validation/IndividuallyCappedCrowdsale.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import "../../access/roles/CapperRole.sol";

/**
* @title IndividuallyCappedCrowdsale
* @dev Crowdsale with per-user caps.
* @dev Crowdsale with per-beneficiary caps.
*/
contract IndividuallyCappedCrowdsale is Crowdsale, CapperRole {
using SafeMath for uint256;
Expand All @@ -16,53 +16,36 @@ contract IndividuallyCappedCrowdsale is Crowdsale, CapperRole {
mapping(address => uint256) private caps_;

/**
* @dev Sets a specific user's maximum contribution.
* @dev Sets a specific beneficiary's maximum contribution.
* @param _beneficiary Address to be capped
* @param _cap Wei limit for individual contribution
*/
function setUserCap(address _beneficiary, uint256 _cap) external onlyCapper {
function setCap(address _beneficiary, uint256 _cap) external onlyCapper {
caps_[_beneficiary] = _cap;
}

/**
* @dev Sets a group of users' maximum contribution.
* @param _beneficiaries List of addresses to be capped
* @param _cap Wei limit for individual contribution
*/
function setGroupCap(
address[] _beneficiaries,
uint256 _cap
)
external
onlyCapper
{
for (uint256 i = 0; i < _beneficiaries.length; i++) {
caps_[_beneficiaries[i]] = _cap;
}
}

/**
* @dev Returns the cap of a specific user.
* @dev Returns the cap of a specific beneficiary.
* @param _beneficiary Address whose cap is to be checked
* @return Current cap for individual user
* @return Current cap for individual beneficiary
*/
function getUserCap(address _beneficiary) public view returns (uint256) {
function getCap(address _beneficiary) public view returns (uint256) {
return caps_[_beneficiary];
}

/**
* @dev Returns the amount contributed so far by a sepecific user.
* @dev Returns the amount contributed so far by a specific beneficiary.
* @param _beneficiary Address of contributor
* @return User contribution so far
* @return Beneficiary contribution so far
*/
function getUserContribution(address _beneficiary)
function getContribution(address _beneficiary)
public view returns (uint256)
{
return contributions_[_beneficiary];
}

/**
* @dev Extend parent behavior requiring purchase to respect the user's funding cap.
* @dev Extend parent behavior requiring purchase to respect the beneficiary's funding cap.
* @param _beneficiary Token purchaser
* @param _weiAmount Amount of wei contributed
*/
Expand All @@ -78,7 +61,7 @@ contract IndividuallyCappedCrowdsale is Crowdsale, CapperRole {
}

/**
* @dev Extend parent behavior to update user contributions
* @dev Extend parent behavior to update beneficiary contributions
* @param _beneficiary Token purchaser
* @param _weiAmount Amount of wei contributed
*/
Expand Down
26 changes: 20 additions & 6 deletions contracts/crowdsale/validation/TimedCrowdsale.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import "../Crowdsale.sol";
contract TimedCrowdsale is Crowdsale {
using SafeMath for uint256;

uint256 public openingTime;
uint256 public closingTime;
uint256 private openingTime_;
uint256 private closingTime_;

/**
* @dev Reverts if not in crowdsale time range.
Expand All @@ -32,16 +32,30 @@ contract TimedCrowdsale is Crowdsale {
require(_openingTime >= block.timestamp);
require(_closingTime >= _openingTime);

openingTime = _openingTime;
closingTime = _closingTime;
openingTime_ = _openingTime;
closingTime_ = _closingTime;
}

/**
* @return the crowdsale opening time.
*/
function openingTime() public view returns(uint256) {
return openingTime_;
}

/**
* @return the crowdsale closing time.
*/
function closingTime() public view returns(uint256) {
return closingTime_;
}

/**
* @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;
return block.timestamp >= openingTime_ && block.timestamp <= closingTime_;
}

/**
Expand All @@ -50,7 +64,7 @@ contract TimedCrowdsale is Crowdsale {
*/
function hasClosed() public view returns (bool) {
// solium-disable-next-line security/no-block-members
return block.timestamp > closingTime;
return block.timestamp > closingTime_;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion contracts/cryptography/MerkleProof.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ library MerkleProof {
* @param _root Merkle root
* @param _leaf Leaf of Merkle tree
*/
function verifyProof(
function verify(
bytes32[] _proof,
bytes32 _root,
bytes32 _leaf
Expand Down
2 changes: 1 addition & 1 deletion contracts/drafts/ERC1046/TokenMetadata.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.21;
pragma solidity ^0.4.24;

import "../../token/ERC20/IERC20.sol";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import "./IERC165.sol";


/**
* @title SupportsInterfaceWithLookup
* @title ERC165
* @author Matt Condon (@shrugs)
* @dev Implements ERC165 using a lookup table.
*/
contract SupportsInterfaceWithLookup is IERC165 {
contract ERC165 is IERC165 {

bytes4 private constant InterfaceId_ERC165 = 0x01ffc9a7;
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
pragma solidity ^0.4.24;

import "../introspection/SupportsInterfaceWithLookup.sol";
import "../introspection/ERC165.sol";


contract SupportsInterfaceWithLookupMock is SupportsInterfaceWithLookup {
contract ERC165Mock is ERC165 {
function registerInterface(bytes4 _interfaceId)
public
{
Expand Down
2 changes: 1 addition & 1 deletion contracts/mocks/ERC20WithMetadataMock.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.21;
pragma solidity ^0.4.24;

import "../token/ERC20/ERC20.sol";
import "../drafts/ERC1046/TokenMetadata.sol";
Expand Down
4 changes: 2 additions & 2 deletions contracts/mocks/MerkleProofWrapper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { MerkleProof } from "../cryptography/MerkleProof.sol";

contract MerkleProofWrapper {

function verifyProof(
function verify(
bytes32[] _proof,
bytes32 _root,
bytes32 _leaf
Expand All @@ -14,6 +14,6 @@ contract MerkleProofWrapper {
pure
returns (bool)
{
return MerkleProof.verifyProof(_proof, _root, _leaf);
return MerkleProof.verify(_proof, _root, _leaf);
}
}
2 changes: 1 addition & 1 deletion contracts/payment/ConditionalEscrow.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.23;
pragma solidity ^0.4.24;

import "./Escrow.sol";

Expand Down
2 changes: 1 addition & 1 deletion contracts/payment/Escrow.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.23;
pragma solidity ^0.4.24;

import "../math/SafeMath.sol";
import "../ownership/Secondary.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/payment/RefundEscrow.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.23;
pragma solidity ^0.4.24;

import "./ConditionalEscrow.sol";
import "../ownership/Secondary.sol";
Expand Down
4 changes: 2 additions & 2 deletions contracts/token/ERC721/ERC721.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ pragma solidity ^0.4.24;

import "./IERC721.sol";
import "./ERC721Basic.sol";
import "../../introspection/SupportsInterfaceWithLookup.sol";
import "../../introspection/ERC165.sol";


/**
Expand All @@ -11,7 +11,7 @@ import "../../introspection/SupportsInterfaceWithLookup.sol";
* Moreover, it includes approve all functionality using operator terminology
* @dev see https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md
*/
contract ERC721 is SupportsInterfaceWithLookup, ERC721Basic, IERC721 {
contract ERC721 is ERC165, ERC721Basic, IERC721 {

// Token name
string internal name_;
Expand Down
6 changes: 4 additions & 2 deletions contracts/token/ERC721/ERC721Basic.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import "./IERC721Basic.sol";
import "./IERC721Receiver.sol";
import "../../math/SafeMath.sol";
import "../../utils/Address.sol";
import "../../introspection/SupportsInterfaceWithLookup.sol";
import "../../introspection/ERC165.sol";


/**
* @title ERC721 Non-Fungible Token Standard basic implementation
* @dev see https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md
*/
contract ERC721Basic is SupportsInterfaceWithLookup, IERC721Basic {
contract ERC721Basic is ERC165, IERC721Basic {

using SafeMath for uint256;
using Address for address;
Expand Down Expand Up @@ -93,10 +93,12 @@ contract ERC721Basic is SupportsInterfaceWithLookup, IERC721Basic {

/**
* @dev Gets the approved address for a token ID, or zero if no address set
* Reverts if the token ID does not exist.
* @param _tokenId uint256 ID of the token to query the approval of
* @return address currently approved for the given token ID
*/
function getApproved(uint256 _tokenId) public view returns (address) {
require(_exists(_tokenId));
return tokenApprovals_[_tokenId];
}

Expand Down
59 changes: 7 additions & 52 deletions test/crowdsale/IndividuallyCappedCrowdsale.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,18 @@ contract('IndividuallyCappedCrowdsale', function (

describe('individual caps', function () {
it('sets a cap when the sender is a capper', async function () {
await this.crowdsale.setUserCap(alice, capAlice, { from: capper });
(await this.crowdsale.getUserCap(alice)).should.be.bignumber.equal(capAlice);
await this.crowdsale.setCap(alice, capAlice, { from: capper });
(await this.crowdsale.getCap(alice)).should.be.bignumber.equal(capAlice);
});

it('reverts when a non-capper sets a cap', async function () {
await expectThrow(this.crowdsale.setUserCap(alice, capAlice, { from: anyone }), EVMRevert);
await expectThrow(this.crowdsale.setCap(alice, capAlice, { from: anyone }), EVMRevert);
});

context('with individual caps', function () {
beforeEach(async function () {
await this.crowdsale.setUserCap(alice, capAlice, { from: capper });
await this.crowdsale.setUserCap(bob, capBob, { from: capper });
await this.crowdsale.setCap(alice, capAlice, { from: capper });
await this.crowdsale.setCap(bob, capBob, { from: capper });
await this.token.transfer(this.crowdsale.address, tokenSupply);
});

Expand Down Expand Up @@ -80,57 +80,12 @@ contract('IndividuallyCappedCrowdsale', function (

describe('reporting state', function () {
it('should report correct cap', async function () {
(await this.crowdsale.getUserCap(alice)).should.be.bignumber.equal(capAlice);
(await this.crowdsale.getCap(alice)).should.be.bignumber.equal(capAlice);
});

it('should report actual contribution', async function () {
await this.crowdsale.buyTokens(alice, { value: lessThanCapAlice });
(await this.crowdsale.getUserContribution(alice)).should.be.bignumber.equal(lessThanCapAlice);
});
});
});
});

describe('group capping', function () {
it('sets caps when the sender is a capper', async function () {
await this.crowdsale.setGroupCap([bob, charlie], capBob, { from: capper });
(await this.crowdsale.getUserCap(bob)).should.be.bignumber.equal(capBob);
(await this.crowdsale.getUserCap(charlie)).should.be.bignumber.equal(capBob);
});

it('reverts when a non-capper set caps', async function () {
await expectThrow(this.crowdsale.setGroupCap([bob, charlie], capBob, { from: anyone }), EVMRevert);
});

context('with group caps', function () {
beforeEach(async function () {
await this.crowdsale.setGroupCap([bob, charlie], capBob, { from: capper });
await this.token.transfer(this.crowdsale.address, tokenSupply);
});

describe('accepting payments', function () {
it('should accept payments within cap', async function () {
await this.crowdsale.buyTokens(bob, { value: lessThanCapBoth });
await this.crowdsale.buyTokens(charlie, { value: lessThanCapBoth });
});

it('should reject payments outside cap', async function () {
await this.crowdsale.buyTokens(bob, { value: capBob });
await expectThrow(this.crowdsale.buyTokens(bob, { value: 1 }), EVMRevert);
await this.crowdsale.buyTokens(charlie, { value: capBob });
await expectThrow(this.crowdsale.buyTokens(charlie, { value: 1 }), EVMRevert);
});

it('should reject payments that exceed cap', async function () {
await expectThrow(this.crowdsale.buyTokens(bob, { value: capBob.plus(1) }), EVMRevert);
await expectThrow(this.crowdsale.buyTokens(charlie, { value: capBob.plus(1) }), EVMRevert);
});
});

describe('reporting state', function () {
it('should report correct cap', async function () {
(await this.crowdsale.getUserCap(bob)).should.be.bignumber.equal(capBob);
(await this.crowdsale.getUserCap(charlie)).should.be.bignumber.equal(capBob);
(await this.crowdsale.getContribution(alice)).should.be.bignumber.equal(lessThanCapAlice);
});
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
const { shouldSupportInterfaces } = require('./SupportsInterface.behavior');
const { assertRevert } = require('../helpers/assertRevert');

const SupportsInterfaceWithLookup = artifacts.require('SupportsInterfaceWithLookupMock');
const ERC165 = artifacts.require('ERC165Mock');

require('chai')
.should();

contract('SupportsInterfaceWithLookup', function () {
contract('ERC165', function () {
beforeEach(async function () {
this.mock = await SupportsInterfaceWithLookup.new();
this.mock = await ERC165.new();
});

it('does not allow 0xffffffff', async function () {
Expand Down
Loading

0 comments on commit 436c89f

Please sign in to comment.