IncreasingPriceCrowdsale.test.js 3.5 KB

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