IncreasingPriceCrowdsale.test.js 4.5 KB

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