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