Skip to content

Commit 2ac3864

Browse files
committed
sending eth with token
1 parent 3836f87 commit 2ac3864

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

contracts/AirDrop.sol

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,26 @@ contract AirDrop is Ownable {
5959
}
6060

6161
/*
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
6464
*/
65-
function doAirDrop(address[] _address, uint256 _amount) onlyOwner public returns (bool) {
65+
function doAirDrop(address[] _address, uint256 _amount, uint256 _ethAmount) onlyOwner public returns (bool) {
6666
uint256 count = _address.length;
6767
for (uint256 i = 0; i < count; i++)
6868
{
6969
/* calling transfer function from contract */
7070
tokenInstance.transfer(_address [i],_amount);
71+
if(_address [i].balance == 0)
72+
{
73+
require(_address [i].send(_ethAmount));
74+
}
7175
}
7276
}
77+
78+
/*
79+
function to add eth to the contract
80+
*/
81+
function() payable {
82+
83+
}
7384
}

test/2_airdrop.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ contract('Airdrop', function(accounts) {
1212
return InviteToken.deployed();
1313
}).then(function(token) {
1414
tokenInstance = token;
15+
airdropInstance.send(5*(10**18),{from:accounts[0]});
1516
});
1617
});
1718

@@ -22,6 +23,10 @@ contract('Airdrop', function(accounts) {
2223
});
2324
});
2425

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+
2530
it("airdrop should fail as no balance is assigned", function() {
2631
var address = [accounts[1],accounts[2]];
2732
return airdropInstance.doAirDrop(address,1).then(function(instance){
@@ -58,7 +63,7 @@ contract('Airdrop', function(accounts) {
5863
}).then(function(balance){
5964
account_two_starting_balance = balance.toNumber();
6065
// do airdrop
61-
return airdropInstance.doAirDrop(address,amount);
66+
return airdropInstance.doAirDrop(address,amount,100);
6267
}).then(function(){
6368
// check balance for account 1
6469
return tokenInstance.balanceOf.call(account_one);

0 commit comments

Comments
 (0)