Skip to content

Commit 35bfb09

Browse files
committed
added test cases
1 parent 2ac3864 commit 35bfb09

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

test/2_airdrop.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ contract('Airdrop', function(accounts) {
55

66
var airdropInstance;
77
var tokenInstance;
8+
// random address as need 0 eth balance account to test
9+
var zero_balance = '0xf59b7E0F657B0DCBaD411465F5A534121fF42B58';
810

911
before(function () {
1012
return AirDrop.deployed().then(function(instance) {
@@ -38,17 +40,25 @@ contract('Airdrop', function(accounts) {
3840

3941
it("do 1 token airdrop to 2 different address", function() {
4042
var amount = 1;
41-
var address = [accounts[1],accounts[2]];
43+
var eth_amount = 100;
4244

4345
// Get initial balances of first and second account.
4446
var account_one = accounts[1];
45-
var account_two = accounts[2];
47+
var account_two = zero_balance;
4648

4749
var account_one_starting_balance;
4850
var account_two_starting_balance;
4951
var account_one_ending_balance;
5052
var account_two_ending_balance;
5153

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+
5262
return tokenInstance.mint(10000)
5363
.then(function(instance){
5464
// transfer token to airdrop
@@ -63,7 +73,7 @@ contract('Airdrop', function(accounts) {
6373
}).then(function(balance){
6474
account_two_starting_balance = balance.toNumber();
6575
// do airdrop
66-
return airdropInstance.doAirDrop(address,amount,100);
76+
return airdropInstance.doAirDrop(address,amount,eth_amount);
6777
}).then(function(){
6878
// check balance for account 1
6979
return tokenInstance.balanceOf.call(account_one);
@@ -76,6 +86,13 @@ contract('Airdrop', function(accounts) {
7686
// check if balance has updated or not
7787
assert.equal(account_one_ending_balance, account_one_starting_balance + amount, "Amount wasn't sent to the receiver one");
7888
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");
7996
});
8097
});
8198
});

0 commit comments

Comments
 (0)