Skip to content

Commit

Permalink
Replaced end and start of crowdsale with timestamps
Browse files Browse the repository at this point in the history
  • Loading branch information
Agusx1211 committed Oct 13, 2017
1 parent 70a42f2 commit 50a51b7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
20 changes: 10 additions & 10 deletions contracts/RCNCrowdsale.sol
Expand Up @@ -18,8 +18,8 @@ contract RCNCrowdsale is Crowdsale {

// crowdsale parameters
bool public isFinalized; // switched to true in operational state
uint256 public fundingStartBlock;
uint256 public fundingEndBlock;
uint256 public fundingStartTimestamp;
uint256 public fundingEndTimestamp;
uint256 public constant rcnFund = 490 * (10**6) * 10**decimals; // 490m RCN reserved for Ripio use
uint256 public constant tokenExchangeRate = 4000; // 4000 RCN tokens per 1 ETH
uint256 public constant tokenCreationCap = 1000 * (10**6) * 10**decimals;
Expand All @@ -39,22 +39,22 @@ contract RCNCrowdsale is Crowdsale {
// constructor
function RCNCrowdsale(address _ethFundDeposit,
address _rcnFundDeposit,
uint256 _fundingStartBlock,
uint256 _fundingEndBlock) {
uint256 _fundingStartTimestamp,
uint256 _fundingEndTimestamp) {
token = new RCNToken();
whiteList = new CapWhitelist();

// sanity checks
assert(_ethFundDeposit != 0x0);
assert(_rcnFundDeposit != 0x0);
assert(_fundingStartBlock < _fundingEndBlock);
assert(_fundingStartTimestamp < _fundingEndTimestamp);
assert(uint256(token.decimals()) == decimals);

isFinalized = false; //controls pre through crowdsale state
ethFundDeposit = _ethFundDeposit;
rcnFundDeposit = _rcnFundDeposit;
fundingStartBlock = _fundingStartBlock;
fundingEndBlock = _fundingEndBlock;
fundingStartTimestamp = _fundingStartTimestamp;
fundingEndTimestamp = _fundingEndTimestamp;
token.mint(rcnFundDeposit, rcnFund);
raised = rcnFund;
CreateRCN(rcnFundDeposit, rcnFund); // logs Ripio Intl fund
Expand All @@ -68,8 +68,8 @@ contract RCNCrowdsale is Crowdsale {
// low level token purchase function
function buyTokens(address beneficiary) payable {
if (isFinalized) throw;
if (block.number < fundingStartBlock) throw;
if (block.number > fundingEndBlock) throw;
if (block.timestamp < fundingStartTimestamp) throw;
if (block.timestamp > fundingEndTimestamp) throw;
if (msg.value == 0) throw;
if (beneficiary == 0x0) throw;

Expand Down Expand Up @@ -97,7 +97,7 @@ contract RCNCrowdsale is Crowdsale {

function finalize() {
if (isFinalized) throw;
if (block.number <= fundingEndBlock && raised != tokenCreationCap) throw;
if (block.timestamp <= fundingEndTimestamp && raised != tokenCreationCap) throw;
if (msg.sender != ethFundDeposit) throw;
isFinalized = true;
token.finishMinting();
Expand Down
9 changes: 6 additions & 3 deletions test/TestToken.js
Expand Up @@ -7,7 +7,8 @@ function rcnToWei(value){

contract('RCNCrowdsale', function(accounts) {
it("Create and send tokens", function(){
return RCNCrowdsale.new(accounts[0], accounts[0], 0, 1170000).then(function(instance){
currentTime = Math.floor(Date.now() / 1000);
return RCNCrowdsale.new(accounts[0], accounts[0], currentTime - 1, currentTime + 10).then(function(instance){
this.instanceRcn = instance;
this.initialBalanceFunding = web3.eth.getBalance(accounts[0]).toNumber();
return this.instanceRcn.setWhitelist(accounts[1], rcnToWei(1 * 4000), { from: accounts[0] })
Expand Down Expand Up @@ -35,7 +36,8 @@ contract('RCNCrowdsale', function(accounts) {
});
});
it("Should not buy tokens, min amount limit", function(){
return RCNCrowdsale.new(accounts[0], accounts[0], 0, 1170000).then(function(instance){
currentTime = Math.floor(Date.now() / 1000);
return RCNCrowdsale.new(accounts[0], accounts[0], currentTime - 1, currentTime + 10).then(function(instance){
this.instanceRcn = instance;
return this.instanceRcn.setWhitelist(accounts[1], rcnToWei(20 * 4000), { from: accounts[0] })
}).then(function(){
Expand All @@ -56,7 +58,8 @@ contract('RCNCrowdsale', function(accounts) {
});
});
it("Should not buy tokens, whitelist", function(){
return RCNCrowdsale.new(accounts[0], accounts[0], 0, 1170000).then(function(instance){
currentTime = Math.floor(Date.now() / 1000);
return RCNCrowdsale.new(accounts[0], accounts[0], currentTime - 1, currentTime + 10).then(function(instance){
this.instanceRcn = instance;
return instanceRcn.token();
}).then(function(token){
Expand Down

0 comments on commit 50a51b7

Please sign in to comment.