IncreasingPriceCrowdsale.test.js 5.2 KB

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