IncreasingPriceCrowdsale.test.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. const { ether } = require('../helpers/ether');
  2. const { advanceBlock } = require('../helpers/advanceToBlock');
  3. const time = require('../helpers/time');
  4. const shouldFail = require('../helpers/shouldFail');
  5. const BigNumber = web3.BigNumber;
  6. require('chai')
  7. .use(require('chai-bignumber')(BigNumber))
  8. .should();
  9. const IncreasingPriceCrowdsaleImpl = artifacts.require('IncreasingPriceCrowdsaleImpl');
  10. const SimpleToken = artifacts.require('SimpleToken');
  11. contract('IncreasingPriceCrowdsale', function ([_, investor, wallet, purchaser]) {
  12. const value = ether(1);
  13. const tokenSupply = new BigNumber('1e22');
  14. describe('rate during crowdsale should change at a fixed step every block', async function () {
  15. const initialRate = new BigNumber(9166);
  16. const finalRate = new BigNumber(5500);
  17. const rateAtTime150 = new BigNumber(9166);
  18. const rateAtTime300 = new BigNumber(9165);
  19. const rateAtTime1500 = new BigNumber(9157);
  20. const rateAtTime30 = new BigNumber(9166);
  21. const rateAtTime150000 = new BigNumber(8257);
  22. const rateAtTime450000 = new BigNumber(6439);
  23. beforeEach(async function () {
  24. await advanceBlock();
  25. this.startTime = (await time.latest()) + time.duration.weeks(1);
  26. this.closingTime = this.startTime + time.duration.weeks(1);
  27. this.afterClosingTime = this.closingTime + time.duration.seconds(1);
  28. this.token = await SimpleToken.new();
  29. });
  30. it('rejects a final rate larger than the initial rate', async function () {
  31. await shouldFail.reverting(IncreasingPriceCrowdsaleImpl.new(
  32. this.startTime, this.closingTime, wallet, this.token.address, initialRate, initialRate.plus(1)
  33. ));
  34. });
  35. it('rejects a final rate of zero', async function () {
  36. await shouldFail.reverting(IncreasingPriceCrowdsaleImpl.new(
  37. this.startTime, this.closingTime, wallet, this.token.address, initialRate, 0
  38. ));
  39. });
  40. context('with crowdsale', function () {
  41. beforeEach(async function () {
  42. this.crowdsale = await IncreasingPriceCrowdsaleImpl.new(
  43. this.startTime, this.closingTime, wallet, this.token.address, initialRate, finalRate
  44. );
  45. await this.token.transfer(this.crowdsale.address, tokenSupply);
  46. });
  47. it('should have initial and final rate', async function () {
  48. (await this.crowdsale.initialRate()).should.be.bignumber.equal(initialRate);
  49. (await this.crowdsale.finalRate()).should.be.bignumber.equal(finalRate);
  50. });
  51. it('at start', async function () {
  52. await time.increaseTo(this.startTime);
  53. await this.crowdsale.buyTokens(investor, { value, from: purchaser });
  54. (await this.token.balanceOf(investor)).should.be.bignumber.equal(value.mul(initialRate));
  55. });
  56. it('at time 150', async function () {
  57. await time.increaseTo(this.startTime + 150);
  58. await this.crowdsale.buyTokens(investor, { value, from: purchaser });
  59. (await this.token.balanceOf(investor)).should.be.bignumber.equal(value.mul(rateAtTime150));
  60. });
  61. it('at time 300', async function () {
  62. await time.increaseTo(this.startTime + 300);
  63. await this.crowdsale.buyTokens(investor, { value, from: purchaser });
  64. (await this.token.balanceOf(investor)).should.be.bignumber.equal(value.mul(rateAtTime300));
  65. });
  66. it('at time 1500', async function () {
  67. await time.increaseTo(this.startTime + 1500);
  68. await this.crowdsale.buyTokens(investor, { value, from: purchaser });
  69. (await this.token.balanceOf(investor)).should.be.bignumber.equal(value.mul(rateAtTime1500));
  70. });
  71. it('at time 30', async function () {
  72. await time.increaseTo(this.startTime + 30);
  73. await this.crowdsale.buyTokens(investor, { value, from: purchaser });
  74. (await this.token.balanceOf(investor)).should.be.bignumber.equal(value.mul(rateAtTime30));
  75. });
  76. it('at time 150000', async function () {
  77. await time.increaseTo(this.startTime + 150000);
  78. await this.crowdsale.buyTokens(investor, { value, from: purchaser });
  79. (await this.token.balanceOf(investor)).should.be.bignumber.equal(value.mul(rateAtTime150000));
  80. });
  81. it('at time 450000', async function () {
  82. await time.increaseTo(this.startTime + 450000);
  83. await this.crowdsale.buyTokens(investor, { value, from: purchaser });
  84. (await this.token.balanceOf(investor)).should.be.bignumber.equal(value.mul(rateAtTime450000));
  85. });
  86. });
  87. });
  88. });