CappedCrowdsale.test.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. const { BN, ether, expectRevert } = require('openzeppelin-test-helpers');
  2. const { expect } = require('chai');
  3. const CappedCrowdsaleImpl = artifacts.require('CappedCrowdsaleImpl');
  4. const SimpleToken = artifacts.require('SimpleToken');
  5. contract('CappedCrowdsale', function ([_, wallet]) {
  6. const rate = new BN('1');
  7. const cap = ether('100');
  8. const lessThanCap = ether('60');
  9. const tokenSupply = new BN('10').pow(new BN('22'));
  10. beforeEach(async function () {
  11. this.token = await SimpleToken.new();
  12. });
  13. it('rejects a cap of zero', async function () {
  14. await expectRevert(CappedCrowdsaleImpl.new(rate, wallet, this.token.address, 0),
  15. 'CappedCrowdsale: cap is 0'
  16. );
  17. });
  18. context('with crowdsale', function () {
  19. beforeEach(async function () {
  20. this.crowdsale = await CappedCrowdsaleImpl.new(rate, wallet, this.token.address, cap);
  21. await this.token.transfer(this.crowdsale.address, tokenSupply);
  22. });
  23. describe('accepting payments', function () {
  24. it('should accept payments within cap', async function () {
  25. await this.crowdsale.send(cap.sub(lessThanCap));
  26. await this.crowdsale.send(lessThanCap);
  27. });
  28. it('should reject payments outside cap', async function () {
  29. await this.crowdsale.send(cap);
  30. await expectRevert(this.crowdsale.send(1), 'CappedCrowdsale: cap exceeded');
  31. });
  32. it('should reject payments that exceed cap', async function () {
  33. await expectRevert(this.crowdsale.send(cap.addn(1)), 'CappedCrowdsale: cap exceeded');
  34. });
  35. });
  36. describe('ending', function () {
  37. it('should not reach cap if sent under cap', async function () {
  38. await this.crowdsale.send(lessThanCap);
  39. expect(await this.crowdsale.capReached()).to.equal(false);
  40. });
  41. it('should not reach cap if sent just under cap', async function () {
  42. await this.crowdsale.send(cap.subn(1));
  43. expect(await this.crowdsale.capReached()).to.equal(false);
  44. });
  45. it('should reach cap if cap sent', async function () {
  46. await this.crowdsale.send(cap);
  47. expect(await this.crowdsale.capReached()).to.equal(true);
  48. });
  49. });
  50. });
  51. });