IncreasingPriceCrowdsale.test.js 5.1 KB

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