MintedCrowdsale.test.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 MintableToken = artifacts.require('MintableToken');
  7. const RBACMintableToken = artifacts.require('RBACMintableToken');
  8. const StandardToken = artifacts.require('StandardToken');
  9. contract('MintedCrowdsale', function ([_, investor, wallet, purchaser]) {
  10. const rate = new BigNumber(1000);
  11. const value = ether(5);
  12. describe('using MintableToken', function () {
  13. beforeEach(async function () {
  14. this.token = await MintableToken.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. const ROLE_MINTER = 'minter';
  25. beforeEach(async function () {
  26. this.token = await RBACMintableToken.new();
  27. this.crowdsale = await MintedCrowdsale.new(rate, wallet, this.token.address);
  28. await this.token.addMinter(this.crowdsale.address);
  29. });
  30. it('should have minter role on token', async function () {
  31. (await this.token.hasRole(this.crowdsale.address, ROLE_MINTER)).should.equal(true);
  32. });
  33. shouldBehaveLikeMintedCrowdsale([_, investor, wallet, purchaser], rate, value);
  34. });
  35. describe('using non-mintable token', function () {
  36. beforeEach(async function () {
  37. this.token = await StandardToken.new();
  38. this.crowdsale = await MintedCrowdsale.new(rate, wallet, this.token.address);
  39. });
  40. it('rejects bare payments', async function () {
  41. await assertRevert(this.crowdsale.send(value));
  42. });
  43. it('rejects token purchases', async function () {
  44. await assertRevert(this.crowdsale.buyTokens(investor, { value: value, from: purchaser }));
  45. });
  46. });
  47. });