remove whitelist, add minimum amount
This commit is contained in:
parent
b635c8d751
commit
83a2ed12b9
|
@ -6,16 +6,17 @@ import "zeppelin-solidity/contracts/ownership/Ownable.sol";
|
|||
pragma solidity ^0.4.17;
|
||||
|
||||
contract PresaleOracles is Ownable {
|
||||
using SafeMath for uint256;
|
||||
uint256 public startTime;
|
||||
uint256 public endTime;
|
||||
uint256 public cap;
|
||||
uint256 public rate;
|
||||
bool public isInitialized = false;
|
||||
uint256 public totalInvestedInWei;
|
||||
mapping(address => uint256) public investorBalances;
|
||||
mapping(address => bool) public whitelist;
|
||||
uint256 public investorsLength;
|
||||
uint256 public minimumContribution;
|
||||
mapping(address => uint256) public investorBalances;
|
||||
address public vault;
|
||||
bool public isInitialized = false;
|
||||
// TESTED by Roman Storm
|
||||
function () public payable {
|
||||
buy();
|
||||
|
@ -24,26 +25,26 @@ contract PresaleOracles is Ownable {
|
|||
function Presale() public {
|
||||
}
|
||||
//TESTED by Roman Storm
|
||||
function initialize(uint256 _startTime, uint256 _endTime, uint256 _cap, address _vault) public onlyOwner {
|
||||
function initialize(uint256 _startTime, uint256 _endTime, uint256 _cap, uint256 _minimumContribution, address _vault) public onlyOwner {
|
||||
require(!isInitialized);
|
||||
require(_startTime != 0);
|
||||
require(_endTime != 0);
|
||||
require(_endTime > _startTime);
|
||||
require(_cap != 0);
|
||||
require(_minimumContribution != 0);
|
||||
require(_vault != 0x0);
|
||||
startTime = _startTime;
|
||||
endTime = _endTime;
|
||||
cap = _cap;
|
||||
isInitialized = true;
|
||||
minimumContribution =_minimumContribution;
|
||||
vault = _vault;
|
||||
}
|
||||
//TESTED by Roman Storm
|
||||
function buy() public payable {
|
||||
require(whitelist[msg.sender]);
|
||||
require(msg.value > 0);
|
||||
require(isValidPurchase());
|
||||
require(isInitialized);
|
||||
require(getTime() >= startTime && getTime() <= endTime);
|
||||
require(totalInvestedInWei + msg.value <= cap);
|
||||
address investor = msg.sender;
|
||||
investorBalances[investor] += msg.value;
|
||||
totalInvestedInWei += msg.value;
|
||||
|
@ -54,7 +55,7 @@ contract PresaleOracles is Ownable {
|
|||
function forwardFunds(uint256 _amount) internal {
|
||||
vault.transfer(_amount);
|
||||
}
|
||||
|
||||
//TESTED by Roman Storm
|
||||
function claimTokens(address _token) public onlyOwner {
|
||||
if (_token == 0x0) {
|
||||
owner.transfer(this.balance);
|
||||
|
@ -66,32 +67,13 @@ contract PresaleOracles is Ownable {
|
|||
token.transfer(owner, balance);
|
||||
}
|
||||
|
||||
function whitelistInvestor(address _newInvestor) public onlyOwner {
|
||||
if(!whitelist[_newInvestor]) {
|
||||
whitelist[_newInvestor] = true;
|
||||
investorsLength++;
|
||||
}
|
||||
}
|
||||
function whitelistInvestors(address[] _investors) external onlyOwner {
|
||||
require(_investors.length <= 250);
|
||||
for(uint8 i=0; i<_investors.length;i++) {
|
||||
address newInvestor = _investors[i];
|
||||
if(!whitelist[newInvestor]) {
|
||||
whitelist[newInvestor] = true;
|
||||
investorsLength++;
|
||||
}
|
||||
}
|
||||
}
|
||||
function blacklistInvestor(address _investor) public onlyOwner {
|
||||
if(whitelist[_investor]) {
|
||||
delete whitelist[_investor];
|
||||
if(investorsLength != 0) {
|
||||
investorsLength--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getTime() internal view returns(uint256) {
|
||||
return now;
|
||||
}
|
||||
//TESTED by Roman Storm
|
||||
function isValidPurchase() public view returns(bool) {
|
||||
bool hasMinimumAmount = investorBalances[msg.sender].add(msg.value) >= minimumContribution;
|
||||
bool withinCap = totalInvestedInWei.add(msg.value) <= cap;
|
||||
return hasMinimumAmount && withinCap;
|
||||
}
|
||||
}
|
147
test/presale.js
147
test/presale.js
|
@ -42,11 +42,11 @@ contract('Presale', function(accounts) {
|
|||
PRESALE_END_DATE = moment('2017-12-18T16:00:00Z').unix();
|
||||
})
|
||||
it('rejects if not sent by owner', async () => {
|
||||
await presaleContract.initialize(PRESALE_START_DATE, PRESALE_END_DATE, ETHER, accounts[1], {from: accounts[1]})
|
||||
await presaleContract.initialize(PRESALE_START_DATE, PRESALE_END_DATE, ETHER.mul(40000), ETHER.mul(100), accounts[1], {from: accounts[1]})
|
||||
.should.be.rejectedWith(REVERT_MSG);
|
||||
})
|
||||
it('sets values', async () => {
|
||||
await presaleContract.initialize(PRESALE_START_DATE, PRESALE_END_DATE, ETHER, accounts[1], {from: accounts[0]})
|
||||
await presaleContract.initialize(PRESALE_START_DATE, PRESALE_END_DATE, ETHER.mul(40000), ETHER.mul(100), accounts[1], {from: accounts[0]})
|
||||
true.should.be.equal(
|
||||
await presaleContract.isInitialized()
|
||||
)
|
||||
|
@ -56,42 +56,51 @@ contract('Presale', function(accounts) {
|
|||
PRESALE_END_DATE.should.be.bignumber.equal(
|
||||
await presaleContract.endTime()
|
||||
)
|
||||
ETHER.should.be.bignumber.equal(
|
||||
ETHER.mul(40000).should.be.bignumber.equal(
|
||||
await presaleContract.cap()
|
||||
)
|
||||
accounts[1].should.be.equal(
|
||||
await presaleContract.vault()
|
||||
)
|
||||
ETHER.mul(100).should.be.bignumber.equal(
|
||||
await presaleContract.minimumContribution()
|
||||
)
|
||||
|
||||
})
|
||||
it('cannot initialize twice', async () => {
|
||||
// require(!isInitialized);
|
||||
await presaleContract.initialize(PRESALE_START_DATE, PRESALE_END_DATE, ETHER, accounts[1], {from: accounts[0]})
|
||||
await presaleContract.initialize(PRESALE_START_DATE, PRESALE_END_DATE, ETHER, accounts[1], {from: accounts[0]})
|
||||
await presaleContract.initialize(PRESALE_START_DATE, PRESALE_END_DATE, ETHER.mul(40000), ETHER.mul(100), accounts[1], {from: accounts[0]})
|
||||
await presaleContract.initialize(PRESALE_START_DATE, PRESALE_END_DATE, ETHER.mul(40000), ETHER.mul(100), accounts[1], {from: accounts[0]})
|
||||
.should.be.rejectedWith(REVERT_MSG);
|
||||
})
|
||||
it('startTime cannot be 0', async () => {
|
||||
// require(_startTime != 0);
|
||||
await presaleContract.initialize(0, PRESALE_END_DATE, ETHER, accounts[1], {from: accounts[1]})
|
||||
await presaleContract.initialize(0, PRESALE_END_DATE, ETHER.mul(40000), ETHER.mul(100), accounts[1], {from: accounts[1]})
|
||||
.should.be.rejectedWith(REVERT_MSG);
|
||||
})
|
||||
it('endTime cannot be 0', async () => {
|
||||
// require(_endTime != 0);
|
||||
await presaleContract.initialize(PRESALE_START_DATE, 0, ETHER, accounts[1], {from: accounts[1]})
|
||||
await presaleContract.initialize(PRESALE_START_DATE, 0, ETHER.mul(40000), ETHER.mul(100), accounts[1], {from: accounts[1]})
|
||||
.should.be.rejectedWith(REVERT_MSG);
|
||||
})
|
||||
it('endTime cannot be less than startTime', async () => {
|
||||
// require(_endTime > _startTime);
|
||||
await presaleContract.initialize(PRESALE_END_DATE, PRESALE_START_DATE, ETHER, accounts[1], {from: accounts[1]})
|
||||
await presaleContract.initialize(PRESALE_END_DATE, PRESALE_START_DATE, ETHER.mul(40000), ETHER.mul(100), accounts[1], {from: accounts[1]})
|
||||
.should.be.rejectedWith(REVERT_MSG);
|
||||
})
|
||||
it('cap cannot be 0', async () => {
|
||||
// require(_cap != 0);
|
||||
await presaleContract.initialize(PRESALE_START_DATE, PRESALE_END_DATE, 0, accounts[1], {from: accounts[1]})
|
||||
await presaleContract.initialize(PRESALE_START_DATE, PRESALE_END_DATE, 0, ETHER.mul(100), accounts[1], {from: accounts[1]})
|
||||
.should.be.rejectedWith(REVERT_MSG);
|
||||
})
|
||||
it('vault cannot be 0x0', async () => {
|
||||
// require(_vault != 0x0);
|
||||
await presaleContract.initialize(PRESALE_START_DATE, PRESALE_END_DATE, ETHER, '0x0', {from: accounts[1]})
|
||||
await presaleContract.initialize(PRESALE_START_DATE, PRESALE_END_DATE, ETHER.mul(40000), ETHER.mul(100), '0x0', {from: accounts[1]})
|
||||
.should.be.rejectedWith(REVERT_MSG);
|
||||
})
|
||||
it('minimumContribution cannot be 0', async () => {
|
||||
// require(_vault != 0x0);
|
||||
await presaleContract.initialize(PRESALE_START_DATE, PRESALE_END_DATE, ETHER.mul(40000), 0, accounts[1], {from: accounts[1]})
|
||||
.should.be.rejectedWith(REVERT_MSG);
|
||||
})
|
||||
})
|
||||
|
@ -101,43 +110,36 @@ contract('Presale', function(accounts) {
|
|||
beforeEach(async () => {
|
||||
PRESALE_START_DATE = moment('2017-12-11T16:00:00Z').unix();
|
||||
PRESALE_END_DATE = moment('2017-12-18T16:00:00Z').unix();
|
||||
await presaleContract.initialize(PRESALE_START_DATE, PRESALE_END_DATE, ETHER.mul(2), accounts[1], {from: accounts[0]})
|
||||
})
|
||||
it('cannot buy if not whitelisted', async () => {
|
||||
// require(whitelist[msg.sender]);
|
||||
await presaleContract.sendTransaction({amount: ETHER})
|
||||
.should.be.rejectedWith(REVERT_MSG);
|
||||
await presaleContract.initialize(PRESALE_START_DATE, PRESALE_END_DATE, ETHER.mul(40000), ETHER.mul(100), accounts[1], {from: accounts[0]})
|
||||
})
|
||||
it('cannot buy if not value is 0', async () => {
|
||||
// require(msg.value > 0);
|
||||
await presaleContract.setTime(PRESALE_START_DATE);
|
||||
await presaleContract.whitelistInvestor(accounts[0]);
|
||||
await presaleContract.sendTransaction({value: 0})
|
||||
.should.be.rejectedWith(REVERT_MSG);
|
||||
})
|
||||
|
||||
it('can not buy if not initialized', async () => {
|
||||
// require(isInitialized);
|
||||
await presaleContract.sendTransaction({amount: ETHER})
|
||||
.should.be.rejectedWith('VM Exception while processing transaction: revert');
|
||||
it('cannot buy if not value is less than minimum', async () => {
|
||||
// require(msg.value > 0);
|
||||
await presaleContract.setTime(PRESALE_START_DATE);
|
||||
await presaleContract.sendTransaction({value: ETHER.mul(99)})
|
||||
.should.be.rejectedWith(REVERT_MSG);
|
||||
})
|
||||
|
||||
it('can not buy if time is not within startTime&endTime', async ()=> {
|
||||
// require(now >= startTime && now <= endTime);
|
||||
await presaleContract.setTime(PRESALE_START_DATE - 1);
|
||||
await presaleContract.whitelistInvestor(accounts[0]);
|
||||
await presaleContract.sendTransaction({value: ETHER})
|
||||
await presaleContract.sendTransaction({value: ETHER.mul(100)})
|
||||
.should.be.rejectedWith(REVERT_MSG);
|
||||
await presaleContract.setTime(PRESALE_END_DATE + 1);
|
||||
await presaleContract.sendTransaction({value: ETHER})
|
||||
await presaleContract.sendTransaction({value: ETHER.mul(100)})
|
||||
.should.be.rejectedWith(REVERT_MSG);
|
||||
})
|
||||
|
||||
it('can not buy more than cap', async () => {
|
||||
// require(totalInvestedInWei + msg.value <= cap);
|
||||
// bool withinCap = totalInvestedInWei.add(msg.value) <= cap;
|
||||
await presaleContract.setTime(PRESALE_START_DATE);
|
||||
await presaleContract.whitelistInvestor(accounts[0]);
|
||||
await presaleContract.sendTransaction({value: ETHER.mul(2) + 1})
|
||||
await presaleContract.sendTransaction({value: ETHER.mul(40000).add(1)})
|
||||
.should.be.rejectedWith(REVERT_MSG);
|
||||
})
|
||||
|
||||
|
@ -148,99 +150,32 @@ contract('Presale', function(accounts) {
|
|||
const vault = accounts[1];
|
||||
const preVaultBalance = await web3.eth.getBalance(vault);
|
||||
await presaleContract.setTime(PRESALE_START_DATE);
|
||||
await presaleContract.whitelistInvestor(accounts[0]);
|
||||
await presaleContract.sendTransaction({value: ETHER});
|
||||
ETHER.should.be.bignumber.equal(
|
||||
await presaleContract.sendTransaction({value: ETHER.mul(100)});
|
||||
ETHER.mul(100).should.be.bignumber.equal(
|
||||
await presaleContract.investorBalances(accounts[0])
|
||||
)
|
||||
ETHER.should.be.bignumber.equal(
|
||||
ETHER.mul(100).should.be.bignumber.equal(
|
||||
await presaleContract.totalInvestedInWei()
|
||||
)
|
||||
preVaultBalance.add(ETHER).should.be.bignumber.equal(
|
||||
preVaultBalance.add(ETHER.mul(100)).should.be.bignumber.equal(
|
||||
await web3.eth.getBalance(vault)
|
||||
)
|
||||
await presaleContract.sendTransaction({value: ETHER});
|
||||
await presaleContract.sendTransaction({value: ETHER.mul(2)});
|
||||
|
||||
ETHER.mul(2).should.be.bignumber.equal(
|
||||
ETHER.mul(100).add(ETHER.mul(2)).should.be.bignumber.equal(
|
||||
await presaleContract.investorBalances(accounts[0])
|
||||
)
|
||||
ETHER.mul(2).should.be.bignumber.equal(
|
||||
ETHER.mul(100).add(ETHER.mul(2)).should.be.bignumber.equal(
|
||||
await presaleContract.totalInvestedInWei()
|
||||
)
|
||||
preVaultBalance.add(ETHER.mul(2)).should.be.bignumber.equal(
|
||||
preVaultBalance.add(ETHER.mul(100).add(ETHER.mul(2))).should.be.bignumber.equal(
|
||||
await web3.eth.getBalance(vault)
|
||||
)
|
||||
|
||||
await presaleContract.sendTransaction({value: ETHER.mul(40000-100-2).add(1)})
|
||||
.should.be.rejectedWith(REVERT_MSG);
|
||||
})
|
||||
})
|
||||
|
||||
describe('#whitelistInvestor', async ()=>{
|
||||
it('cannot by called by non-owner', async ()=> {
|
||||
await presaleContract.whitelistInvestor(accounts[0], {from: accounts[1]})
|
||||
.should.be.rejectedWith(REVERT_MSG);
|
||||
})
|
||||
it('whitelists an investor', async ()=> {
|
||||
'0'.should.be.bignumber.equal(
|
||||
await presaleContract.investorsLength()
|
||||
)
|
||||
false.should.be.equal(
|
||||
await presaleContract.whitelist(accounts[0])
|
||||
)
|
||||
await presaleContract.whitelistInvestor(accounts[0]);
|
||||
true.should.be.equal(
|
||||
await presaleContract.whitelist(accounts[0])
|
||||
)
|
||||
'1'.should.be.bignumber.equal(
|
||||
await presaleContract.investorsLength()
|
||||
)
|
||||
})
|
||||
})
|
||||
describe('#whitelistInvestors', async ()=>{
|
||||
it('cannot by called by non-owner', async ()=> {
|
||||
await presaleContract.whitelistInvestors([accounts[0]], {from: accounts[1]})
|
||||
.should.be.rejectedWith(REVERT_MSG);
|
||||
})
|
||||
it('whitelists investors', async ()=> {
|
||||
'0'.should.be.bignumber.equal(
|
||||
await presaleContract.investorsLength()
|
||||
)
|
||||
false.should.be.equal(
|
||||
await presaleContract.whitelist(accounts[0])
|
||||
)
|
||||
await presaleContract.whitelistInvestors([accounts[0], accounts[1], accounts[2]]);
|
||||
true.should.be.equal(
|
||||
await presaleContract.whitelist(accounts[2])
|
||||
)
|
||||
'3'.should.be.bignumber.equal(
|
||||
await presaleContract.investorsLength()
|
||||
)
|
||||
})
|
||||
})
|
||||
describe('#blacklistInvestor', async ()=>{
|
||||
it('cannot by called by non-owner', async ()=> {
|
||||
await presaleContract.blacklistInvestor(accounts[0], {from: accounts[1]})
|
||||
.should.be.rejectedWith(REVERT_MSG);
|
||||
})
|
||||
it('blacklist an investors', async ()=> {
|
||||
'0'.should.be.bignumber.equal(
|
||||
await presaleContract.investorsLength()
|
||||
)
|
||||
false.should.be.equal(
|
||||
await presaleContract.whitelist(accounts[0])
|
||||
)
|
||||
await presaleContract.whitelistInvestors([accounts[0], accounts[1], accounts[2]]);
|
||||
true.should.be.equal(
|
||||
await presaleContract.whitelist(accounts[0])
|
||||
)
|
||||
'3'.should.be.bignumber.equal(
|
||||
await presaleContract.investorsLength()
|
||||
)
|
||||
await presaleContract.blacklistInvestor(accounts[0]);
|
||||
false.should.be.equal(
|
||||
await presaleContract.whitelist(accounts[0])
|
||||
)
|
||||
'2'.should.be.bignumber.equal(
|
||||
await presaleContract.investorsLength()
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
});
|
Loading…
Reference in New Issue