CappedCrowdsale.test.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. 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 expectThrow(
  23. CappedCrowdsale.new(rate, wallet, 0, this.token.address),
  24. EVMRevert,
  25. );
  26. });
  27. });
  28. describe('accepting payments', function () {
  29. it('should accept payments within cap', async function () {
  30. await this.crowdsale.send(cap.minus(lessThanCap));
  31. await this.crowdsale.send(lessThanCap);
  32. });
  33. it('should reject payments outside cap', async function () {
  34. await this.crowdsale.send(cap);
  35. await expectThrow(
  36. this.crowdsale.send(1),
  37. EVMRevert,
  38. );
  39. });
  40. it('should reject payments that exceed cap', async function () {
  41. await expectThrow(
  42. this.crowdsale.send(cap.plus(1)),
  43. EVMRevert,
  44. );
  45. });
  46. });
  47. describe('ending', function () {
  48. it('should not reach cap if sent under cap', async function () {
  49. await this.crowdsale.send(lessThanCap);
  50. (await this.crowdsale.capReached()).should.equal(false);
  51. });
  52. it('should not reach cap if sent just under cap', async function () {
  53. await this.crowdsale.send(cap.minus(1));
  54. (await this.crowdsale.capReached()).should.equal(false);
  55. });
  56. it('should reach cap if cap sent', async function () {
  57. await this.crowdsale.send(cap);
  58. (await this.crowdsale.capReached()).should.equal(true);
  59. });
  60. });
  61. });