Skip to content

Commit 3585a4d

Browse files
authored
Merge pull request #289 from windingtree/increase-coverage-crowdsale-2
And more tests and increase coverage in LifCrowdsale
2 parents 5a2dff7 + 209c01c commit 3585a4d

File tree

3 files changed

+409
-29
lines changed

3 files changed

+409
-29
lines changed

contracts/LifMarketValidationMechanism.sol

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,17 +138,19 @@ contract LifMarketValidationMechanism is Ownable {
138138
// the 100% remaining can be claimed by the foundation. Values multipled by 10^5
139139

140140
uint256[24] memory accumDistribution24 = [
141-
uint256(0), 18, 117, 351, 767, 1407, 2309,3511, 5047, 6952, 9257
142-
,11995, 15196, 18889, 23104, 27870, 33215, 39166, 45749
143-
,52992, 60921, 69561, 78938, 89076
141+
uint256(0), 18, 117, 351, 767, 1407,
142+
2309, 3511, 5047, 6952, 9257, 11995,
143+
15196, 18889, 23104, 27870, 33215, 39166,
144+
45749, 52992, 60921, 69561, 78938, 89076
144145
];
145146

146147
uint256[48] memory accumDistribution48 = [
147-
uint256(0), 3, 18, 54, 117, 214, 351, 534, 767, 1056, 1406, 1822
148-
,2308, 2869, 3510, 4234, 5046, 5950, 6950, 8051, 9256, 10569
149-
,11994, 13535, 15195, 16978, 18888, 20929, 23104, 25416, 27870
150-
,30468, 33214, 36112, 39165, 42376, 45749, 49286, 52992, 56869
151-
,60921, 65150, 69560, 74155, 78937, 83909, 89075, 94438
148+
uint256(0), 3, 18, 54, 117, 214, 351, 534,
149+
767, 1056, 1406, 1822, 2308, 2869, 3510, 4234,
150+
5046, 5950, 6950, 8051, 9256, 10569, 11994, 13535,
151+
15195, 16978, 18888, 20929, 23104, 25416, 27870, 30468,
152+
33214, 36112, 39165, 42376, 45749, 49286, 52992, 56869,
153+
60921, 65150, 69560, 74155, 78937, 83909, 89075, 94438
152154
];
153155

154156
for (uint8 i = 0; i < totalPeriods; i++) {

test/Crowdsale.js

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ var LifCrowdsale = artifacts.require('./LifCrowdsale.sol'),
33

44
let help = require('./helpers');
55

6+
var BigNumber = web3.BigNumber;
7+
8+
require('chai')
9+
.use(require('chai-bignumber')(BigNumber))
10+
.should();
11+
612
var latestTime = require('./helpers/latestTime');
713
var {duration,increaseTimeTestRPCTo} = require('./helpers/increaseTime');
814

@@ -189,6 +195,17 @@ contract('LifToken Crowdsale', function(accounts) {
189195
}
190196
});
191197

198+
it('fails on buyTokens with rate==0 (before startTimestamp)', async function() {
199+
const crowdsale = await createCrowdsale({});
200+
await crowdsale.setWeiPerUSDinTGE(10000);
201+
try {
202+
await crowdsale.buyTokens(accounts[5], {value: 1000, from: accounts[5]});
203+
assert(false, 'should have thrown');
204+
} catch(e) {
205+
assert(help.isInvalidOpcodeEx(e));
206+
}
207+
});
208+
192209
/// addPrivatePresaleTokens
193210
it('handles an addPrivatePresaleTokens tx fine', async function() {
194211
const crowdsale = await createCrowdsale({}),
@@ -244,4 +261,143 @@ contract('LifToken Crowdsale', function(accounts) {
244261
assert(help.isInvalidOpcodeEx(e));
245262
}
246263
});
264+
265+
/// claimEth
266+
it('claimEth succeeds after an underfunded finalized crowdsale', async function() {
267+
const start = latestTime() + defaultTimeDelta,
268+
end1 = start + defaultTimeDelta,
269+
end2 = end1 + defaultTimeDelta,
270+
beneficiary = accounts[6],
271+
crowdsale = await createCrowdsale({
272+
start: start,
273+
end1: end1,
274+
end2: end2
275+
}),
276+
weiPerUsd = 10000,
277+
weiAmount = 5000000 * weiPerUsd - 1; // exactly USD 1 less than the funding limit
278+
279+
await crowdsale.setWeiPerUSDinTGE(weiPerUsd);
280+
await increaseTimeTestRPCTo(start + 2);
281+
await crowdsale.buyTokens(beneficiary, {value: weiAmount, from: accounts[5]});
282+
283+
await increaseTimeTestRPCTo(end2 + 2);
284+
await crowdsale.finalize();
285+
286+
const balanceBeforeClaim = web3.eth.getBalance(beneficiary);
287+
288+
const tx = await crowdsale.claimEth({from: beneficiary});
289+
290+
balanceBeforeClaim.plus(weiAmount).minus(help.txGasCost(tx)).
291+
should.be.bignumber.equal(web3.eth.getBalance(beneficiary));
292+
});
293+
294+
it('claimEth fails after a funded finalized crowdsale', async function() {
295+
const start = latestTime() + defaultTimeDelta,
296+
end1 = start + defaultTimeDelta,
297+
end2 = end1 + defaultTimeDelta,
298+
crowdsale = await createCrowdsale({
299+
start: start,
300+
end1: end1,
301+
end2: end2
302+
}),
303+
weiPerUsd = 10000,
304+
weiAmount = 5000000 * weiPerUsd;
305+
await crowdsale.setWeiPerUSDinTGE(weiPerUsd);
306+
await increaseTimeTestRPCTo(start + 2);
307+
await crowdsale.buyTokens(accounts[6], {value: weiAmount, from: accounts[5]});
308+
309+
await increaseTimeTestRPCTo(end2 + 2);
310+
await crowdsale.finalize();
311+
312+
try {
313+
await crowdsale.claimEth({from: accounts[6]});
314+
assert(false, 'should have thrown');
315+
} catch(e) {
316+
assert(help.isInvalidOpcodeEx(e));
317+
}
318+
});
319+
320+
it('claimEth fails after an underfunded non-finalized (but ended) crowdsale ', async function() {
321+
const start = latestTime() + defaultTimeDelta,
322+
end1 = start + defaultTimeDelta,
323+
end2 = end1 + defaultTimeDelta,
324+
beneficiary = accounts[6],
325+
crowdsale = await createCrowdsale({
326+
start: start,
327+
end1: end1,
328+
end2: end2
329+
}),
330+
weiPerUsd = 10000,
331+
weiAmount = 5000000 * weiPerUsd - 1;
332+
await crowdsale.setWeiPerUSDinTGE(weiPerUsd);
333+
await increaseTimeTestRPCTo(start + 2);
334+
await crowdsale.buyTokens(beneficiary, {value: weiAmount, from: accounts[5]});
335+
336+
await increaseTimeTestRPCTo(end2 + 2);
337+
338+
try {
339+
await crowdsale.claimEth({from: beneficiary});
340+
assert(false, 'should have thrown');
341+
} catch(e) {
342+
assert(help.isInvalidOpcodeEx(e));
343+
}
344+
});
345+
346+
it('claimEth fails after an underfunded finalized crowdsale for an address with no purchases', async function() {
347+
const start = latestTime() + defaultTimeDelta,
348+
end1 = start + defaultTimeDelta,
349+
end2 = end1 + defaultTimeDelta,
350+
beneficiary = accounts[6],
351+
crowdsale = await createCrowdsale({
352+
start: start,
353+
end1: end1,
354+
end2: end2
355+
}),
356+
weiPerUsd = 10000,
357+
weiAmount = 5000000 * weiPerUsd - 1; // exactly USD 1 less than the funding limit
358+
359+
await crowdsale.setWeiPerUSDinTGE(weiPerUsd);
360+
await increaseTimeTestRPCTo(start + 2);
361+
await crowdsale.buyTokens(beneficiary, {value: weiAmount, from: accounts[5]});
362+
363+
await increaseTimeTestRPCTo(end2 + 2);
364+
await crowdsale.finalize();
365+
366+
try {
367+
await crowdsale.claimEth({from: accounts[8]});
368+
assert(false, 'should have thrown');
369+
} catch(e) {
370+
assert(help.isInvalidOpcodeEx(e));
371+
}
372+
});
373+
374+
/// finalize
375+
it('finalize fails when called for the second time', async function() {
376+
const start = latestTime() + defaultTimeDelta,
377+
end1 = start + defaultTimeDelta,
378+
end2 = end1 + defaultTimeDelta,
379+
beneficiary = accounts[6],
380+
crowdsale = await createCrowdsale({
381+
start: start,
382+
end1: end1,
383+
end2: end2
384+
}),
385+
weiPerUsd = 10000,
386+
weiAmount = 5000000 * weiPerUsd - 1; // exactly USD 1 less than the funding limit
387+
388+
await crowdsale.setWeiPerUSDinTGE(weiPerUsd);
389+
await increaseTimeTestRPCTo(start + 2);
390+
await crowdsale.buyTokens(beneficiary, {value: weiAmount, from: accounts[5]});
391+
392+
await increaseTimeTestRPCTo(end2 + 2);
393+
await crowdsale.finalize();
394+
395+
try {
396+
await crowdsale.finalize();
397+
assert(false, 'should have thrown');
398+
} catch(e) {
399+
assert(help.isInvalidOpcodeEx(e));
400+
}
401+
});
402+
247403
});

0 commit comments

Comments
 (0)