MintedCrowdsale.test.js 1.7 KB

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