MintedCrowdsale.test.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. const { shouldBehaveLikeMintedCrowdsale } = require('./MintedCrowdsale.behavior');
  2. const { ether } = require('../helpers/ether');
  3. const { assertRevert } = require('../helpers/assertRevert');
  4. const BigNumber = web3.BigNumber;
  5. const MintedCrowdsale = artifacts.require('MintedCrowdsaleImpl');
  6. const ERC20Mintable = artifacts.require('ERC20Mintable');
  7. const RBACMintableToken = artifacts.require('RBACMintableToken');
  8. const ERC20 = artifacts.require('ERC20');
  9. contract('MintedCrowdsale', function ([_, investor, wallet, purchaser]) {
  10. const rate = new BigNumber(1000);
  11. const value = ether(5);
  12. describe('using ERC20Mintable', function () {
  13. beforeEach(async function () {
  14. this.token = await ERC20Mintable.new();
  15. this.crowdsale = await MintedCrowdsale.new(rate, wallet, this.token.address);
  16. await this.token.transferOwnership(this.crowdsale.address);
  17. });
  18. it('should be token owner', async function () {
  19. (await this.token.owner()).should.equal(this.crowdsale.address);
  20. });
  21. shouldBehaveLikeMintedCrowdsale([_, investor, wallet, purchaser], rate, value);
  22. });
  23. describe('using RBACMintableToken', function () {
  24. beforeEach(async function () {
  25. this.token = await RBACMintableToken.new();
  26. this.crowdsale = await MintedCrowdsale.new(rate, wallet, this.token.address);
  27. await this.token.addMinter(this.crowdsale.address);
  28. });
  29. it('should have minter role on token', async function () {
  30. (await this.token.isMinter(this.crowdsale.address)).should.equal(true);
  31. });
  32. shouldBehaveLikeMintedCrowdsale([_, investor, wallet, purchaser], rate, value);
  33. });
  34. describe('using non-mintable token', function () {
  35. beforeEach(async function () {
  36. this.token = await ERC20.new();
  37. this.crowdsale = await MintedCrowdsale.new(rate, wallet, this.token.address);
  38. });
  39. it('rejects bare payments', async function () {
  40. await assertRevert(this.crowdsale.send(value));
  41. });
  42. it('rejects token purchases', async function () {
  43. await assertRevert(this.crowdsale.buyTokens(investor, { value: value, from: purchaser }));
  44. });
  45. });
  46. });