CappedCrowdsale.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. beforeEach(async function () {
  16. this.startBlock = web3.eth.blockNumber + 10
  17. this.endBlock = web3.eth.blockNumber + 20
  18. this.crowdsale = await CappedCrowdsale.new(this.startBlock, this.endBlock, rate, wallet, cap)
  19. this.token = MintableToken.at(await this.crowdsale.token())
  20. })
  21. describe('accepting payments', function () {
  22. beforeEach(async function () {
  23. await advanceToBlock(this.startBlock - 1)
  24. })
  25. it('should accept payments within cap', async function () {
  26. await this.crowdsale.send(cap.minus(lessThanCap)).should.be.fulfilled
  27. await this.crowdsale.send(lessThanCap).should.be.fulfilled
  28. })
  29. it('should reject payments outside cap', async function () {
  30. await this.crowdsale.send(cap)
  31. await this.crowdsale.send(1).should.be.rejectedWith(EVMThrow)
  32. })
  33. it('should reject payments that exceed cap', async function () {
  34. await this.crowdsale.send(cap.plus(1)).should.be.rejectedWith(EVMThrow)
  35. })
  36. })
  37. describe('ending', function () {
  38. beforeEach(async function () {
  39. await advanceToBlock(this.startBlock - 1)
  40. })
  41. it('should not be ended if under cap', async function () {
  42. let hasEnded = await this.crowdsale.hasEnded()
  43. hasEnded.should.equal(false)
  44. await this.crowdsale.send(lessThanCap)
  45. hasEnded = await this.crowdsale.hasEnded()
  46. hasEnded.should.equal(false)
  47. })
  48. it('should not be ended if just under cap', async function () {
  49. await this.crowdsale.send(cap.minus(1))
  50. let hasEnded = await this.crowdsale.hasEnded()
  51. hasEnded.should.equal(false)
  52. })
  53. it('should be ended if cap reached', async function () {
  54. await this.crowdsale.send(cap)
  55. let hasEnded = await this.crowdsale.hasEnded()
  56. hasEnded.should.equal(true)
  57. })
  58. })
  59. })