WhitelistedCrowdsale.test.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import ether from '../helpers/ether';
  2. const BigNumber = web3.BigNumber;
  3. require('chai')
  4. .use(require('chai-as-promised'))
  5. .should();
  6. const WhitelistedCrowdsale = artifacts.require('WhitelistedCrowdsaleImpl');
  7. const SimpleToken = artifacts.require('SimpleToken');
  8. contract('WhitelistedCrowdsale', function ([_, wallet, authorized, unauthorized, anotherAuthorized]) {
  9. const rate = 1;
  10. const value = ether(42);
  11. const tokenSupply = new BigNumber('1e22');
  12. describe('single user whitelisting', function () {
  13. beforeEach(async function () {
  14. this.token = await SimpleToken.new();
  15. this.crowdsale = await WhitelistedCrowdsale.new(rate, wallet, this.token.address);
  16. await this.token.transfer(this.crowdsale.address, tokenSupply);
  17. await this.crowdsale.addToWhitelist(authorized);
  18. });
  19. describe('accepting payments', function () {
  20. it('should accept payments to whitelisted (from whichever buyers)', async function () {
  21. await this.crowdsale.buyTokens(authorized, { value: value, from: authorized }).should.be.fulfilled;
  22. await this.crowdsale.buyTokens(authorized, { value: value, from: unauthorized }).should.be.fulfilled;
  23. });
  24. it('should reject payments to not whitelisted (from whichever buyers)', async function () {
  25. await this.crowdsale.send(value).should.be.rejected;
  26. await this.crowdsale.buyTokens(unauthorized, { value: value, from: unauthorized }).should.be.rejected;
  27. await this.crowdsale.buyTokens(unauthorized, { value: value, from: authorized }).should.be.rejected;
  28. });
  29. it('should reject payments to addresses removed from whitelist', async function () {
  30. await this.crowdsale.removeFromWhitelist(authorized);
  31. await this.crowdsale.buyTokens(authorized, { value: value, from: authorized }).should.be.rejected;
  32. });
  33. });
  34. describe('reporting whitelisted', function () {
  35. it('should correctly report whitelisted addresses', async function () {
  36. let isAuthorized = await this.crowdsale.whitelist(authorized);
  37. isAuthorized.should.equal(true);
  38. let isntAuthorized = await this.crowdsale.whitelist(unauthorized);
  39. isntAuthorized.should.equal(false);
  40. });
  41. });
  42. });
  43. describe('many user whitelisting', function () {
  44. beforeEach(async function () {
  45. this.token = await SimpleToken.new();
  46. this.crowdsale = await WhitelistedCrowdsale.new(rate, wallet, this.token.address);
  47. await this.token.transfer(this.crowdsale.address, tokenSupply);
  48. await this.crowdsale.addManyToWhitelist([authorized, anotherAuthorized]);
  49. });
  50. describe('accepting payments', function () {
  51. it('should accept payments to whitelisted (from whichever buyers)', async function () {
  52. await this.crowdsale.buyTokens(authorized, { value: value, from: authorized }).should.be.fulfilled;
  53. await this.crowdsale.buyTokens(authorized, { value: value, from: unauthorized }).should.be.fulfilled;
  54. await this.crowdsale.buyTokens(anotherAuthorized, { value: value, from: authorized }).should.be.fulfilled;
  55. await this.crowdsale.buyTokens(anotherAuthorized, { value: value, from: unauthorized }).should.be.fulfilled;
  56. });
  57. it('should reject payments to not whitelisted (with whichever buyers)', async function () {
  58. await this.crowdsale.send(value).should.be.rejected;
  59. await this.crowdsale.buyTokens(unauthorized, { value: value, from: unauthorized }).should.be.rejected;
  60. await this.crowdsale.buyTokens(unauthorized, { value: value, from: authorized }).should.be.rejected;
  61. });
  62. it('should reject payments to addresses removed from whitelist', async function () {
  63. await this.crowdsale.removeFromWhitelist(anotherAuthorized);
  64. await this.crowdsale.buyTokens(authorized, { value: value, from: authorized }).should.be.fulfilled;
  65. await this.crowdsale.buyTokens(anotherAuthorized, { value: value, from: authorized }).should.be.rejected;
  66. });
  67. });
  68. describe('reporting whitelisted', function () {
  69. it('should correctly report whitelisted addresses', async function () {
  70. let isAuthorized = await this.crowdsale.whitelist(authorized);
  71. isAuthorized.should.equal(true);
  72. let isAnotherAuthorized = await this.crowdsale.whitelist(anotherAuthorized);
  73. isAnotherAuthorized.should.equal(true);
  74. let isntAuthorized = await this.crowdsale.whitelist(unauthorized);
  75. isntAuthorized.should.equal(false);
  76. });
  77. });
  78. });
  79. });