CappedCrowdsale.js 2.6 KB

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