Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
49b16cf
Basic idea
eternauta1337 Feb 4, 2018
fc7af3c
Fine tuning idea
eternauta1337 Feb 5, 2018
d54f799
Add comments / tidy up Crowdsale base class
eternauta1337 Feb 5, 2018
f48c150
fixed TimedCrowdsale constructor
fiiiu Feb 7, 2018
3f5680b
added simple crowdsale test
fiiiu Feb 7, 2018
a8a14df
added HODL directory under home to store unused contracts. ugly hack …
fiiiu Feb 7, 2018
469a999
Capped no longer inherits from Timed, added capReached() method (repl…
fiiiu Feb 8, 2018
90f0973
added SafeMath in TimedCrowdsale for safety, CHECK whether it is inhe…
fiiiu Feb 8, 2018
3ffe518
several fixes related to separating Capped from Timed. functions rena…
fiiiu Feb 8, 2018
a5aaf94
added TimedCrowdsaleImpl.sol, TimedCrowdsale tests, passed
fiiiu Feb 8, 2018
8a3cfb9
added Whitelisted implementation and test, passed.
fiiiu Feb 8, 2018
6343246
removed unnecessary super constructor call in WhitelistedCrowdsale, r…
fiiiu Feb 8, 2018
2c22337
renamed UserCappedCrowdsale to IndividuallyCappedCrowdsale, implement…
fiiiu Feb 8, 2018
8c8fed1
homogeneized use of using SafeMath for uint256 across validation crow…
fiiiu Feb 8, 2018
962b5bc
adding questions.md where I track questions, bugs and progress
fiiiu Feb 8, 2018
bbb2dfa
modified VariablePriceCrowdsale, added Impl.
fiiiu Feb 9, 2018
3fdb6da
finished VariablePrice, fixed sign, added test, passing.
fiiiu Feb 9, 2018
53ec3cc
changed VariablePrice to IncreasingPrice, added corresponding require()
fiiiu Feb 14, 2018
2be5806
MintedCrowdsale done, mock implemented, test passing
fiiiu Feb 14, 2018
b814a05
PremintedCrowdsale done, mocks, tests passing
fiiiu Feb 14, 2018
dd05925
checked FinalizableCrowdsale
fiiiu Feb 14, 2018
120d277
PostDeliveryCrowdsale done, mock, tests passing.
fiiiu Feb 14, 2018
e677e33
RefundableCrowdsale done. Detached Vault. modified mock and test, pas…
fiiiu Feb 14, 2018
5873f8e
renamed crowdsale-refactor to crowdsale in contracts and test
fiiiu Feb 14, 2018
2fe239c
deleted HODL old contracts
fiiiu Feb 15, 2018
bf5e9dd
polished variable names in tests
fiiiu Feb 15, 2018
cd0ba80
fixed typos and removed comments in tests
fiiiu Feb 15, 2018
0487d25
Renamed 'crowdsale-refactor' to 'crowdsale' in all imports
eternauta1337 Feb 15, 2018
c4a2f9c
Fix minor param naming issues in Crowdsale functions and added docume…
eternauta1337 Feb 15, 2018
3ef55bc
Added documentation to Crowdsale extensions
eternauta1337 Feb 15, 2018
c1a41ae
removed residual comments and progress tracking files
fiiiu Feb 15, 2018
b455000
added docs for validation crowdsales
fiiiu Feb 15, 2018
a841691
Made user promises in PostDeliveryCrowdsale public so that users can …
eternauta1337 Feb 15, 2018
3d4d41a
added docs for distribution crowdsales
fiiiu Feb 15, 2018
8b6b342
renamed PremintedCrowdsale to AllowanceCrowdsale
fiiiu Feb 16, 2018
1a2a5ec
added allowance check function and corresponding test. fixed filename…
fiiiu Feb 16, 2018
1680a18
spilt Crowdsale _postValidatePurchase in _postValidatePurchase and _u…
fiiiu Feb 16, 2018
344bec6
polished tests for linter, salve Travis
fiiiu Feb 16, 2018
7d4035a
polished IncreasingPriceCrowdsale.sol for linter.
fiiiu Feb 16, 2018
bcd0464
renamed and polished for linter WhitelistedCrowdsale test.
fiiiu Feb 16, 2018
51c0954
fixed indentation in IncreasingPriceCrowdsaleImpl.sol for linter
fiiiu Feb 16, 2018
cd15b41
fixed ignoring token.mint return value in MintedCrowdsale.sol
fiiiu Feb 17, 2018
e716a22
expanded docs throughout, fixed minor issues
fiiiu Feb 19, 2018
7134f0d
extended test coverage for IndividuallyCappedCrowdsale
fiiiu Feb 19, 2018
f56116e
Extended WhitelistedCrwodsale test coverage
fiiiu Feb 19, 2018
2a6dd9f
roll back decoupling of RefundVault in RefundableCrowdsale
fiiiu Feb 19, 2018
8e8e8cc
moved cap exceedance checks in Capped and IndividuallyCapped crowdsal…
fiiiu Feb 19, 2018
fa055a6
revert name change, IndividuallyCapped to UserCapped
fiiiu Feb 19, 2018
56e83b9
extended docs.
fiiiu Feb 19, 2018
1bf30f9
added crowd whitelisting with tests
fiiiu Feb 19, 2018
a70e3ed
added group capping, plus tests
fiiiu Feb 19, 2018
5f4fc83
added modifiers in TimedCrowdsale and WhitelistedCrowdsale
fiiiu Feb 19, 2018
47ce79f
polished tests for linter
fiiiu Feb 19, 2018
5dab495
moved check of whitelisted to modifier, mainly for testing coverage
fiiiu Feb 19, 2018
dd338f1
fixed minor ordering/polishingafter review
fiiiu Feb 19, 2018
8376baa
modified TimedCrowdsale modifier/constructor ordering
fiiiu Feb 19, 2018
8ad6a10
unchanged truffle-config.js
fiiiu Feb 20, 2018
107fdc4
changed indentation of visibility modifier in mocks
fiiiu Feb 20, 2018
530d85d
changed naming of modifier and function to use Open/Closed for TimedC…
fiiiu Feb 20, 2018
9fe61b8
changed ordering of constructor calls in SampleCrowdsale
fiiiu Feb 20, 2018
de8e88f
changed startTime and endTime to openingTime and closingTime throughout
fiiiu Feb 20, 2018
6c38f46
fixed exceeding line lenght for linter
fiiiu Feb 20, 2018
33839c1
Merge branch 'master' into feature/crowdsale-refactor
fiiiu Feb 20, 2018
df03099
renamed _emitTokens to _deliverTokens
fiiiu Feb 20, 2018
c6def0e
renamed addCrowdToWhitelist to addManyToWhitelist
fiiiu Feb 20, 2018
c177f01
renamed UserCappedCrowdsale to IndividuallyCappedCrowdsale
fiiiu Feb 20, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
several fixes related to separating Capped from Timed. functions rena…
…med, mocks changed. Capped tests passing
  • Loading branch information
fiiiu authored and eternauta1337 committed Feb 15, 2018
commit 3ffe518650d02cbc47d6be24e9fdcee7dab09834
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ contract FinalizableCrowdsale is TimedCrowdsale, Ownable {
*/
function finalize() onlyOwner public {
require(!isFinalized);
require(hasEnded());
require(hasExpired());

finalization();
Finalized();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import "../validation/TimedCrowdsale.sol";
import "../../token/ERC20/ERC20.sol";

contract PostDeliveryCrowdsale is TimedCrowdsale {

mapping(address => uint256) promises;

function processPurchase(address _beneficiary, uint256 _tokenAmount) internal {
promises[_beneficiary] = promises[_beneficiary].add(_tokenAmount);
}

function withdrawTokens() public {
require(hasEnded());
require(hasExpired());
uint256 amount = promises[msg.sender];
require(amount > 0);
promises[msg.sender] = 0;
Expand Down
5 changes: 3 additions & 2 deletions contracts/crowdsale-refactor/validation/TimedCrowdsale.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pragma solidity ^0.4.18;

import "../../math/SafeMath.sol";
import "../Crowdsale.sol";

contract TimedCrowdsale is Crowdsale {
Expand All @@ -9,8 +10,8 @@ contract TimedCrowdsale is Crowdsale {
uint256 public endTime;

function TimedCrowdsale(uint256 _startTime, uint256 _endTime) public {
require(_startTime >= now);
require(_endTime >= _startTime);
//require(_startTime >= now);
//require(_endTime >= _startTime);

startTime = _startTime;
endTime = _endTime;
Expand Down
10 changes: 6 additions & 4 deletions contracts/examples/SampleCrowdsale.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pragma solidity ^0.4.18;

import "../crowdsale/CappedCrowdsale.sol";
import "../crowdsale/RefundableCrowdsale.sol";
import "../crowdsale-refactor/validation/CappedCrowdsale.sol";
import "../crowdsale-refactor/distribution/RefundableCrowdsale.sol";
import "../token/ERC20/MintableToken.sol";


Expand Down Expand Up @@ -32,11 +32,13 @@ contract SampleCrowdsaleToken is MintableToken {
*/
contract SampleCrowdsale is CappedCrowdsale, RefundableCrowdsale {

function SampleCrowdsale(uint256 _startTime, uint256 _endTime, uint256 _rate, uint256 _goal, uint256 _cap, address _wallet, MintableToken _token) public
//function SampleCrowdsale(uint256 _startTime, uint256 _endTime, uint256 _rate, uint256 _goal, uint256 _cap, address _wallet, MintableToken _token) public
function SampleCrowdsale(uint256 _rate, uint256 _goal, uint256 _cap, address _wallet, MintableToken _token) public
CappedCrowdsale(_cap)
FinalizableCrowdsale()
RefundableCrowdsale(_goal)
Crowdsale(_startTime, _endTime, _rate, _wallet, _token)
//Crowdsale(_startTime, _endTime, _rate, _wallet, _token)
Crowdsale(_rate, _wallet, _token)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I notice that we should probably be following the "most basic class first" rules here, like we do in the other *Impl.sol files. Is there a reason Crowdsale() is last? or should it be the first, since it's the most basic class?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, it's perhaps that this might not actually work, since the Crowdsale is inherited from last and doesn't call super.*

{
//As goal needs to be met for a successful crowdsale
//the value needs to less or equal than a cap which is limit for accepted funds
Expand Down
11 changes: 5 additions & 6 deletions contracts/mocks/CappedCrowdsaleImpl.sol
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
pragma solidity ^0.4.18;


import "../crowdsale/CappedCrowdsale.sol";
//import "../examples/SimpleToken.sol";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we remove this line?

import "../token/ERC20/ERC20.sol";
import "../crowdsale-refactor/validation/CappedCrowdsale.sol";


contract CappedCrowdsaleImpl is CappedCrowdsale {

function CappedCrowdsaleImpl (
uint256 _startTime,
uint256 _endTime,
uint256 _rate,
address _wallet,
uint256 _cap,
MintableToken _token
ERC20 _token
) public
Crowdsale(_startTime, _endTime, _rate, _wallet, _token)
Crowdsale(_rate, _wallet, _token)
CappedCrowdsale(_cap)
{
}
Expand Down
11 changes: 6 additions & 5 deletions contracts/mocks/FinalizableCrowdsaleImpl.sol
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
pragma solidity ^0.4.18;


import "../crowdsale/FinalizableCrowdsale.sol";
import "../token/ERC20/MintableToken.sol";
import "../crowdsale-refactor/distribution/FinalizableCrowdsale.sol";


contract FinalizableCrowdsaleImpl is FinalizableCrowdsale {

function FinalizableCrowdsaleImpl (
uint256 _startTime,
uint256 _endTime,
//uint256 _startTime,
//uint256 _endTime,
uint256 _rate,
address _wallet,
MintableToken _token
) public
Crowdsale(_startTime, _endTime, _rate, _wallet, _token)
//Crowdsale(_startTime, _endTime, _rate, _wallet, _token)
Crowdsale(_rate, _wallet, _token)
{
}

Expand Down
11 changes: 6 additions & 5 deletions contracts/mocks/RefundableCrowdsaleImpl.sol
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
pragma solidity ^0.4.18;


import "../crowdsale/RefundableCrowdsale.sol";
import "../token/ERC20/MintableToken.sol";
import "../crowdsale-refactor/distribution/RefundableCrowdsale.sol";


contract RefundableCrowdsaleImpl is RefundableCrowdsale {

function RefundableCrowdsaleImpl (
uint256 _startTime,
uint256 _endTime,
//uint256 _startTime,
//uint256 _endTime,
uint256 _rate,
address _wallet,
uint256 _goal,
MintableToken _token
) public
Crowdsale(_startTime, _endTime, _rate, _wallet, _token)
//Crowdsale(_startTime, _endTime,
Crowdsale(_rate, _wallet, _token)
RefundableCrowdsale(_goal)
{
}
Expand Down
51 changes: 19 additions & 32 deletions test/crowdsale-refactor/CappedCrowdsale.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,28 @@ require('chai')
.should();

const CappedCrowdsale = artifacts.require('CappedCrowdsaleImpl');
const MintableToken = artifacts.require('MintableToken');
const SimpleToken = artifacts.require('SimpleToken');

contract('CappedCrowdsale', function ([_, wallet]) {
const rate = new BigNumber(1000);
const rate = new BigNumber(1);// Not that many SimpleTokens!! 1000);

const cap = ether(300);
const cap = ether(100);
const lessThanCap = ether(60);

before(async function () {
// Advance to the next block to correctly read time in the solidity "now" function interpreted by testrpc
await advanceBlock();
});
const capital = ether(1000);

beforeEach(async function () {
this.startTime = latestTime() + duration.weeks(1);
this.endTime = this.startTime + duration.weeks(1);

this.token = await MintableToken.new();
this.crowdsale = await CappedCrowdsale.new(this.startTime, this.endTime, rate, wallet, cap, this.token.address);
await this.token.transferOwnership(this.crowdsale.address);
this.token = await SimpleToken.new();
this.crowdsale = await CappedCrowdsale.new(rate, wallet, cap, this.token.address);
this.token.transfer(this.crowdsale.address, capital);
});

describe('creating a valid crowdsale', function () {
it('should fail with zero cap', async function () {
await CappedCrowdsale.new(this.startTime, this.endTime, rate, wallet, 0).should.be.rejectedWith(EVMRevert);
await CappedCrowdsale.new(rate, wallet, 0, this.token.address).should.be.rejectedWith(EVMRevert);
});
});

describe('accepting payments', function () {
beforeEach(async function () {
await increaseTimeTo(this.startTime);
});

it('should accept payments within cap', async function () {
await this.crowdsale.send(cap.minus(lessThanCap)).should.be.fulfilled;
Expand All @@ -61,28 +51,25 @@ contract('CappedCrowdsale', function ([_, wallet]) {
});

describe('ending', function () {
beforeEach(async function () {
await increaseTimeTo(this.startTime);
});

it('should not be ended if under cap', async function () {
let hasEnded = await this.crowdsale.hasEnded();
hasEnded.should.equal(false);
it('should not reach cap if sent under cap', async function () {
let capReached = await this.crowdsale.capReached();
capReached.should.equal(false);
await this.crowdsale.send(lessThanCap);
hasEnded = await this.crowdsale.hasEnded();
hasEnded.should.equal(false);
capReached = await this.crowdsale.capReached();
capReached.should.equal(false);
});

it('should not be ended if just under cap', async function () {
it('should not reach cap if sent just under cap', async function () {
await this.crowdsale.send(cap.minus(1));
let hasEnded = await this.crowdsale.hasEnded();
hasEnded.should.equal(false);
let capReached = await this.crowdsale.capReached();
capReached.should.equal(false);
});

it('should be ended if cap reached', async function () {
it('should reach cap if cap sent', async function () {
await this.crowdsale.send(cap);
let hasEnded = await this.crowdsale.hasEnded();
hasEnded.should.equal(true);
let capReached = await this.crowdsale.capReached();
capReached.should.equal(true);
});
});
});
23 changes: 4 additions & 19 deletions test/crowdsale-refactor/Crowdsale.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,17 @@ const Crowdsale = artifacts.require('Crowdsale');
const SimpleToken = artifacts.require('SimpleToken');

contract('Crowdsale', function ([god, investor, wallet, purchaser]) {
const rate = new BigNumber(1000);
const value = ether(4.2);
const holdings = ether(10000);
const rate = new BigNumber(1); // Not that many SimpleTokens!! 1000);
const value = ether(42);
const capital = ether(10000);

const expectedTokenAmount = rate.mul(value);

beforeEach(async function () {

this.token = await SimpleToken.new();
this.crowdsale = await Crowdsale.new(rate, wallet, this.token.address);
//fund crowdsale
this.token.transfer(this.crowdsale.address, holdings);
this.token.transfer(this.crowdsale.address, capital);
});


Expand Down Expand Up @@ -56,13 +55,6 @@ contract('Crowdsale', function ([god, investor, wallet, purchaser]) {
event.args.amount.should.be.bignumber.equal(expectedTokenAmount);
});

//OBSOLETE, not minting
// it('should increase totalSupply', async function () {
// await this.crowdsale.send(value);
// const totalSupply = await this.token.totalSupply();
// totalSupply.should.be.bignumber.equal(expectedTokenAmount);
// });

it('should assign tokens to sender', async function () {
await this.crowdsale.sendTransaction({ value: value, from: investor });
let balance = await this.token.balanceOf(investor);
Expand Down Expand Up @@ -92,13 +84,6 @@ contract('Crowdsale', function ([god, investor, wallet, purchaser]) {
event.args.amount.should.be.bignumber.equal(expectedTokenAmount);
});

// OBSOLETE
// it('should increase totalSupply', async function () {
// await this.crowdsale.buyTokens(investor, { value, from: purchaser });
// const totalSupply = await this.token.totalSupply();
// totalSupply.should.be.bignumber.equal(expectedTokenAmount);
// });

it('should assign tokens to beneficiary', async function () {
await this.crowdsale.buyTokens(investor, { value, from: purchaser });
const balance = await this.token.balanceOf(investor);
Expand Down