MintedCrowdsale.test.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. const { BN, ether, shouldFail } = require('openzeppelin-test-helpers');
  2. const { shouldBehaveLikeMintedCrowdsale } = require('./MintedCrowdsale.behavior');
  3. const MintedCrowdsaleImpl = artifacts.require('MintedCrowdsaleImpl');
  4. const ERC20Mintable = artifacts.require('ERC20Mintable');
  5. const ERC20 = artifacts.require('ERC20');
  6. contract('MintedCrowdsale', function ([_, deployer, investor, wallet, purchaser]) {
  7. const rate = new BN('1000');
  8. const value = ether('5');
  9. describe('using ERC20Mintable', function () {
  10. beforeEach(async function () {
  11. this.token = await ERC20Mintable.new({ from: deployer });
  12. this.crowdsale = await MintedCrowdsaleImpl.new(rate, wallet, this.token.address);
  13. await this.token.addMinter(this.crowdsale.address, { from: deployer });
  14. await this.token.renounceMinter({ from: deployer });
  15. });
  16. it('crowdsale should be minter', async function () {
  17. (await this.token.isMinter(this.crowdsale.address)).should.equal(true);
  18. });
  19. shouldBehaveLikeMintedCrowdsale([_, investor, wallet, purchaser], rate, value);
  20. });
  21. describe('using non-mintable token', function () {
  22. beforeEach(async function () {
  23. this.token = await ERC20.new();
  24. this.crowdsale = await MintedCrowdsaleImpl.new(rate, wallet, this.token.address);
  25. });
  26. it('rejects bare payments', async function () {
  27. await shouldFail.reverting(this.crowdsale.send(value));
  28. });
  29. it('rejects token purchases', async function () {
  30. await shouldFail.reverting(this.crowdsale.buyTokens(investor, { value: value, from: purchaser }));
  31. });
  32. });
  33. });