Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 3 additions & 2 deletions contracts/crowdsale/RefundableCrowdsale.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ contract RefundableCrowdsale is FinalizableCrowdsale {
// refund vault used to hold funds while crowdsale is running
RefundVault public vault;

function RefundableCrowdsale(uint256 _goal) public {
function RefundableCrowdsale(uint256 _goal, RefundVault _vault) public {
require(_goal > 0);
vault = new RefundVault(wallet);
require(_vault != address(0));
vault = _vault;
goal = _goal;
}

Expand Down
5 changes: 3 additions & 2 deletions contracts/examples/SampleCrowdsale.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ pragma solidity ^0.4.18;

import "../crowdsale/CappedCrowdsale.sol";
import "../crowdsale/RefundableCrowdsale.sol";
import "../crowdsale/RefundVault.sol";
import "../token/ERC20/MintableToken.sol";


Expand Down Expand Up @@ -32,10 +33,10 @@ 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, RefundVault _vault) public
CappedCrowdsale(_cap)
FinalizableCrowdsale()
RefundableCrowdsale(_goal)
RefundableCrowdsale(_goal, _vault)
Crowdsale(_startTime, _endTime, _rate, _wallet, _token)
{
//As goal needs to be met for a successful crowdsale
Expand Down
5 changes: 3 additions & 2 deletions contracts/mocks/RefundableCrowdsaleImpl.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ contract RefundableCrowdsaleImpl is RefundableCrowdsale {
uint256 _rate,
address _wallet,
uint256 _goal,
MintableToken _token
MintableToken _token,
RefundVault _vault
) public
Crowdsale(_startTime, _endTime, _rate, _wallet, _token)
RefundableCrowdsale(_goal)
RefundableCrowdsale(_goal, _vault)
{
}

Expand Down
8 changes: 7 additions & 1 deletion test/crowdsale/CappedCrowdsale.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ contract('CappedCrowdsale', function ([_, wallet]) {

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(
this.startTime,
this.endTime,
rate, wallet,
0,
this.token.address
).should.be.rejectedWith(EVMRevert);
});
});

Expand Down
25 changes: 23 additions & 2 deletions test/crowdsale/RefundableCrowdsale.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require('chai')

const RefundableCrowdsale = artifacts.require('RefundableCrowdsaleImpl');
const MintableToken = artifacts.require('MintableToken');
const RefundVault = artifacts.require('RefundVault');

contract('RefundableCrowdsale', function ([_, owner, wallet, investor]) {
const rate = new BigNumber(1000);
Expand All @@ -30,15 +31,35 @@ contract('RefundableCrowdsale', function ([_, owner, wallet, investor]) {
this.afterEndTime = this.endTime + duration.seconds(1);

this.token = await MintableToken.new();
this.vault = await RefundVault.new(wallet);

this.crowdsale = await RefundableCrowdsale.new(
this.startTime, this.endTime, rate, wallet, goal, this.token.address, { from: owner }
this.startTime,
this.endTime,
rate,
wallet,
goal,
this.token.address,
this.vault.address,
{ from: owner }
);

await this.token.transferOwnership(this.crowdsale.address);
await this.vault.transferOwnership(this.crowdsale.address);
});

describe('creating a valid crowdsale', function () {
it('should fail with zero goal', async function () {
await RefundableCrowdsale.new(this.startTime, this.endTime, rate, wallet, 0, { from: owner })
await RefundableCrowdsale.new(
this.startTime,
this.endTime,
rate,
wallet,
0,
this.token.address,
this.vault.address,
{ from: owner }
)
.should.be.rejectedWith(EVMRevert);
});
});
Expand Down
8 changes: 7 additions & 1 deletion test/examples/SampleCrowdsale.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require('chai')

const SampleCrowdsale = artifacts.require('SampleCrowdsale');
const SampleCrowdsaleToken = artifacts.require('SampleCrowdsaleToken');
const RefundVault = artifacts.require('RefundVault');

contract('SampleCrowdsale', function ([owner, wallet, investor]) {
const RATE = new BigNumber(10);
Expand All @@ -30,15 +31,20 @@ contract('SampleCrowdsale', function ([owner, wallet, investor]) {
this.afterEndTime = this.endTime + duration.seconds(1);

this.token = await SampleCrowdsaleToken.new();
this.vault = await RefundVault.new(wallet, { from: owner });

this.crowdsale = await SampleCrowdsale.new(
this.startTime, this.endTime, RATE, GOAL, CAP, wallet, this.token.address
this.startTime, this.endTime, RATE, GOAL, CAP, wallet, this.token.address, this.vault.address
);

await this.vault.transferOwnership(this.crowdsale.address);
await this.token.transferOwnership(this.crowdsale.address);
});

it('should create crowdsale with correct parameters', async function () {
this.crowdsale.should.exist;
this.token.should.exist;
this.vault.should.exist;

const startTime = await this.crowdsale.startTime();
const endTime = await this.crowdsale.endTime();
Expand Down