CappedCrowdsale.test.js 2.2 KB

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