Skip to content

Commit 715be38

Browse files
author
Stavros
committed
more tests
1 parent f849270 commit 715be38

14 files changed

+417
-146
lines changed

.node-xmlhttprequest-sync-13778

Whitespace-only changes.

constants.js

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,30 @@
1+
const Web3 = require('web3')
2+
const web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:9545")) // Hardcoded testrpc port
3+
4+
15
module.exports = {
26
crowdsale: {
37
START: Math.round(new Date().getTime()/1000),
48
END: Math.round(new Date().getTime()/1000) + 60*60,
59
MINIMUM_WEI_FUNDING_GOAL: 3 * 10**18,
6-
MAXIMUM_SELLABLE_TOKENS: 1800 * 10 ** 18,
10+
MAXIMUM_SELLABLE_TOKENS: 2200 * 10 ** 18,
711
LOCKTIME: 60 * 60 //1hour
812
},
913

1014
precrowdsale: {
1115
START: Math.round(new Date().getTime()/1000),
1216
END: Math.round(new Date().getTime()/1000) + 60*60*2,
13-
PRESALE_TOKEN_CAP: 3000000 * 10 ** 18
17+
PRESALE_TOKEN_CAP: 1000 * 10 ** 18
1418
},
1519

1620
finalizeagent: {
1721
},
1822

1923
multisig: {
20-
MAINADDRESS: '0x00c9b8f5c03de53059b6f21238b070f50e986c25',
21-
USERGROWTHADDRESS: '0x00c9b8f5c03de53059b6f21238b070f50e986c25',
22-
STABILITYADDRESS: '0x00c9b8f5c03de53059b6f21238b070f50e986c25',
23-
BOUNTYADDRESS: '0x00c9b8f5c03de53059b6f21238b070f50e986c25'
24+
MAINADDRESS: web3.eth.accounts[16],
25+
USERGROWTHADDRESS: web3.eth.accounts[17],
26+
STABILITYADDRESS: web3.eth.accounts[18],
27+
BOUNTYADDRESS: web3.eth.accounts[19]
2428
},
2529

2630
pricingStrategy: {
@@ -30,20 +34,16 @@ module.exports = {
3034
1 * 10 ** 18, //1st cap
3135
0.002 * 10 ** 18, // 2nd price
3236
2 * 10 ** 18, // 2nd cap
33-
0.003 * 10 ** 18, // 3nd price
37+
0.0025 * 10 ** 18, // 3nd price
3438
3* 10 ** 18, // 3nd cap
3539
0.004 * 10 ** 18, // 4nd price
36-
4* 10 ** 18, // 4nd cap
40+
8* 10 ** 18, // 4nd cap (should be higher by far from the token cap of crowdsale)
3741
0 // end price has to be 0
3842
],
39-
PRESALE_PRICE_WEI: 500000000000000
43+
PRESALE_PRICE_WEI: 0.0005 * 10**18
4044
},
4145

4246
whitelist: {
43-
WHITELISTERS: [
44-
'0x00c9b8f5c03de53059b6f21238b070f50e986c25',
45-
'0x002941C2DfAE6a6058915B58D6B28c4dcd8f1542'
46-
],
4747
presaleCap: 1 * 10 ** 18,
4848
tier1Cap: 1 * 10 ** 18,
4949
tier2Cap: 1 * 10 ** 18,

contracts/GetCrowdsale.sol

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,27 @@ import './GetWhitelist.sol';
77
contract GetCrowdsale is MintedTokenCappedCrowdsale {
88

99
uint public lockTime;
10-
address presale;
10+
FinalizeAgent presaleFinalizeAgent;
1111

1212
event PresaleUpdated(uint weiAmount, uint tokenAmount);
1313

1414
function GetCrowdsale(
15-
uint _lockTime, address _presale,
15+
uint _lockTime, FinalizeAgent _presaleFinalizeAgent,
1616
address _token, PricingStrategy _pricingStrategy, address _multisigWallet,
1717
uint _start, uint _end, uint _minimumFundingGoal, uint _maximumSellableTokens)
1818

1919
MintedTokenCappedCrowdsale(_token, _pricingStrategy, _multisigWallet,
2020
_start, _end, _minimumFundingGoal, _maximumSellableTokens)
2121
{
22-
require(_presale != 0x0);
22+
require(_presaleFinalizeAgent.isSane());
2323
require(_lockTime > 0);
2424
lockTime = _lockTime;
25-
presale = _presale;
25+
presaleFinalizeAgent = _presaleFinalizeAgent;
2626
}
2727

2828
function logPresaleResults(uint tokenAmount, uint weiAmount) returns (bool) {
2929

30-
require(msg.sender == presale);
30+
require(msg.sender == address(presaleFinalizeAgent));
3131
weiRaised = weiRaised.plus(weiAmount);
3232
tokensSold = tokensSold.plus(tokenAmount);
3333
presaleWeiRaised = presaleWeiRaised.plus(weiAmount);

contracts/GetFinalizeAgent.sol

+2-1
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,12 @@ contract GetFinalizeAgent is FinalizeAgent {
5252
revert();
5353
}
5454

55-
// How many % of tokens the founders and others get
5655
uint tokensSold = crowdsale.tokensSold();
5756
uint decimals = token.decimals();
5857

58+
// maximum digits here (10 + 18 + 12)
5959
token.mint(userGrowthMultisig, tokensSold.times(73170731707) / 100000000000);
60+
6061
token.mint(stabilityMultisig, 12600000 * (10**decimals));
6162
token.mint(bountyMultisig, 1800000 * (10**decimals));
6263

contracts/GetPreFinalizeAgent.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ contract GetPreFinalizeAgent is FinalizeAgent, Ownable {
2929
}
3030

3131
function finalizeCrowdsale() {
32-
if(msg.sender != address(crowdsale)) {
32+
if(msg.sender != address(preCrowdsale)) {
3333
revert();
3434
}
3535

contracts/GetPricingStrategy.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ contract GetPricingStrategy is EthTranchePricing {
2727
}
2828

2929
// needed to update the correct tier in whitelist
30-
function getCurrentTrancheIndex(uint weiRaised) private constant returns (uint) {
30+
function getCurrentTrancheIndex(uint weiRaised) public constant returns (uint) {
3131
uint i;
3232

3333
for(i=0; i < tranches.length; i++) {

migrations/4_deploy_precrowdsale.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ module.exports = function(deployer) {
3232
return GetPreCrowdsale.deployed();
3333
}).then((precrowdsale) => {
3434
return precrowdsale.setFinalizeAgent(
35-
GetPreFinalizeAgent.address, {from: web3.eth.accounts[0]});
35+
GetPreFinalizeAgent.address);
3636
}).then(() => {
3737
return GetToken.deployed();
3838
}).then((token) => {
39-
return token.setMintAgent(GetPreCrowdsale.address, true, {from: web3.eth.accounts[0]});
39+
return token.setMintAgent(GetPreCrowdsale.address, true);
4040
}).then(() => {
4141
return GetWhitelist.deployed();
4242
}).then((whitelist) => {

migrations/5_deploy_crowdsale.js

+11-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const GetPricingStrategy = artifacts.require("./GetPricingStrategy.sol");
22
const GetToken = artifacts.require("./GetToken.sol");
33
const GetCrowdsale = artifacts.require("./GetCrowdsale.sol");
4-
const GetPreCrowdsale = artifacts.require("./GetPreCrowdsale.sol");
4+
const GetPreFinalizeAgent = artifacts.require("./GetPreFinalizeAgent.sol");
55
const GetWhitelist = artifacts.require('./GetWhitelist.sol');
66
const GetFinalizeAgent = artifacts.require('./GetFinalizeAgent.sol');
77
const constants = require('../constants.js');
@@ -16,7 +16,7 @@ module.exports = function(deployer) {
1616
return deployer.deploy(
1717
GetCrowdsale,
1818
constants.crowdsale.LOCKTIME,
19-
GetPreCrowdsale.address,
19+
GetPreFinalizeAgent.address,
2020

2121
GetToken.address,
2222
GetPricingStrategy.address,
@@ -40,18 +40,22 @@ module.exports = function(deployer) {
4040
return GetCrowdsale.deployed();
4141
}).then((crowdsale) => {
4242
return crowdsale.setFinalizeAgent(
43-
GetFinalizeAgent.address, {from: web3.eth.accounts[0]});
43+
GetFinalizeAgent.address);
4444
}).then(() => {
4545
return GetToken.deployed();
4646
}).then((token) => {
4747
return Promise.all([
48-
token.setMintAgent(GetCrowdsale.address, true, {from: web3.eth.accounts[0]}),
49-
token.setMintAgent(GetFinalizeAgent.address, true, {from: web3.eth.accounts[0]}),
50-
token.setReleaseAgent(GetFinalizeAgent.address, {from: web3.eth.accounts[0]})
48+
token.setMintAgent(GetCrowdsale.address, true),
49+
token.setMintAgent(GetFinalizeAgent.address, true),
50+
token.setReleaseAgent(GetFinalizeAgent.address)
5151
])
5252
}).then(() => {
5353
return GetWhitelist.deployed();
5454
}).then((whitelist) => {
5555
return whitelist.setWhitelister(GetPricingStrategy.address, true);
56-
});;
56+
}).then(() => {
57+
return GetPreFinalizeAgent.deployed();
58+
}).then((prefinalizeagent) => {
59+
return prefinalizeagent.setCrowdsale(GetCrowdsale.address);
60+
});
5761
};

start_testrpc

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
testrpc --account="$1,1000000000000000000000000"\
2-
--account="$2,1000000000000000000000000"\
3-
--account="$3,1000000000000000000000000"\
1+
testrpc --accounts 20\
42
--port 9545\
53
--network-id 2
File renamed without changes.

test/1_precrowdsale.js

+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
var GetWhitelist = artifacts.require("./GetWhitelist.sol");
2+
var GetPreCrowdsale = artifacts.require("./GetPreCrowdsale.sol");
3+
var GetCrowdsale = artifacts.require("./GetCrowdsale.sol");
4+
var GetToken = artifacts.require("./GetToken.sol");
5+
var constants = require('../constants.js');
6+
const fullAmount = constants.precrowdsale.PRESALE_TOKEN_CAP / 10**18 * constants.pricingStrategy.PRESALE_PRICE_WEI;
7+
8+
9+
contract('GetPreCrowdsale', function(accounts) {
10+
it("whitelisted presale should be able to buy", async function() {
11+
const whitelist = await GetWhitelist.deployed();
12+
const precrowdsale = await GetPreCrowdsale.deployed();
13+
await whitelist.setWhitelister(accounts[0], true);
14+
15+
await whitelist.accept(accounts[0], true);
16+
17+
await precrowdsale.buy({value: fullAmount, from: accounts[0]});
18+
});
19+
20+
it("whitelisted sale should not be able to buy", async function() {
21+
const whitelist = await GetWhitelist.deployed();
22+
const precrowdsale = await GetPreCrowdsale.deployed();
23+
24+
await whitelist.accept(accounts[1], false);
25+
try{
26+
await precrowdsale.buy({value: 100, from: accounts[1]});
27+
}catch (error){
28+
assert(error.message.indexOf("invalid opcode") != -1, "Incorrect throw");
29+
return;
30+
}
31+
throw new Error("whitelisted in sale bought coins");
32+
});
33+
34+
it("correct token amount", async function(){
35+
const token = await GetToken.deployed();
36+
const balance = await token.balanceOf.call(accounts[0]);
37+
assert.equal(balance.valueOf(), constants.precrowdsale.PRESALE_TOKEN_CAP);
38+
})
39+
40+
it("Correct data in precrowdsale", async function() {
41+
const precrowdsale = await GetPreCrowdsale.deployed();
42+
const investorCount = await precrowdsale.investorCount.call();
43+
assert.equal(investorCount.valueOf(), 1, "1 wasn't the investor count");
44+
const tokensSold = await precrowdsale.tokensSold.call();
45+
const tokenAmount = await precrowdsale.tokenAmountOf(accounts[0]);
46+
const tokenCount = constants.precrowdsale.PRESALE_TOKEN_CAP;
47+
assert.equal(tokenAmount.valueOf(), tokenCount, "Incorrect token count");
48+
assert.equal(tokensSold.valueOf(), tokenCount, "Incorrect total token count");
49+
});
50+
51+
it("precrowdsale is full", async function() {
52+
const precrowdsale = await GetPreCrowdsale.deployed();
53+
const full = await precrowdsale.isCrowdsaleFull();
54+
const state = await precrowdsale.getState();
55+
assert.equal(state.valueOf(), 4, "Not in success state");
56+
assert.equal(full, true, "Not full");
57+
});
58+
59+
it("cannot buy in full precrowdsale", async function() {
60+
const precrowdsale = await GetPreCrowdsale.deployed();
61+
try{
62+
await precrowdsale.buy({value: 100, from: accounts[0]});
63+
}catch (error){
64+
assert(error.message.indexOf("invalid opcode") != -1, "Incorrect throw");
65+
return;
66+
}
67+
throw new Error("Bought in full");
68+
});
69+
70+
it("cannot finalize from a non owner", async function() {
71+
const precrowdsale = await GetPreCrowdsale.deployed();
72+
try{
73+
await precrowdsale.finalize({from: accounts[1]});
74+
}catch (error){
75+
assert(error.message.indexOf("invalid opcode") != -1, "Incorrect throw");
76+
return;
77+
}
78+
throw new Error("non owner finalized");
79+
});
80+
81+
82+
it("owner can finalize", async function() {
83+
const precrowdsale = await GetPreCrowdsale.deployed();
84+
const state = await precrowdsale.getState();
85+
await precrowdsale.finalize({from: accounts[0]});
86+
});
87+
88+
it("crowdsale is updated", async function() {
89+
const precrowdsale = await GetPreCrowdsale.deployed();
90+
const crowdsale = await GetCrowdsale.deployed();
91+
const crowdsaleTokens = await crowdsale.tokensSold();
92+
const precrowdsaleTokens = await precrowdsale.tokensSold();
93+
assert.equal(crowdsaleTokens.valueOf(), precrowdsaleTokens.valueOf(), "Incorrect tokensSold");
94+
assert.equal(crowdsaleTokens.valueOf(), constants.precrowdsale.PRESALE_TOKEN_CAP, "Incorrect tokensSold")
95+
96+
const crowdsaleWeiRaised = await crowdsale.weiRaised();
97+
const precrowdsaleWeiRaised = await precrowdsale.weiRaised();
98+
assert.equal(crowdsaleWeiRaised.valueOf(), precrowdsaleWeiRaised.valueOf(), "Incorrect weiRaised");
99+
assert.equal(precrowdsaleWeiRaised.valueOf(), fullAmount, "Incorrect weiRaised")
100+
101+
102+
const crowdsalePresaleWeiRaised = await crowdsale.presaleWeiRaised();
103+
assert.equal(crowdsalePresaleWeiRaised.valueOf(), precrowdsaleWeiRaised.valueOf(), "Incorrect presaleweiRaised");
104+
105+
});
106+
107+
});

0 commit comments

Comments
 (0)