MintedCrowdsale.behavior.js 1.5 KB

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