MintedCrowdsale.behavior.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. const expectEvent = require('../helpers/expectEvent');
  2. const { ethGetBalance } = require('../helpers/web3');
  3. const BigNumber = web3.BigNumber;
  4. require('chai')
  5. .use(require('chai-bignumber')(BigNumber))
  6. .should();
  7. function shouldBehaveLikeMintedCrowdsale ([_, investor, wallet, purchaser], rate, value) {
  8. const expectedTokenAmount = rate.mul(value);
  9. describe('as a minted crowdsale', function () {
  10. describe('accepting payments', function () {
  11. it('should accept payments', async function () {
  12. await this.crowdsale.send(value);
  13. await this.crowdsale.buyTokens(investor, { value: value, from: purchaser });
  14. });
  15. });
  16. describe('high-level purchase', function () {
  17. it('should log purchase', async function () {
  18. const { logs } = await this.crowdsale.sendTransaction({ value: value, from: investor });
  19. expectEvent.inLogs(logs, 'TokensPurchased', {
  20. purchaser: investor,
  21. beneficiary: investor,
  22. value: value,
  23. amount: expectedTokenAmount,
  24. });
  25. });
  26. it('should assign tokens to sender', async function () {
  27. await this.crowdsale.sendTransaction({ value: value, from: investor });
  28. (await this.token.balanceOf(investor)).should.be.bignumber.equal(expectedTokenAmount);
  29. });
  30. it('should forward funds to wallet', async function () {
  31. const pre = await ethGetBalance(wallet);
  32. await this.crowdsale.sendTransaction({ value, from: investor });
  33. const post = await ethGetBalance(wallet);
  34. post.minus(pre).should.be.bignumber.equal(value);
  35. });
  36. });
  37. });
  38. }
  39. module.exports = {
  40. shouldBehaveLikeMintedCrowdsale,
  41. };