123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- import ether from '../helpers/ether';
- const BigNumber = web3.BigNumber;
- require('chai')
- .use(require('chai-as-promised'))
- .should();
- const WhitelistedCrowdsale = artifacts.require('WhitelistedCrowdsaleImpl');
- const SimpleToken = artifacts.require('SimpleToken');
- contract('WhitelistedCrowdsale', function ([_, wallet, authorized, unauthorized, anotherAuthorized]) {
- const rate = 1;
- const value = ether(42);
- const tokenSupply = new BigNumber('1e22');
- describe('single user whitelisting', function () {
- beforeEach(async function () {
- this.token = await SimpleToken.new();
- this.crowdsale = await WhitelistedCrowdsale.new(rate, wallet, this.token.address);
- await this.token.transfer(this.crowdsale.address, tokenSupply);
- await this.crowdsale.addToWhitelist(authorized);
- });
- describe('accepting payments', function () {
- it('should accept payments to whitelisted (from whichever buyers)', async function () {
- await this.crowdsale.buyTokens(authorized, { value: value, from: authorized }).should.be.fulfilled;
- await this.crowdsale.buyTokens(authorized, { value: value, from: unauthorized }).should.be.fulfilled;
- });
- it('should reject payments to not whitelisted (from whichever buyers)', async function () {
- await this.crowdsale.send(value).should.be.rejected;
- await this.crowdsale.buyTokens(unauthorized, { value: value, from: unauthorized }).should.be.rejected;
- await this.crowdsale.buyTokens(unauthorized, { value: value, from: authorized }).should.be.rejected;
- });
- it('should reject payments to addresses removed from whitelist', async function () {
- await this.crowdsale.removeFromWhitelist(authorized);
- await this.crowdsale.buyTokens(authorized, { value: value, from: authorized }).should.be.rejected;
- });
- });
- describe('reporting whitelisted', function () {
- it('should correctly report whitelisted addresses', async function () {
- let isAuthorized = await this.crowdsale.whitelist(authorized);
- isAuthorized.should.equal(true);
- let isntAuthorized = await this.crowdsale.whitelist(unauthorized);
- isntAuthorized.should.equal(false);
- });
- });
- });
- describe('many user whitelisting', function () {
- beforeEach(async function () {
- this.token = await SimpleToken.new();
- this.crowdsale = await WhitelistedCrowdsale.new(rate, wallet, this.token.address);
- await this.token.transfer(this.crowdsale.address, tokenSupply);
- await this.crowdsale.addManyToWhitelist([authorized, anotherAuthorized]);
- });
- describe('accepting payments', function () {
- it('should accept payments to whitelisted (from whichever buyers)', async function () {
- await this.crowdsale.buyTokens(authorized, { value: value, from: authorized }).should.be.fulfilled;
- await this.crowdsale.buyTokens(authorized, { value: value, from: unauthorized }).should.be.fulfilled;
- await this.crowdsale.buyTokens(anotherAuthorized, { value: value, from: authorized }).should.be.fulfilled;
- await this.crowdsale.buyTokens(anotherAuthorized, { value: value, from: unauthorized }).should.be.fulfilled;
- });
- it('should reject payments to not whitelisted (with whichever buyers)', async function () {
- await this.crowdsale.send(value).should.be.rejected;
- await this.crowdsale.buyTokens(unauthorized, { value: value, from: unauthorized }).should.be.rejected;
- await this.crowdsale.buyTokens(unauthorized, { value: value, from: authorized }).should.be.rejected;
- });
- it('should reject payments to addresses removed from whitelist', async function () {
- await this.crowdsale.removeFromWhitelist(anotherAuthorized);
- await this.crowdsale.buyTokens(authorized, { value: value, from: authorized }).should.be.fulfilled;
- await this.crowdsale.buyTokens(anotherAuthorized, { value: value, from: authorized }).should.be.rejected;
- });
- });
- describe('reporting whitelisted', function () {
- it('should correctly report whitelisted addresses', async function () {
- let isAuthorized = await this.crowdsale.whitelist(authorized);
- isAuthorized.should.equal(true);
- let isAnotherAuthorized = await this.crowdsale.whitelist(anotherAuthorized);
- isAnotherAuthorized.should.equal(true);
- let isntAuthorized = await this.crowdsale.whitelist(unauthorized);
- isntAuthorized.should.equal(false);
- });
- });
- });
- });
|