Skip to content

Commit 3ee4794

Browse files
committed
test case
1 parent 2252a55 commit 3ee4794

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

test/2_airdrop.js

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,18 @@ contract('Airdrop', function(accounts) {
55

66
var airdropInstance;
77
var tokenInstance;
8+
var eth_contract_balance = 5*(10**18);
89
// random address as need 0 eth balance account to test
910
var zero_balance = '0xf59b7E0F657B0DCBaD411465F5A534121fF42B58';
11+
var zero_balance2 = '0xf59b7E0F657B0DCBaD411465F5A534121fF42B57';
1012

1113
before(function () {
1214
return AirDrop.deployed().then(function(instance) {
1315
airdropInstance = instance;
1416
return InviteToken.deployed();
1517
}).then(function(token) {
1618
tokenInstance = token;
17-
airdropInstance.send(5*(10**18),{from:accounts[0]});
19+
airdropInstance.send(eth_contract_balance,{from:accounts[0]});
1820
});
1921
});
2022

@@ -26,7 +28,7 @@ contract('Airdrop', function(accounts) {
2628
});
2729

2830
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");
3032
});
3133

3234
it("airdrop should fail as no balance is assigned", function() {
@@ -45,20 +47,28 @@ contract('Airdrop', function(accounts) {
4547
// Get initial balances of first and second account.
4648
var account_one = accounts[1];
4749
var account_two = zero_balance;
50+
var account_three = zero_balance2;
4851

4952
var account_one_starting_balance;
5053
var account_two_starting_balance;
54+
var account_three_starting_balance;
55+
5156
var account_one_ending_balance;
5257
var account_two_ending_balance;
58+
var account_three_ending_balance;
5359

5460
var account_one_eth_starting_balance = web3.eth.getBalance(account_one).toNumber();
5561
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();
5663

5764
var account_one_eth_ending_balance;
5865
var account_two_eth_ending_balance;
66+
var account_three_eth_ending_balance;
5967

6068
var address = [account_one,account_two];
6169

70+
var address_batch_2 = [account_three];
71+
6272
return tokenInstance.mint(10000)
6373
.then(function(instance){
6474
// transfer token to airdrop
@@ -72,27 +82,41 @@ contract('Airdrop', function(accounts) {
7282
return tokenInstance.balanceOf.call(account_two);
7383
}).then(function(balance){
7484
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();
7589
// do airdrop
7690
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);
7794
}).then(function(){
7895
// check balance for account 1
7996
return tokenInstance.balanceOf.call(account_one);
8097
}).then(function(balance){
98+
account_one_ending_balance = balance.toNumber();
8199
// check balance for account 2
82-
account_one_ending_balance = balance.toNumber();
83100
return tokenInstance.balanceOf.call(account_two);
84101
}).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();
86107
// check if balance has updated or not
87108
assert.equal(account_one_ending_balance, account_one_starting_balance + amount, "Amount wasn't sent to the receiver one");
88109
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");
89111
// fetch final eth balance
90112
account_one_eth_ending_balance = web3.eth.getBalance(account_one).toNumber();
91113
account_two_eth_ending_balance = web3.eth.getBalance(account_two).toNumber();
114+
account_three_eth_ending_balance = web3.eth.getBalance(account_three).toNumber();
92115

93116
// check if eth is updated for 2nd and remains the same for first
94117
assert.equal(account_one_eth_ending_balance, account_one_eth_starting_balance, "Eth balance is not the same");
95118
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");
96120
});
97121
});
98122
});

0 commit comments

Comments
 (0)