You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.8 KiB
50 lines
1.8 KiB
7 years ago
|
const { ethGetBalance } = require('../helpers/web3');
|
||
7 years ago
|
|
||
7 years ago
|
const BigNumber = web3.BigNumber;
|
||
|
|
||
|
const should = require('chai')
|
||
|
.use(require('chai-bignumber')(BigNumber))
|
||
|
.should();
|
||
|
|
||
7 years ago
|
function shouldBehaveLikeMintedCrowdsale ([_, investor, wallet, purchaser], rate, value) {
|
||
7 years ago
|
const expectedTokenAmount = rate.mul(value);
|
||
|
|
||
|
describe('as a minted crowdsale', function () {
|
||
|
describe('accepting payments', function () {
|
||
|
it('should accept payments', async function () {
|
||
7 years ago
|
await this.crowdsale.send(value);
|
||
|
await this.crowdsale.buyTokens(investor, { value: value, from: purchaser });
|
||
7 years ago
|
});
|
||
|
});
|
||
|
|
||
|
describe('high-level purchase', function () {
|
||
|
it('should log purchase', async function () {
|
||
|
const { logs } = await this.crowdsale.sendTransaction({ value: value, from: investor });
|
||
|
const event = logs.find(e => e.event === 'TokenPurchase');
|
||
|
should.exist(event);
|
||
|
event.args.purchaser.should.equal(investor);
|
||
|
event.args.beneficiary.should.equal(investor);
|
||
|
event.args.value.should.be.bignumber.equal(value);
|
||
|
event.args.amount.should.be.bignumber.equal(expectedTokenAmount);
|
||
|
});
|
||
|
|
||
|
it('should assign tokens to sender', async function () {
|
||
|
await this.crowdsale.sendTransaction({ value: value, from: investor });
|
||
7 years ago
|
const balance = await this.token.balanceOf(investor);
|
||
7 years ago
|
balance.should.be.bignumber.equal(expectedTokenAmount);
|
||
|
});
|
||
|
|
||
|
it('should forward funds to wallet', async function () {
|
||
7 years ago
|
const pre = await ethGetBalance(wallet);
|
||
7 years ago
|
await this.crowdsale.sendTransaction({ value, from: investor });
|
||
7 years ago
|
const post = await ethGetBalance(wallet);
|
||
7 years ago
|
post.minus(pre).should.be.bignumber.equal(value);
|
||
|
});
|
||
|
});
|
||
|
});
|
||
|
}
|
||
7 years ago
|
|
||
|
module.exports = {
|
||
|
shouldBehaveLikeMintedCrowdsale,
|
||
|
};
|