@@ -5,6 +5,8 @@ contract('Airdrop', function(accounts) {
5
5
6
6
var airdropInstance ;
7
7
var tokenInstance ;
8
+ // random address as need 0 eth balance account to test
9
+ var zero_balance = '0xf59b7E0F657B0DCBaD411465F5A534121fF42B58' ;
8
10
9
11
before ( function ( ) {
10
12
return AirDrop . deployed ( ) . then ( function ( instance ) {
@@ -38,17 +40,25 @@ contract('Airdrop', function(accounts) {
38
40
39
41
it ( "do 1 token airdrop to 2 different address" , function ( ) {
40
42
var amount = 1 ;
41
- var address = [ accounts [ 1 ] , accounts [ 2 ] ] ;
43
+ var eth_amount = 100 ;
42
44
43
45
// Get initial balances of first and second account.
44
46
var account_one = accounts [ 1 ] ;
45
- var account_two = accounts [ 2 ] ;
47
+ var account_two = zero_balance ;
46
48
47
49
var account_one_starting_balance ;
48
50
var account_two_starting_balance ;
49
51
var account_one_ending_balance ;
50
52
var account_two_ending_balance ;
51
53
54
+ var account_one_eth_starting_balance = web3 . eth . getBalance ( account_one ) . toNumber ( ) ;
55
+ var account_two_eth_starting_balance = web3 . eth . getBalance ( account_two ) . toNumber ( ) ;
56
+
57
+ var account_one_eth_ending_balance ;
58
+ var account_two_eth_ending_balance ;
59
+
60
+ var address = [ account_one , account_two ] ;
61
+
52
62
return tokenInstance . mint ( 10000 )
53
63
. then ( function ( instance ) {
54
64
// transfer token to airdrop
@@ -63,7 +73,7 @@ contract('Airdrop', function(accounts) {
63
73
} ) . then ( function ( balance ) {
64
74
account_two_starting_balance = balance . toNumber ( ) ;
65
75
// do airdrop
66
- return airdropInstance . doAirDrop ( address , amount , 100 ) ;
76
+ return airdropInstance . doAirDrop ( address , amount , eth_amount ) ;
67
77
} ) . then ( function ( ) {
68
78
// check balance for account 1
69
79
return tokenInstance . balanceOf . call ( account_one ) ;
@@ -76,6 +86,13 @@ contract('Airdrop', function(accounts) {
76
86
// check if balance has updated or not
77
87
assert . equal ( account_one_ending_balance , account_one_starting_balance + amount , "Amount wasn't sent to the receiver one" ) ;
78
88
assert . equal ( account_two_ending_balance , account_two_starting_balance + amount , "Amount wasn't correctly sent to the receiver two" ) ;
89
+ // fetch final eth balance
90
+ account_one_eth_ending_balance = web3 . eth . getBalance ( account_one ) . toNumber ( ) ;
91
+ account_two_eth_ending_balance = web3 . eth . getBalance ( account_two ) . toNumber ( ) ;
92
+
93
+ // check if eth is updated for 2nd and remains the same for first
94
+ assert . equal ( account_one_eth_ending_balance , account_one_eth_starting_balance , "Eth balance is not the same" ) ;
95
+ assert . equal ( account_two_eth_ending_balance , account_two_eth_starting_balance + eth_amount , "Eth balance was not update correctly" ) ;
79
96
} ) ;
80
97
} ) ;
81
98
} ) ;
0 commit comments