No longer assigning awaits to temporary variables. (#1216)

This commit is contained in:
Nicolás Venturo
2018-08-17 16:10:40 -03:00
committed by GitHub
parent df9426f989
commit 20cf885430
43 changed files with 231 additions and 467 deletions

View File

@ -47,8 +47,7 @@ contract('AllowanceCrowdsale', function ([_, investor, wallet, purchaser, tokenW
it('should assign tokens to sender', async function () {
await this.crowdsale.sendTransaction({ value: value, from: investor });
const balance = await this.token.balanceOf(investor);
balance.should.be.bignumber.equal(expectedTokenAmount);
(await this.token.balanceOf(investor)).should.be.bignumber.equal(expectedTokenAmount);
});
it('should forward funds to wallet', async function () {
@ -63,8 +62,7 @@ contract('AllowanceCrowdsale', function ([_, investor, wallet, purchaser, tokenW
it('should report correct allowace left', async function () {
const remainingAllowance = tokenAllowance - expectedTokenAmount;
await this.crowdsale.buyTokens(investor, { value: value, from: purchaser });
const tokensRemaining = await this.crowdsale.remainingTokens();
tokensRemaining.should.be.bignumber.equal(remainingAllowance);
(await this.crowdsale.remainingTokens()).should.be.bignumber.equal(remainingAllowance);
});
});

View File

@ -57,20 +57,17 @@ contract('CappedCrowdsale', function ([_, wallet]) {
describe('ending', function () {
it('should not reach cap if sent under cap', async function () {
await this.crowdsale.send(lessThanCap);
const capReached = await this.crowdsale.capReached();
capReached.should.eq(false);
(await this.crowdsale.capReached()).should.be.false;
});
it('should not reach cap if sent just under cap', async function () {
await this.crowdsale.send(cap.minus(1));
const capReached = await this.crowdsale.capReached();
capReached.should.eq(false);
(await this.crowdsale.capReached()).should.be.false;
});
it('should reach cap if cap sent', async function () {
await this.crowdsale.send(cap);
const capReached = await this.crowdsale.capReached();
capReached.should.eq(true);
(await this.crowdsale.capReached()).should.be.true;
});
});
});

View File

@ -92,8 +92,7 @@ contract('Crowdsale', function ([_, investor, wallet, purchaser]) {
it('should assign tokens to sender', async function () {
await this.crowdsale.sendTransaction({ value: value, from: investor });
const balance = await this.token.balanceOf(investor);
balance.should.be.bignumber.equal(expectedTokenAmount);
(await this.token.balanceOf(investor)).should.be.bignumber.equal(expectedTokenAmount);
});
it('should forward funds to wallet', async function () {
@ -117,8 +116,7 @@ contract('Crowdsale', function ([_, investor, wallet, purchaser]) {
it('should assign tokens to beneficiary', async function () {
await this.crowdsale.buyTokens(investor, { value, from: purchaser });
const balance = await this.token.balanceOf(investor);
balance.should.be.bignumber.equal(expectedTokenAmount);
(await this.token.balanceOf(investor)).should.be.bignumber.equal(expectedTokenAmount);
});
it('should forward funds to wallet', async function () {

View File

@ -17,7 +17,6 @@ contract('IncreasingPriceCrowdsale', function ([_, investor, wallet, purchaser])
const tokenSupply = new BigNumber('1e22');
describe('rate during crowdsale should change at a fixed step every block', async function () {
let balance;
const initialRate = new BigNumber(9166);
const finalRate = new BigNumber(5500);
const rateAtTime150 = new BigNumber(9166);
@ -42,50 +41,43 @@ contract('IncreasingPriceCrowdsale', function ([_, investor, wallet, purchaser])
it('at start', async function () {
await increaseTimeTo(this.startTime);
await this.crowdsale.buyTokens(investor, { value, from: purchaser });
balance = await this.token.balanceOf(investor);
balance.should.be.bignumber.equal(value.mul(initialRate));
(await this.token.balanceOf(investor)).should.be.bignumber.equal(value.mul(initialRate));
});
it('at time 150', async function () {
await increaseTimeTo(this.startTime + 150);
await this.crowdsale.buyTokens(investor, { value, from: purchaser });
balance = await this.token.balanceOf(investor);
balance.should.be.bignumber.equal(value.mul(rateAtTime150));
(await this.token.balanceOf(investor)).should.be.bignumber.equal(value.mul(rateAtTime150));
});
it('at time 300', async function () {
await increaseTimeTo(this.startTime + 300);
await this.crowdsale.buyTokens(investor, { value, from: purchaser });
balance = await this.token.balanceOf(investor);
balance.should.be.bignumber.equal(value.mul(rateAtTime300));
(await this.token.balanceOf(investor)).should.be.bignumber.equal(value.mul(rateAtTime300));
});
it('at time 1500', async function () {
await increaseTimeTo(this.startTime + 1500);
await this.crowdsale.buyTokens(investor, { value, from: purchaser });
balance = await this.token.balanceOf(investor);
balance.should.be.bignumber.equal(value.mul(rateAtTime1500));
(await this.token.balanceOf(investor)).should.be.bignumber.equal(value.mul(rateAtTime1500));
});
it('at time 30', async function () {
await increaseTimeTo(this.startTime + 30);
await this.crowdsale.buyTokens(investor, { value, from: purchaser });
balance = await this.token.balanceOf(investor);
balance.should.be.bignumber.equal(value.mul(rateAtTime30));
(await this.token.balanceOf(investor)).should.be.bignumber.equal(value.mul(rateAtTime30));
});
it('at time 150000', async function () {
await increaseTimeTo(this.startTime + 150000);
await this.crowdsale.buyTokens(investor, { value, from: purchaser });
balance = await this.token.balanceOf(investor);
balance.should.be.bignumber.equal(value.mul(rateAtTime150000));
(await this.token.balanceOf(investor)).should.be.bignumber.equal(value.mul(rateAtTime150000));
});
it('at time 450000', async function () {
await increaseTimeTo(this.startTime + 450000);
await this.crowdsale.buyTokens(investor, { value, from: purchaser });
balance = await this.token.balanceOf(investor);
balance.should.be.bignumber.equal(value.mul(rateAtTime450000));
(await this.token.balanceOf(investor)).should.be.bignumber.equal(value.mul(rateAtTime450000));
});
});
});

View File

@ -56,14 +56,12 @@ contract('IndividuallyCappedCrowdsale', function ([_, wallet, alice, bob, charli
describe('reporting state', function () {
it('should report correct cap', async function () {
const retrievedCap = await this.crowdsale.getUserCap(alice);
retrievedCap.should.be.bignumber.equal(capAlice);
(await this.crowdsale.getUserCap(alice)).should.be.bignumber.equal(capAlice);
});
it('should report actual contribution', async function () {
await this.crowdsale.buyTokens(alice, { value: lessThanCapAlice });
const retrievedContribution = await this.crowdsale.getUserContribution(alice);
retrievedContribution.should.be.bignumber.equal(lessThanCapAlice);
(await this.crowdsale.getUserContribution(alice)).should.be.bignumber.equal(lessThanCapAlice);
});
});
});
@ -97,10 +95,8 @@ contract('IndividuallyCappedCrowdsale', function ([_, wallet, alice, bob, charli
describe('reporting state', function () {
it('should report correct cap', async function () {
const retrievedCapBob = await this.crowdsale.getUserCap(bob);
retrievedCapBob.should.be.bignumber.equal(capBob);
const retrievedCapCharlie = await this.crowdsale.getUserCap(charlie);
retrievedCapCharlie.should.be.bignumber.equal(capBob);
(await this.crowdsale.getUserCap(bob)).should.be.bignumber.equal(capBob);
(await this.crowdsale.getUserCap(charlie)).should.be.bignumber.equal(capBob);
});
});
});

View File

@ -30,8 +30,7 @@ function shouldBehaveLikeMintedCrowdsale ([_, investor, wallet, purchaser], rate
it('should assign tokens to sender', async function () {
await this.crowdsale.sendTransaction({ value: value, from: investor });
const balance = await this.token.balanceOf(investor);
balance.should.be.bignumber.equal(expectedTokenAmount);
(await this.token.balanceOf(investor)).should.be.bignumber.equal(expectedTokenAmount);
});
it('should forward funds to wallet', async function () {

View File

@ -19,8 +19,7 @@ contract('MintedCrowdsale', function ([_, investor, wallet, purchaser]) {
});
it('should be token owner', async function () {
const owner = await this.token.owner();
owner.should.eq(this.crowdsale.address);
(await this.token.owner()).should.eq(this.crowdsale.address);
});
shouldBehaveLikeMintedCrowdsale([_, investor, wallet, purchaser], rate, value);
@ -36,8 +35,7 @@ contract('MintedCrowdsale', function ([_, investor, wallet, purchaser]) {
});
it('should have minter role on token', async function () {
const isMinter = await this.token.hasRole(this.crowdsale.address, ROLE_MINTER);
isMinter.should.eq(true);
(await this.token.hasRole(this.crowdsale.address, ROLE_MINTER)).should.be.true;
});
shouldBehaveLikeMintedCrowdsale([_, investor, wallet, purchaser], rate, value);

View File

@ -39,8 +39,7 @@ contract('PostDeliveryCrowdsale', function ([_, investor, wallet, purchaser]) {
it('should not immediately assign tokens to beneficiary', async function () {
await increaseTimeTo(this.openingTime);
await this.crowdsale.buyTokens(investor, { value: value, from: purchaser });
const balance = await this.token.balanceOf(investor);
balance.should.be.bignumber.equal(0);
(await this.token.balanceOf(investor)).should.be.bignumber.equal(0);
});
it('should not allow beneficiaries to withdraw tokens before crowdsale ends', async function () {
@ -61,7 +60,6 @@ contract('PostDeliveryCrowdsale', function ([_, investor, wallet, purchaser]) {
await this.crowdsale.buyTokens(investor, { value: value, from: purchaser });
await increaseTimeTo(this.afterClosingTime);
await this.crowdsale.withdrawTokens({ from: investor });
const balance = await this.token.balanceOf(investor);
balance.should.be.bignumber.equal(value);
(await this.token.balanceOf(investor)).should.be.bignumber.equal(value);
});
});

View File

@ -34,11 +34,9 @@ contract('TimedCrowdsale', function ([_, investor, wallet, purchaser]) {
});
it('should be ended only after end', async function () {
let ended = await this.crowdsale.hasClosed();
ended.should.eq(false);
(await this.crowdsale.hasClosed()).should.be.false;
await increaseTimeTo(this.afterClosingTime);
ended = await this.crowdsale.hasClosed();
ended.should.eq(true);
(await this.crowdsale.hasClosed()).should.be.true;
});
describe('accepting payments', function () {

View File

@ -43,10 +43,8 @@ contract('WhitelistedCrowdsale', function ([_, wallet, authorized, unauthorized,
describe('reporting whitelisted', function () {
it('should correctly report whitelisted addresses', async function () {
const isAuthorized = await this.crowdsale.whitelist(authorized);
isAuthorized.should.eq(true);
const isntAuthorized = await this.crowdsale.whitelist(unauthorized);
isntAuthorized.should.eq(false);
(await this.crowdsale.whitelist(authorized)).should.be.true;
(await this.crowdsale.whitelist(unauthorized)).should.be.false;
});
});
});
@ -82,12 +80,9 @@ contract('WhitelistedCrowdsale', function ([_, wallet, authorized, unauthorized,
describe('reporting whitelisted', function () {
it('should correctly report whitelisted addresses', async function () {
const isAuthorized = await this.crowdsale.whitelist(authorized);
isAuthorized.should.eq(true);
const isAnotherAuthorized = await this.crowdsale.whitelist(anotherAuthorized);
isAnotherAuthorized.should.eq(true);
const isntAuthorized = await this.crowdsale.whitelist(unauthorized);
isntAuthorized.should.eq(false);
(await this.crowdsale.whitelist(authorized)).should.be.true;
(await this.crowdsale.whitelist(anotherAuthorized)).should.be.true;
(await this.crowdsale.whitelist(unauthorized)).should.be.false;
});
});
});