MintedCrowdsale.behavior.js 1.5 KB

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