CappedCrowdsale.test.js 2.2 KB

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