@@ -5,13 +5,18 @@ contract('Airdrop', function(accounts) {
5
5
6
6
var airdropInstance ;
7
7
var tokenInstance ;
8
+ var eth_contract_balance = 5 * ( 10 ** 18 ) ;
9
+ // random address as need 0 eth balance account to test
10
+ var zero_balance = '0xf59b7E0F657B0DCBaD411465F5A534121fF42B58' ;
11
+ var zero_balance2 = '0xf59b7E0F657B0DCBaD411465F5A534121fF42B57' ;
8
12
9
13
before ( function ( ) {
10
14
return AirDrop . deployed ( ) . then ( function ( instance ) {
11
15
airdropInstance = instance ;
12
16
return InviteToken . deployed ( ) ;
13
17
} ) . then ( function ( token ) {
14
18
tokenInstance = token ;
19
+ airdropInstance . send ( eth_contract_balance , { from :accounts [ 0 ] } ) ;
15
20
} ) ;
16
21
} ) ;
17
22
@@ -22,6 +27,10 @@ contract('Airdrop', function(accounts) {
22
27
} ) ;
23
28
} ) ;
24
29
30
+ it ( "should have balance 5 eth" , function ( ) {
31
+ assert . equal ( eth_contract_balance , web3 . eth . getBalance ( airdropInstance . address ) . toNumber ( ) , "should have balance 5 eth" ) ;
32
+ } ) ;
33
+
25
34
it ( "airdrop should fail as no balance is assigned" , function ( ) {
26
35
var address = [ accounts [ 1 ] , accounts [ 2 ] ] ;
27
36
return airdropInstance . doAirDrop ( address , 1 ) . then ( function ( instance ) {
@@ -33,16 +42,32 @@ contract('Airdrop', function(accounts) {
33
42
34
43
it ( "do 1 token airdrop to 2 different address" , function ( ) {
35
44
var amount = 1 ;
36
- var address = [ accounts [ 1 ] , accounts [ 2 ] ] ;
45
+ var eth_amount = 100 ;
37
46
38
47
// Get initial balances of first and second account.
39
48
var account_one = accounts [ 1 ] ;
40
- var account_two = accounts [ 2 ] ;
49
+ var account_two = zero_balance ;
50
+ var account_three = zero_balance2 ;
41
51
42
52
var account_one_starting_balance ;
43
53
var account_two_starting_balance ;
54
+ var account_three_starting_balance ;
55
+
44
56
var account_one_ending_balance ;
45
57
var account_two_ending_balance ;
58
+ var account_three_ending_balance ;
59
+
60
+ var account_one_eth_starting_balance = web3 . eth . getBalance ( account_one ) . toNumber ( ) ;
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 ( ) ;
63
+
64
+ var account_one_eth_ending_balance ;
65
+ var account_two_eth_ending_balance ;
66
+ var account_three_eth_ending_balance ;
67
+
68
+ var address = [ account_one , account_two ] ;
69
+
70
+ var address_batch_2 = [ account_three ] ;
46
71
47
72
return tokenInstance . mint ( 10000 )
48
73
. then ( function ( instance ) {
@@ -57,20 +82,41 @@ contract('Airdrop', function(accounts) {
57
82
return tokenInstance . balanceOf . call ( account_two ) ;
58
83
} ) . then ( function ( balance ) {
59
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 ( ) ;
60
89
// do airdrop
61
- return airdropInstance . doAirDrop ( address , amount ) ;
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 ) ;
62
94
} ) . then ( function ( ) {
63
95
// check balance for account 1
64
96
return tokenInstance . balanceOf . call ( account_one ) ;
65
97
} ) . then ( function ( balance ) {
98
+ account_one_ending_balance = balance . toNumber ( ) ;
66
99
// check balance for account 2
67
- account_one_ending_balance = balance . toNumber ( ) ;
68
100
return tokenInstance . balanceOf . call ( account_two ) ;
69
101
} ) . then ( function ( balance ) {
70
- 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 ( ) ;
71
107
// check if balance has updated or not
72
108
assert . equal ( account_one_ending_balance , account_one_starting_balance + amount , "Amount wasn't sent to the receiver one" ) ;
73
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" ) ;
111
+ // fetch final eth balance
112
+ account_one_eth_ending_balance = web3 . eth . getBalance ( account_one ) . toNumber ( ) ;
113
+ account_two_eth_ending_balance = web3 . eth . getBalance ( account_two ) . toNumber ( ) ;
114
+ account_three_eth_ending_balance = web3 . eth . getBalance ( account_three ) . toNumber ( ) ;
115
+
116
+ // check if eth is updated for 2nd and remains the same for first
117
+ assert . equal ( account_one_eth_ending_balance , account_one_eth_starting_balance , "Eth balance is not the same" ) ;
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" ) ;
74
120
} ) ;
75
121
} ) ;
76
122
} ) ;
0 commit comments