IncreasingPriceCrowdsale.test.js 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 BigNumber = web3.BigNumber;
  6. require('chai')
  7. .use(require('chai-bignumber')(BigNumber))
  8. .should();
  9. const IncreasingPriceCrowdsale = artifacts.require('IncreasingPriceCrowdsaleImpl');
  10. const SimpleToken = artifacts.require('SimpleToken');
  11. contract('IncreasingPriceCrowdsale', function ([_, investor, wallet, purchaser]) {
  12. const value = ether(1);
  13. const tokenSupply = new BigNumber('1e22');
  14. describe('rate during crowdsale should change at a fixed step every block', async function () {
  15. let balance;
  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. this.crowdsale = await IncreasingPriceCrowdsale.new(
  31. this.startTime, this.closingTime, wallet, this.token.address, initialRate, finalRate
  32. );
  33. await this.token.transfer(this.crowdsale.address, tokenSupply);
  34. });
  35. it('at start', async function () {
  36. await increaseTimeTo(this.startTime);
  37. await this.crowdsale.buyTokens(investor, { value, from: purchaser });
  38. balance = await this.token.balanceOf(investor);
  39. balance.should.be.bignumber.equal(value.mul(initialRate));
  40. });
  41. it('at time 150', async function () {
  42. await increaseTimeTo(this.startTime + 150);
  43. await this.crowdsale.buyTokens(investor, { value, from: purchaser });
  44. balance = await this.token.balanceOf(investor);
  45. balance.should.be.bignumber.equal(value.mul(rateAtTime150));
  46. });
  47. it('at time 300', async function () {
  48. await increaseTimeTo(this.startTime + 300);
  49. await this.crowdsale.buyTokens(investor, { value, from: purchaser });
  50. balance = await this.token.balanceOf(investor);
  51. balance.should.be.bignumber.equal(value.mul(rateAtTime300));
  52. });
  53. it('at time 1500', async function () {
  54. await increaseTimeTo(this.startTime + 1500);
  55. await this.crowdsale.buyTokens(investor, { value, from: purchaser });
  56. balance = await this.token.balanceOf(investor);
  57. balance.should.be.bignumber.equal(value.mul(rateAtTime1500));
  58. });
  59. it('at time 30', async function () {
  60. await increaseTimeTo(this.startTime + 30);
  61. await this.crowdsale.buyTokens(investor, { value, from: purchaser });
  62. balance = await this.token.balanceOf(investor);
  63. balance.should.be.bignumber.equal(value.mul(rateAtTime30));
  64. });
  65. it('at time 150000', async function () {
  66. await increaseTimeTo(this.startTime + 150000);
  67. await this.crowdsale.buyTokens(investor, { value, from: purchaser });
  68. balance = await this.token.balanceOf(investor);
  69. balance.should.be.bignumber.equal(value.mul(rateAtTime150000));
  70. });
  71. it('at time 450000', async function () {
  72. await increaseTimeTo(this.startTime + 450000);
  73. await this.crowdsale.buyTokens(investor, { value, from: purchaser });
  74. balance = await this.token.balanceOf(investor);
  75. balance.should.be.bignumber.equal(value.mul(rateAtTime450000));
  76. });
  77. });
  78. });