@@ -3,6 +3,12 @@ var LifCrowdsale = artifacts.require('./LifCrowdsale.sol'),
3
3
4
4
let help = require ( './helpers' ) ;
5
5
6
+ var BigNumber = web3 . BigNumber ;
7
+
8
+ require ( 'chai' )
9
+ . use ( require ( 'chai-bignumber' ) ( BigNumber ) )
10
+ . should ( ) ;
11
+
6
12
var latestTime = require ( './helpers/latestTime' ) ;
7
13
var { duration, increaseTimeTestRPCTo} = require ( './helpers/increaseTime' ) ;
8
14
@@ -189,6 +195,17 @@ contract('LifToken Crowdsale', function(accounts) {
189
195
}
190
196
} ) ;
191
197
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
+
192
209
/// addPrivatePresaleTokens
193
210
it ( 'handles an addPrivatePresaleTokens tx fine' , async function ( ) {
194
211
const crowdsale = await createCrowdsale ( { } ) ,
@@ -244,4 +261,143 @@ contract('LifToken Crowdsale', function(accounts) {
244
261
assert ( help . isInvalidOpcodeEx ( e ) ) ;
245
262
}
246
263
} ) ;
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
+
247
403
} ) ;
0 commit comments