CappedCrowdsale.test.js 2.3 KB

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