CappedCrowdsale.test.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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(CappedCrowdsaleImpl.new(rate, wallet, this.token.address, 0));
  14. });
  15. context('with crowdsale', function () {
  16. beforeEach(async function () {
  17. this.crowdsale = await CappedCrowdsaleImpl.new(rate, wallet, this.token.address, cap);
  18. await this.token.transfer(this.crowdsale.address, tokenSupply);
  19. });
  20. describe('accepting payments', function () {
  21. it('should accept payments within cap', async function () {
  22. await this.crowdsale.send(cap.sub(lessThanCap));
  23. await this.crowdsale.send(lessThanCap);
  24. });
  25. it('should reject payments outside cap', async function () {
  26. await this.crowdsale.send(cap);
  27. await shouldFail.reverting(this.crowdsale.send(1));
  28. });
  29. it('should reject payments that exceed cap', async function () {
  30. await shouldFail.reverting(this.crowdsale.send(cap.addn(1)));
  31. });
  32. });
  33. describe('ending', function () {
  34. it('should not reach cap if sent under cap', async function () {
  35. await this.crowdsale.send(lessThanCap);
  36. (await this.crowdsale.capReached()).should.equal(false);
  37. });
  38. it('should not reach cap if sent just under cap', async function () {
  39. await this.crowdsale.send(cap.subn(1));
  40. (await this.crowdsale.capReached()).should.equal(false);
  41. });
  42. it('should reach cap if cap sent', async function () {
  43. await this.crowdsale.send(cap);
  44. (await this.crowdsale.capReached()).should.equal(true);
  45. });
  46. });
  47. });
  48. });