MintedCrowdsale.behavior.js 1.5 KB

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