IncreasingPriceCrowdsale.test.js 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import ether from '../helpers/ether';
  2. import { advanceBlock } from '../helpers/advanceToBlock';
  3. import { increaseTimeTo, duration } from '../helpers/increaseTime';
  4. import latestTime from '../helpers/latestTime';
  5. const BigNumber = web3.BigNumber;
  6. require('chai')
  7. .use(require('chai-as-promised'))
  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. let balance;
  17. const initialRate = new BigNumber(9166);
  18. const finalRate = new BigNumber(5500);
  19. const rateAtTime150 = new BigNumber(9166);
  20. const rateAtTime300 = new BigNumber(9165);
  21. const rateAtTime1500 = new BigNumber(9157);
  22. const rateAtTime30 = new BigNumber(9166);
  23. const rateAtTime150000 = new BigNumber(8257);
  24. const rateAtTime450000 = new BigNumber(6439);
  25. beforeEach(async function () {
  26. await advanceBlock();
  27. this.startTime = latestTime() + duration.weeks(1);
  28. this.closingTime = this.startTime + duration.weeks(1);
  29. this.afterClosingTime = this.closingTime + duration.seconds(1);
  30. this.token = await SimpleToken.new();
  31. this.crowdsale = await IncreasingPriceCrowdsale.new(
  32. this.startTime, this.closingTime, wallet, this.token.address, initialRate, finalRate
  33. );
  34. await this.token.transfer(this.crowdsale.address, tokenSupply);
  35. });
  36. it('at start', async function () {
  37. await increaseTimeTo(this.startTime);
  38. await this.crowdsale.buyTokens(investor, { value, from: purchaser });
  39. balance = await this.token.balanceOf(investor);
  40. balance.should.be.bignumber.equal(value.mul(initialRate));
  41. });
  42. it('at time 150', async function () {
  43. await increaseTimeTo(this.startTime + 150);
  44. await this.crowdsale.buyTokens(investor, { value, from: purchaser });
  45. balance = await this.token.balanceOf(investor);
  46. balance.should.be.bignumber.equal(value.mul(rateAtTime150));
  47. });
  48. it('at time 300', async function () {
  49. await increaseTimeTo(this.startTime + 300);
  50. await this.crowdsale.buyTokens(investor, { value, from: purchaser });
  51. balance = await this.token.balanceOf(investor);
  52. balance.should.be.bignumber.equal(value.mul(rateAtTime300));
  53. });
  54. it('at time 1500', async function () {
  55. await increaseTimeTo(this.startTime + 1500);
  56. await this.crowdsale.buyTokens(investor, { value, from: purchaser });
  57. balance = await this.token.balanceOf(investor);
  58. balance.should.be.bignumber.equal(value.mul(rateAtTime1500));
  59. });
  60. it('at time 30', async function () {
  61. await increaseTimeTo(this.startTime + 30);
  62. await this.crowdsale.buyTokens(investor, { value, from: purchaser });
  63. balance = await this.token.balanceOf(investor);
  64. balance.should.be.bignumber.equal(value.mul(rateAtTime30));
  65. });
  66. it('at time 150000', async function () {
  67. await increaseTimeTo(this.startTime + 150000);
  68. await this.crowdsale.buyTokens(investor, { value, from: purchaser });
  69. balance = await this.token.balanceOf(investor);
  70. balance.should.be.bignumber.equal(value.mul(rateAtTime150000));
  71. });
  72. it('at time 450000', async function () {
  73. await increaseTimeTo(this.startTime + 450000);
  74. await this.crowdsale.buyTokens(investor, { value, from: purchaser });
  75. balance = await this.token.balanceOf(investor);
  76. balance.should.be.bignumber.equal(value.mul(rateAtTime450000));
  77. });
  78. });
  79. });