Skip to content

Commit

Permalink
add test for multiple receivers, addOne
Browse files Browse the repository at this point in the history
  • Loading branch information
trin-cz committed Oct 15, 2017
1 parent 5d6f932 commit 4a54010
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 6 deletions.
43 changes: 39 additions & 4 deletions contracts/AthenaLabsICO.sol
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ contract AthenaLabsICO is Ownable, Pausable {
uint256 weiEther = msg.value;

// calculate token amount to be created and reduce slots for limited bonuses
// here we are abusing, that Athena is also 18 decimals
uint256 weiTokens = weiEther.mul(rate).add(calculateAndRegisterBonuses(weiEther));

require(weiTotalAthSold.add(weiTokens) <= weiTotalAthSoldCap);
Expand Down Expand Up @@ -195,10 +196,33 @@ contract AthenaLabsICO is Ownable, Pausable {
return withinPeriod && nonTrivialPurchase;
}

function authorizeOne(address investor_addr) canAdmin whenNotPaused public {
Investor storage investor = investors[investor_addr];
require(!investor.authorized);
uint256 athToSend = investor.athReceivedPending;
uint256 ethToForward = investor.etherInvestedPending;
investor.etherInvested = investor.etherInvested.add(ethToForward);
investor.athReceived = investor.athReceived.add(athToSend);
investor.authorized = true;
investor.etherInvestedPending = 0;
investor.athReceivedPending = 0;
if (!investor.exists) {
investor_list.push(investor_addr);
investor.exists = true;
}
Authorized(investor_addr);
if (ethToForward > 0) {
TokenPurchase(investor_addr, ethToForward, athToSend);
mainWallet.transfer(ethToForward);
token.transfer(investor_addr, athToSend);
}
}

function authorize(address[] investor_addrs) canAdmin whenNotPaused public {
require(investor_addrs.length <= 100);
Investor storage investor;
for (uint i = 0; i < investor_addrs.length; i++) {
Investor storage investor = investors[investor_addrs[i]];
investor = investors[investor_addrs[i]];
if (!investor.exists) {
investor_list.push(investor_addrs[i]);
investor.exists = true;
Expand All @@ -209,6 +233,8 @@ contract AthenaLabsICO is Ownable, Pausable {
investor.etherInvested = investor.etherInvested.add(ethToForward);
investor.athReceived = investor.athReceived.add(athToSend);
investor.authorized = true;
investor.etherInvestedPending = 0;
investor.athReceivedPending = 0;
Authorized(investor_addrs[i]);
if (ethToForward > 0) {
TokenPurchase(investor_addrs[i], ethToForward, athToSend);
Expand Down Expand Up @@ -243,12 +269,21 @@ contract AthenaLabsICO is Ownable, Pausable {
return now > endTime;
}

function giveTokensOne(address beneficiary, uint256 weiTokens) canAdmin public {
require(beneficiary != 0x0);
require(weiTokens >= 5 * weiOneToken);
require(weiTotalBountiesGiven.add(weiTokens) <= weiTotalBountiesGivenCap);
weiTotalBountiesGiven = weiTotalBountiesGiven.add(weiTokens);
TokenBounty(beneficiary, weiTokens);
token.transfer(beneficiary, weiTokens);
}

function giveTokens(address[] beneficiaries, uint256 weiTokens) canAdmin public {
require(beneficiaries.length <= 100);
require(weiTokens >= 100 * weiOneToken);
require(weiTotalBountiesGiven.add(weiTokens * beneficiaries.length) <= weiTotalBountiesGivenCap);
require(weiTokens >= 5 * weiOneToken);
require(weiTotalBountiesGiven.add(weiTokens.mul(beneficiaries.length)) <= weiTotalBountiesGivenCap);
weiTotalBountiesGiven = weiTotalBountiesGiven.add(weiTokens.mul(beneficiaries.length));
for (uint i = 0; i < beneficiaries.length; i++) {
weiTotalBountiesGiven = weiTotalBountiesGiven.add(weiTokens);
TokenBounty(beneficiaries[i], weiTokens);
token.transfer(beneficiaries[i], weiTokens);
}
Expand Down
41 changes: 39 additions & 2 deletions test/TestAthenaICO.js
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,8 @@ contract('AthenaLabsICO', function ([_, admin, wallet, investor, reader, owner])
post.minus(pre).should.be.bignumber.equal(value)
})

it('cannot award less than 100 ATH', async function () {
const value = 99 * 10 ** 18;
it('cannot award less than 5 ATH', async function () {
const value = 4 * 10 ** 18;
await increaseTimeTo(this.startTime)
await this.ico.giveTokens([investor], value, {from: owner}).should.be.rejectedWith(EVMThrow)
})
Expand All @@ -480,6 +480,33 @@ contract('AthenaLabsICO', function ([_, admin, wallet, investor, reader, owner])
const post = await this.athtoken.balanceOf(investor)
post.minus(pre).should.be.bignumber.equal(value)
})

it('can give to multiple receivers', async function () {
const value = 200 * 10 ** 18;
await increaseTimeTo(this.startTime)
const pre = await this.athtoken.balanceOf(investor)
await this.ico.giveTokens([investor, investor, investor], value, {from: owner})
const post = await this.athtoken.balanceOf(investor)
post.minus(pre).should.be.bignumber.equal(3 * value)
})

it('can give to multiple different receivers', async function () {
const value = 200 * 10 ** 18;
await increaseTimeTo(this.startTime)
const pre = await this.athtoken.balanceOf(investor)
await this.ico.giveTokens([investor, owner, admin], value, {from: owner})
const post = await this.athtoken.balanceOf(investor)
post.minus(pre).should.be.bignumber.equal(value)
})

it('can give one', async function () {
const value = 200 * 10 ** 18;
await increaseTimeTo(this.startTime)
const pre = await this.athtoken.balanceOf(investor)
await this.ico.giveTokensOne(investor, value, {from: owner})
const post = await this.athtoken.balanceOf(investor)
post.minus(pre).should.be.bignumber.equal(value)
})
})

describe('finalization', function () {
Expand Down Expand Up @@ -703,5 +730,15 @@ contract('AthenaLabsICO', function ([_, admin, wallet, investor, reader, owner])
const post = await this.athtoken.balanceOf(investor)
post.minus(pre).should.be.bignumber.equal(value * (800 + /* time bonus */ 320) + /* early bonus */ 1200*10**18)
})

it('does receive tokens after authorizationOne', async function () {
const value = ether(10)
await increaseTimeTo(this.startTime)
await this.ico.buyTokens({value, from: investor})
const pre = await this.athtoken.balanceOf(investor)
await this.ico.authorizeOne(investor, {from: admin})
const post = await this.athtoken.balanceOf(investor)
post.minus(pre).should.be.bignumber.equal(value * (800 + /* time bonus */ 320) + /* early bonus */ 1200*10**18)
})
})
})

0 comments on commit 4a54010

Please sign in to comment.