IndividuallyCappedCrowdsale.test.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. const { ether } = require('../helpers/ether');
  2. const { expectThrow } = require('../helpers/expectThrow');
  3. const { EVMRevert } = require('../helpers/EVMRevert');
  4. const BigNumber = web3.BigNumber;
  5. require('chai')
  6. .use(require('chai-bignumber')(BigNumber))
  7. .should();
  8. const CappedCrowdsale = artifacts.require('IndividuallyCappedCrowdsaleImpl');
  9. const SimpleToken = artifacts.require('SimpleToken');
  10. contract('IndividuallyCappedCrowdsale', function ([_, wallet, alice, bob, charlie]) {
  11. const rate = new BigNumber(1);
  12. const capAlice = ether(10);
  13. const capBob = ether(2);
  14. const lessThanCapAlice = ether(6);
  15. const lessThanCapBoth = ether(1);
  16. const tokenSupply = new BigNumber('1e22');
  17. describe('individual capping', function () {
  18. beforeEach(async function () {
  19. this.token = await SimpleToken.new();
  20. this.crowdsale = await CappedCrowdsale.new(rate, wallet, this.token.address);
  21. await this.crowdsale.setCap(alice, capAlice);
  22. await this.crowdsale.setCap(bob, capBob);
  23. await this.token.transfer(this.crowdsale.address, tokenSupply);
  24. });
  25. describe('accepting payments', function () {
  26. it('should accept payments within cap', async function () {
  27. await this.crowdsale.buyTokens(alice, { value: lessThanCapAlice });
  28. await this.crowdsale.buyTokens(bob, { value: lessThanCapBoth });
  29. });
  30. it('should reject payments outside cap', async function () {
  31. await this.crowdsale.buyTokens(alice, { value: capAlice });
  32. await expectThrow(this.crowdsale.buyTokens(alice, { value: 1 }), EVMRevert);
  33. });
  34. it('should reject payments that exceed cap', async function () {
  35. await expectThrow(this.crowdsale.buyTokens(alice, { value: capAlice.plus(1) }), EVMRevert);
  36. await expectThrow(this.crowdsale.buyTokens(bob, { value: capBob.plus(1) }), EVMRevert);
  37. });
  38. it('should manage independent caps', async function () {
  39. await this.crowdsale.buyTokens(alice, { value: lessThanCapAlice });
  40. await expectThrow(this.crowdsale.buyTokens(bob, { value: lessThanCapAlice }), EVMRevert);
  41. });
  42. it('should default to a cap of zero', async function () {
  43. await expectThrow(this.crowdsale.buyTokens(charlie, { value: lessThanCapBoth }), EVMRevert);
  44. });
  45. });
  46. describe('reporting state', function () {
  47. it('should report correct cap', async function () {
  48. (await this.crowdsale.getCap(alice)).should.be.bignumber.equal(capAlice);
  49. });
  50. it('should report actual contribution', async function () {
  51. await this.crowdsale.buyTokens(alice, { value: lessThanCapAlice });
  52. (await this.crowdsale.getContribution(alice)).should.be.bignumber.equal(lessThanCapAlice);
  53. });
  54. });
  55. });
  56. });