CappedCrowdsale.test.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. const { ether } = require('../helpers/ether');
  2. const shouldFail = require('../helpers/shouldFail');
  3. const { BigNumber } = require('../helpers/setup');
  4. const CappedCrowdsaleImpl = artifacts.require('CappedCrowdsaleImpl');
  5. const SimpleToken = artifacts.require('SimpleToken');
  6. contract('CappedCrowdsale', function ([_, wallet]) {
  7. const rate = new BigNumber(1);
  8. const cap = ether(100);
  9. const lessThanCap = ether(60);
  10. const tokenSupply = new BigNumber('1e22');
  11. beforeEach(async function () {
  12. this.token = await SimpleToken.new();
  13. });
  14. it('rejects a cap of zero', async function () {
  15. await shouldFail.reverting(CappedCrowdsaleImpl.new(rate, wallet, this.token.address, 0));
  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.minus(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(this.crowdsale.send(1));
  30. });
  31. it('should reject payments that exceed cap', async function () {
  32. await shouldFail.reverting(this.crowdsale.send(cap.plus(1)));
  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.minus(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. });