Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Improved PostDeliveryCrowdsale tests.
  • Loading branch information
nventuro committed Aug 24, 2018
commit 22788d96ff96e3b965b3317d763ee4cd7b22263f
57 changes: 33 additions & 24 deletions test/crowdsale/PostDeliveryCrowdsale.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const SimpleToken = artifacts.require('SimpleToken');

contract('PostDeliveryCrowdsale', function ([_, investor, wallet, purchaser]) {
const rate = new BigNumber(1);
const value = ether(42);
const tokenSupply = new BigNumber('1e22');

before(async function () {
Expand All @@ -27,7 +26,6 @@ contract('PostDeliveryCrowdsale', function ([_, investor, wallet, purchaser]) {
beforeEach(async function () {
this.openingTime = (await latestTime()) + duration.weeks(1);
this.closingTime = this.openingTime + duration.weeks(1);
this.beforeEndTime = this.closingTime - duration.hours(1);
this.afterClosingTime = this.closingTime + duration.seconds(1);
this.token = await SimpleToken.new();
this.crowdsale = await PostDeliveryCrowdsale.new(
Expand All @@ -36,30 +34,41 @@ contract('PostDeliveryCrowdsale', function ([_, investor, wallet, purchaser]) {
await this.token.transfer(this.crowdsale.address, tokenSupply);
});

it('should not immediately assign tokens to beneficiary', async function () {
await increaseTimeTo(this.openingTime);
await this.crowdsale.buyTokens(investor, { value: value, from: purchaser });
(await this.token.balanceOf(investor)).should.be.bignumber.equal(0);
});
context('after opening time', function () {
beforeEach(async function () {
await increaseTimeTo(this.openingTime);
});

it('should not allow beneficiaries to withdraw tokens before crowdsale ends', async function () {
await increaseTimeTo(this.beforeEndTime);
await this.crowdsale.buyTokens(investor, { value: value, from: purchaser });
await expectThrow(this.crowdsale.withdrawTokens({ from: investor }), EVMRevert);
});
context('with bought tokens', function () {
const value = ether(42);

it('should allow beneficiaries to withdraw tokens after crowdsale ends', async function () {
await increaseTimeTo(this.openingTime);
await this.crowdsale.buyTokens(investor, { value: value, from: purchaser });
await increaseTimeTo(this.afterClosingTime);
await this.crowdsale.withdrawTokens({ from: investor });
});
beforeEach(async function () {
await this.crowdsale.buyTokens(investor, { value: value, from: purchaser });
});

it('should not immediately assign tokens to beneficiary', async function () {
(await this.token.balanceOf(investor)).should.be.bignumber.equal(0);
});

it('should not allow beneficiaries to withdraw tokens before crowdsale ends', async function () {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say "before closing time" to be consistent with the other descriptions.

await expectThrow(this.crowdsale.withdrawTokens({ from: investor }), EVMRevert);
});

context('after closing time', function () {
beforeEach(async function () {
await increaseTimeTo(this.afterClosingTime);
});

it('should allow beneficiaries to withdraw tokens', async function () {
await this.crowdsale.withdrawTokens({ from: investor });
(await this.token.balanceOf(investor)).should.be.bignumber.equal(value);
});

it('should return the amount of tokens bought', async function () {
await increaseTimeTo(this.openingTime);
await this.crowdsale.buyTokens(investor, { value: value, from: purchaser });
await increaseTimeTo(this.afterClosingTime);
await this.crowdsale.withdrawTokens({ from: investor });
(await this.token.balanceOf(investor)).should.be.bignumber.equal(value);
it('should ony allow a single withdrawal', async function () {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in ony.

await this.crowdsale.withdrawTokens({ from: investor });
await expectThrow(this.crowdsale.withdrawTokens({ from: investor }), EVMRevert);
});
});
});
});
});