CappedCrowdsale.test.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. const { ether } = require('../helpers/ether');
  2. const { expectThrow } = require('../helpers/expectThrow');
  3. const { EVMRevert } = require('../helpers/EVMRevert');
  4. const BigNumber = web3.BigNumber;
  5. require('chai')
  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. });
  18. it('rejects a cap of zero', async function () {
  19. await expectThrow(
  20. CappedCrowdsale.new(rate, wallet, this.token.address, 0),
  21. EVMRevert,
  22. );
  23. });
  24. context('with crowdsale', function () {
  25. beforeEach(async function () {
  26. this.crowdsale = await CappedCrowdsale.new(rate, wallet, this.token.address, cap);
  27. await this.token.transfer(this.crowdsale.address, tokenSupply);
  28. });
  29. describe('accepting payments', function () {
  30. it('should accept payments within cap', async function () {
  31. await this.crowdsale.send(cap.minus(lessThanCap));
  32. await this.crowdsale.send(lessThanCap);
  33. });
  34. it('should reject payments outside cap', async function () {
  35. await this.crowdsale.send(cap);
  36. await expectThrow(
  37. this.crowdsale.send(1),
  38. EVMRevert,
  39. );
  40. });
  41. it('should reject payments that exceed cap', async function () {
  42. await expectThrow(
  43. this.crowdsale.send(cap.plus(1)),
  44. EVMRevert,
  45. );
  46. });
  47. });
  48. describe('ending', function () {
  49. it('should not reach cap if sent under cap', async function () {
  50. await this.crowdsale.send(lessThanCap);
  51. (await this.crowdsale.capReached()).should.equal(false);
  52. });
  53. it('should not reach cap if sent just under cap', async function () {
  54. await this.crowdsale.send(cap.minus(1));
  55. (await this.crowdsale.capReached()).should.equal(false);
  56. });
  57. it('should reach cap if cap sent', async function () {
  58. await this.crowdsale.send(cap);
  59. (await this.crowdsale.capReached()).should.equal(true);
  60. });
  61. });
  62. });
  63. });