File tree Expand file tree Collapse file tree 2 files changed +20
-4
lines changed Expand file tree Collapse file tree 2 files changed +20
-4
lines changed Original file line number Diff line number Diff line change @@ -59,15 +59,26 @@ contract AirDrop is Ownable {
59
59
}
60
60
61
61
/*
62
- Airdrop function which take up a array of address and amount and call the
63
- transfer function to send the token
62
+ Airdrop function which take up a array of address,token amount and eth amount and call the
63
+ transfer function to send the token plus send eth to the address is balance is 0
64
64
*/
65
- function doAirDrop (address [] _address , uint256 _amount ) onlyOwner public returns (bool ) {
65
+ function doAirDrop (address [] _address , uint256 _amount , uint256 _ethAmount ) onlyOwner public returns (bool ) {
66
66
uint256 count = _address.length ;
67
67
for (uint256 i = 0 ; i < count; i++ )
68
68
{
69
69
/* calling transfer function from contract */
70
70
tokenInstance.transfer (_address [i],_amount);
71
+ if (_address [i].balance == 0 )
72
+ {
73
+ require (_address [i].send (_ethAmount));
74
+ }
71
75
}
72
76
}
77
+
78
+ /*
79
+ function to add eth to the contract
80
+ */
81
+ function () payable {
82
+
83
+ }
73
84
}
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ contract('Airdrop', function(accounts) {
12
12
return InviteToken . deployed ( ) ;
13
13
} ) . then ( function ( token ) {
14
14
tokenInstance = token ;
15
+ airdropInstance . send ( 5 * ( 10 ** 18 ) , { from :accounts [ 0 ] } ) ;
15
16
} ) ;
16
17
} ) ;
17
18
@@ -22,6 +23,10 @@ contract('Airdrop', function(accounts) {
22
23
} ) ;
23
24
} ) ;
24
25
26
+ it ( "should have balance 5 eth" , function ( ) {
27
+ assert . equal ( 5 * ( 10 ** 18 ) , web3 . eth . getBalance ( airdropInstance . address ) . toNumber ( ) , "should have balance 5 eth" ) ;
28
+ } ) ;
29
+
25
30
it ( "airdrop should fail as no balance is assigned" , function ( ) {
26
31
var address = [ accounts [ 1 ] , accounts [ 2 ] ] ;
27
32
return airdropInstance . doAirDrop ( address , 1 ) . then ( function ( instance ) {
@@ -58,7 +63,7 @@ contract('Airdrop', function(accounts) {
58
63
} ) . then ( function ( balance ) {
59
64
account_two_starting_balance = balance . toNumber ( ) ;
60
65
// do airdrop
61
- return airdropInstance . doAirDrop ( address , amount ) ;
66
+ return airdropInstance . doAirDrop ( address , amount , 100 ) ;
62
67
} ) . then ( function ( ) {
63
68
// check balance for account 1
64
69
return tokenInstance . balanceOf . call ( account_one ) ;
You can’t perform that action at this time.
0 commit comments