IncreasingPriceCrowdsale.test.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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('at start', async function () {
  49. await increaseTimeTo(this.startTime);
  50. await this.crowdsale.buyTokens(investor, { value, from: purchaser });
  51. (await this.token.balanceOf(investor)).should.be.bignumber.equal(value.mul(initialRate));
  52. });
  53. it('at time 150', async function () {
  54. await increaseTimeTo(this.startTime + 150);
  55. await this.crowdsale.buyTokens(investor, { value, from: purchaser });
  56. (await this.token.balanceOf(investor)).should.be.bignumber.equal(value.mul(rateAtTime150));
  57. });
  58. it('at time 300', async function () {
  59. await increaseTimeTo(this.startTime + 300);
  60. await this.crowdsale.buyTokens(investor, { value, from: purchaser });
  61. (await this.token.balanceOf(investor)).should.be.bignumber.equal(value.mul(rateAtTime300));
  62. });
  63. it('at time 1500', async function () {
  64. await increaseTimeTo(this.startTime + 1500);
  65. await this.crowdsale.buyTokens(investor, { value, from: purchaser });
  66. (await this.token.balanceOf(investor)).should.be.bignumber.equal(value.mul(rateAtTime1500));
  67. });
  68. it('at time 30', async function () {
  69. await increaseTimeTo(this.startTime + 30);
  70. await this.crowdsale.buyTokens(investor, { value, from: purchaser });
  71. (await this.token.balanceOf(investor)).should.be.bignumber.equal(value.mul(rateAtTime30));
  72. });
  73. it('at time 150000', async function () {
  74. await increaseTimeTo(this.startTime + 150000);
  75. await this.crowdsale.buyTokens(investor, { value, from: purchaser });
  76. (await this.token.balanceOf(investor)).should.be.bignumber.equal(value.mul(rateAtTime150000));
  77. });
  78. it('at time 450000', async function () {
  79. await increaseTimeTo(this.startTime + 450000);
  80. await this.crowdsale.buyTokens(investor, { value, from: purchaser });
  81. (await this.token.balanceOf(investor)).should.be.bignumber.equal(value.mul(rateAtTime450000));
  82. });
  83. });
  84. });
  85. });