@@ -5,16 +5,18 @@ contract('Airdrop', function(accounts) {
5
5
6
6
var airdropInstance ;
7
7
var tokenInstance ;
8
+ var eth_contract_balance = 5 * ( 10 ** 18 ) ;
8
9
// random address as need 0 eth balance account to test
9
10
var zero_balance = '0xf59b7E0F657B0DCBaD411465F5A534121fF42B58' ;
11
+ var zero_balance2 = '0xf59b7E0F657B0DCBaD411465F5A534121fF42B57' ;
10
12
11
13
before ( function ( ) {
12
14
return AirDrop . deployed ( ) . then ( function ( instance ) {
13
15
airdropInstance = instance ;
14
16
return InviteToken . deployed ( ) ;
15
17
} ) . then ( function ( token ) {
16
18
tokenInstance = token ;
17
- airdropInstance . send ( 5 * ( 10 ** 18 ) , { from :accounts [ 0 ] } ) ;
19
+ airdropInstance . send ( eth_contract_balance , { from :accounts [ 0 ] } ) ;
18
20
} ) ;
19
21
} ) ;
20
22
@@ -26,7 +28,7 @@ contract('Airdrop', function(accounts) {
26
28
} ) ;
27
29
28
30
it ( "should have balance 5 eth" , function ( ) {
29
- assert . equal ( 5 * ( 10 ** 18 ) , web3 . eth . getBalance ( airdropInstance . address ) . toNumber ( ) , "should have balance 5 eth" ) ;
31
+ assert . equal ( eth_contract_balance , web3 . eth . getBalance ( airdropInstance . address ) . toNumber ( ) , "should have balance 5 eth" ) ;
30
32
} ) ;
31
33
32
34
it ( "airdrop should fail as no balance is assigned" , function ( ) {
@@ -45,20 +47,28 @@ contract('Airdrop', function(accounts) {
45
47
// Get initial balances of first and second account.
46
48
var account_one = accounts [ 1 ] ;
47
49
var account_two = zero_balance ;
50
+ var account_three = zero_balance2 ;
48
51
49
52
var account_one_starting_balance ;
50
53
var account_two_starting_balance ;
54
+ var account_three_starting_balance ;
55
+
51
56
var account_one_ending_balance ;
52
57
var account_two_ending_balance ;
58
+ var account_three_ending_balance ;
53
59
54
60
var account_one_eth_starting_balance = web3 . eth . getBalance ( account_one ) . toNumber ( ) ;
55
61
var account_two_eth_starting_balance = web3 . eth . getBalance ( account_two ) . toNumber ( ) ;
62
+ var account_three_eth_starting_balance = web3 . eth . getBalance ( account_two ) . toNumber ( ) ;
56
63
57
64
var account_one_eth_ending_balance ;
58
65
var account_two_eth_ending_balance ;
66
+ var account_three_eth_ending_balance ;
59
67
60
68
var address = [ account_one , account_two ] ;
61
69
70
+ var address_batch_2 = [ account_three ] ;
71
+
62
72
return tokenInstance . mint ( 10000 )
63
73
. then ( function ( instance ) {
64
74
// transfer token to airdrop
@@ -72,27 +82,41 @@ contract('Airdrop', function(accounts) {
72
82
return tokenInstance . balanceOf . call ( account_two ) ;
73
83
} ) . then ( function ( balance ) {
74
84
account_two_starting_balance = balance . toNumber ( ) ;
85
+ // check balance for account 2
86
+ return tokenInstance . balanceOf . call ( account_three ) ;
87
+ } ) . then ( function ( balance ) {
88
+ account_three_starting_balance = balance . toNumber ( ) ;
75
89
// do airdrop
76
90
return airdropInstance . doAirDrop ( address , amount , eth_amount ) ;
91
+ } ) . then ( function ( ) {
92
+ // do airdrop batch 2 with high eth amount
93
+ return airdropInstance . doAirDrop ( address_batch_2 , amount , eth_contract_balance ) ;
77
94
} ) . then ( function ( ) {
78
95
// check balance for account 1
79
96
return tokenInstance . balanceOf . call ( account_one ) ;
80
97
} ) . then ( function ( balance ) {
98
+ account_one_ending_balance = balance . toNumber ( ) ;
81
99
// check balance for account 2
82
- account_one_ending_balance = balance . toNumber ( ) ;
83
100
return tokenInstance . balanceOf . call ( account_two ) ;
84
101
} ) . then ( function ( balance ) {
85
- account_two_ending_balance = balance . toNumber ( ) ;
102
+ account_two_ending_balance = balance . toNumber ( ) ;
103
+ // check balance for account 3
104
+ return tokenInstance . balanceOf . call ( account_three ) ;
105
+ } ) . then ( function ( balance ) {
106
+ account_three_ending_balance = balance . toNumber ( ) ;
86
107
// check if balance has updated or not
87
108
assert . equal ( account_one_ending_balance , account_one_starting_balance + amount , "Amount wasn't sent to the receiver one" ) ;
88
109
assert . equal ( account_two_ending_balance , account_two_starting_balance + amount , "Amount wasn't correctly sent to the receiver two" ) ;
110
+ assert . equal ( account_three_ending_balance , account_three_starting_balance + amount , "Amount wasn't correctly sent to the receiver three" ) ;
89
111
// fetch final eth balance
90
112
account_one_eth_ending_balance = web3 . eth . getBalance ( account_one ) . toNumber ( ) ;
91
113
account_two_eth_ending_balance = web3 . eth . getBalance ( account_two ) . toNumber ( ) ;
114
+ account_three_eth_ending_balance = web3 . eth . getBalance ( account_three ) . toNumber ( ) ;
92
115
93
116
// check if eth is updated for 2nd and remains the same for first
94
117
assert . equal ( account_one_eth_ending_balance , account_one_eth_starting_balance , "Eth balance is not the same" ) ;
95
118
assert . equal ( account_two_eth_ending_balance , account_two_eth_starting_balance + eth_amount , "Eth balance was not update correctly" ) ;
119
+ assert . equal ( account_three_eth_ending_balance , account_three_eth_starting_balance , "Eth balance is not the same when eth amount passed was more then balance" ) ;
96
120
} ) ;
97
121
} ) ;
98
122
} ) ;
0 commit comments