2017-11-09 18:16:40 -08:00
|
|
|
const PresaleOracles = artifacts.require("PresaleOraclesMock.sol");
|
|
|
|
const BigNumber = web3.BigNumber;
|
|
|
|
require('chai')
|
|
|
|
.use(require('chai-as-promised'))
|
|
|
|
.use(require('chai-bignumber')(web3.BigNumber))
|
|
|
|
.should();
|
2017-11-09 20:31:37 -08:00
|
|
|
const REVERT_MSG = 'VM Exception while processing transaction: revert';
|
2017-11-09 18:16:40 -08:00
|
|
|
const moment = require('moment');
|
|
|
|
|
|
|
|
const ETHER = new web3.BigNumber(10).toPower(18);
|
|
|
|
|
|
|
|
function getTime() {
|
|
|
|
return Math.floor(Date.now() / 1000);
|
|
|
|
}
|
|
|
|
|
|
|
|
function latestTime() {
|
|
|
|
return web3.eth.getBlock('latest').timestamp;
|
|
|
|
}
|
|
|
|
|
|
|
|
let PRESALE_START_DATE, PRESALE_END_DATE;
|
|
|
|
contract('Presale', function(accounts) {
|
|
|
|
let presaleContract;
|
|
|
|
|
|
|
|
beforeEach(async () => {
|
|
|
|
presaleContract = await PresaleOracles.new();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('constructor should set owner', async () => {
|
|
|
|
accounts[0].should.be.equal(
|
|
|
|
await presaleContract.owner()
|
|
|
|
);
|
|
|
|
});
|
|
|
|
it('can not buy if not initialized', async () => {
|
|
|
|
await presaleContract.sendTransaction({amount: ETHER})
|
2017-11-09 20:31:37 -08:00
|
|
|
.should.be.rejectedWith(REVERT_MSG);
|
2017-11-09 18:16:40 -08:00
|
|
|
})
|
|
|
|
|
|
|
|
describe('#initilize', async () => {
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
PRESALE_START_DATE = moment('2017-12-11T16:00:00Z').unix();
|
|
|
|
PRESALE_END_DATE = moment('2017-12-18T16:00:00Z').unix();
|
|
|
|
})
|
|
|
|
it('rejects if not sent by owner', async () => {
|
2017-11-10 10:45:09 -08:00
|
|
|
await presaleContract.initialize(PRESALE_START_DATE, PRESALE_END_DATE, ETHER.mul(40000), ETHER.mul(100), accounts[1], {from: accounts[1]})
|
2017-11-09 20:31:37 -08:00
|
|
|
.should.be.rejectedWith(REVERT_MSG);
|
2017-11-09 18:16:40 -08:00
|
|
|
})
|
|
|
|
it('sets values', async () => {
|
2017-11-10 10:45:09 -08:00
|
|
|
await presaleContract.initialize(PRESALE_START_DATE, PRESALE_END_DATE, ETHER.mul(40000), ETHER.mul(100), accounts[1], {from: accounts[0]})
|
2017-11-09 18:16:40 -08:00
|
|
|
true.should.be.equal(
|
|
|
|
await presaleContract.isInitialized()
|
|
|
|
)
|
|
|
|
PRESALE_START_DATE.should.be.bignumber.equal(
|
|
|
|
await presaleContract.startTime()
|
|
|
|
)
|
|
|
|
PRESALE_END_DATE.should.be.bignumber.equal(
|
|
|
|
await presaleContract.endTime()
|
|
|
|
)
|
2017-11-10 10:45:09 -08:00
|
|
|
ETHER.mul(40000).should.be.bignumber.equal(
|
2017-11-09 18:16:40 -08:00
|
|
|
await presaleContract.cap()
|
|
|
|
)
|
|
|
|
accounts[1].should.be.equal(
|
|
|
|
await presaleContract.vault()
|
|
|
|
)
|
2017-11-10 10:45:09 -08:00
|
|
|
ETHER.mul(100).should.be.bignumber.equal(
|
|
|
|
await presaleContract.minimumContribution()
|
|
|
|
)
|
|
|
|
|
2017-11-09 18:16:40 -08:00
|
|
|
})
|
|
|
|
it('cannot initialize twice', async () => {
|
|
|
|
// require(!isInitialized);
|
2017-11-10 10:45:09 -08:00
|
|
|
await presaleContract.initialize(PRESALE_START_DATE, PRESALE_END_DATE, ETHER.mul(40000), ETHER.mul(100), accounts[1], {from: accounts[0]})
|
|
|
|
await presaleContract.initialize(PRESALE_START_DATE, PRESALE_END_DATE, ETHER.mul(40000), ETHER.mul(100), accounts[1], {from: accounts[0]})
|
2017-11-09 20:31:37 -08:00
|
|
|
.should.be.rejectedWith(REVERT_MSG);
|
2017-11-09 18:16:40 -08:00
|
|
|
})
|
|
|
|
it('startTime cannot be 0', async () => {
|
|
|
|
// require(_startTime != 0);
|
2017-11-10 10:45:09 -08:00
|
|
|
await presaleContract.initialize(0, PRESALE_END_DATE, ETHER.mul(40000), ETHER.mul(100), accounts[1], {from: accounts[1]})
|
2017-11-09 20:31:37 -08:00
|
|
|
.should.be.rejectedWith(REVERT_MSG);
|
2017-11-09 18:16:40 -08:00
|
|
|
})
|
|
|
|
it('endTime cannot be 0', async () => {
|
|
|
|
// require(_endTime != 0);
|
2017-11-10 10:45:09 -08:00
|
|
|
await presaleContract.initialize(PRESALE_START_DATE, 0, ETHER.mul(40000), ETHER.mul(100), accounts[1], {from: accounts[1]})
|
2017-11-09 20:31:37 -08:00
|
|
|
.should.be.rejectedWith(REVERT_MSG);
|
2017-11-09 18:16:40 -08:00
|
|
|
})
|
|
|
|
it('endTime cannot be less than startTime', async () => {
|
|
|
|
// require(_endTime > _startTime);
|
2017-11-10 10:45:09 -08:00
|
|
|
await presaleContract.initialize(PRESALE_END_DATE, PRESALE_START_DATE, ETHER.mul(40000), ETHER.mul(100), accounts[1], {from: accounts[1]})
|
2017-11-09 20:31:37 -08:00
|
|
|
.should.be.rejectedWith(REVERT_MSG);
|
2017-11-09 18:16:40 -08:00
|
|
|
})
|
|
|
|
it('cap cannot be 0', async () => {
|
|
|
|
// require(_cap != 0);
|
2017-11-10 10:45:09 -08:00
|
|
|
await presaleContract.initialize(PRESALE_START_DATE, PRESALE_END_DATE, 0, ETHER.mul(100), accounts[1], {from: accounts[1]})
|
2017-11-09 20:31:37 -08:00
|
|
|
.should.be.rejectedWith(REVERT_MSG);
|
2017-11-09 18:16:40 -08:00
|
|
|
})
|
|
|
|
it('vault cannot be 0x0', async () => {
|
|
|
|
// require(_vault != 0x0);
|
2017-11-10 10:45:09 -08:00
|
|
|
await presaleContract.initialize(PRESALE_START_DATE, PRESALE_END_DATE, ETHER.mul(40000), ETHER.mul(100), '0x0', {from: accounts[1]})
|
|
|
|
.should.be.rejectedWith(REVERT_MSG);
|
|
|
|
})
|
|
|
|
it('minimumContribution cannot be 0', async () => {
|
|
|
|
// require(_vault != 0x0);
|
|
|
|
await presaleContract.initialize(PRESALE_START_DATE, PRESALE_END_DATE, ETHER.mul(40000), 0, accounts[1], {from: accounts[1]})
|
2017-11-09 20:31:37 -08:00
|
|
|
.should.be.rejectedWith(REVERT_MSG);
|
2017-11-09 18:16:40 -08:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('#buy', async () => {
|
|
|
|
|
|
|
|
beforeEach(async () => {
|
|
|
|
PRESALE_START_DATE = moment('2017-12-11T16:00:00Z').unix();
|
|
|
|
PRESALE_END_DATE = moment('2017-12-18T16:00:00Z').unix();
|
2017-11-10 10:45:09 -08:00
|
|
|
await presaleContract.initialize(PRESALE_START_DATE, PRESALE_END_DATE, ETHER.mul(40000), ETHER.mul(100), accounts[1], {from: accounts[0]})
|
2017-11-09 18:16:40 -08:00
|
|
|
})
|
|
|
|
it('cannot buy if not value is 0', async () => {
|
|
|
|
// require(msg.value > 0);
|
|
|
|
await presaleContract.setTime(PRESALE_START_DATE);
|
|
|
|
await presaleContract.sendTransaction({value: 0})
|
2017-11-09 20:31:37 -08:00
|
|
|
.should.be.rejectedWith(REVERT_MSG);
|
2017-11-09 18:16:40 -08:00
|
|
|
})
|
|
|
|
|
2017-11-10 10:45:09 -08:00
|
|
|
it('cannot buy if not value is less than minimum', async () => {
|
|
|
|
// require(msg.value > 0);
|
|
|
|
await presaleContract.setTime(PRESALE_START_DATE);
|
|
|
|
await presaleContract.sendTransaction({value: ETHER.mul(99)})
|
|
|
|
.should.be.rejectedWith(REVERT_MSG);
|
2017-11-09 18:16:40 -08:00
|
|
|
})
|
|
|
|
|
|
|
|
it('can not buy if time is not within startTime&endTime', async ()=> {
|
|
|
|
// require(now >= startTime && now <= endTime);
|
|
|
|
await presaleContract.setTime(PRESALE_START_DATE - 1);
|
2017-11-10 10:45:09 -08:00
|
|
|
await presaleContract.sendTransaction({value: ETHER.mul(100)})
|
2017-11-09 20:31:37 -08:00
|
|
|
.should.be.rejectedWith(REVERT_MSG);
|
2017-11-09 18:16:40 -08:00
|
|
|
await presaleContract.setTime(PRESALE_END_DATE + 1);
|
2017-11-10 10:45:09 -08:00
|
|
|
await presaleContract.sendTransaction({value: ETHER.mul(100)})
|
2017-11-09 20:31:37 -08:00
|
|
|
.should.be.rejectedWith(REVERT_MSG);
|
2017-11-09 18:16:40 -08:00
|
|
|
})
|
|
|
|
|
|
|
|
it('can not buy more than cap', async () => {
|
2017-11-10 10:45:09 -08:00
|
|
|
// bool withinCap = totalInvestedInWei.add(msg.value) <= cap;
|
2017-11-09 18:16:40 -08:00
|
|
|
await presaleContract.setTime(PRESALE_START_DATE);
|
2017-11-10 10:45:09 -08:00
|
|
|
await presaleContract.sendTransaction({value: ETHER.mul(40000).add(1)})
|
2017-11-09 20:31:37 -08:00
|
|
|
.should.be.rejectedWith(REVERT_MSG);
|
2017-11-09 18:16:40 -08:00
|
|
|
})
|
|
|
|
|
|
|
|
it('happy path', async () => {
|
|
|
|
// investorBalances[investor] += msg.value;
|
|
|
|
// totalInvestedInWei += msg.value;
|
|
|
|
// forwardFunds(msg.value);
|
|
|
|
const vault = accounts[1];
|
|
|
|
const preVaultBalance = await web3.eth.getBalance(vault);
|
|
|
|
await presaleContract.setTime(PRESALE_START_DATE);
|
2017-11-10 10:45:09 -08:00
|
|
|
await presaleContract.sendTransaction({value: ETHER.mul(100)});
|
|
|
|
ETHER.mul(100).should.be.bignumber.equal(
|
2017-11-09 18:16:40 -08:00
|
|
|
await presaleContract.investorBalances(accounts[0])
|
|
|
|
)
|
2017-11-10 10:45:09 -08:00
|
|
|
ETHER.mul(100).should.be.bignumber.equal(
|
2017-11-09 18:16:40 -08:00
|
|
|
await presaleContract.totalInvestedInWei()
|
|
|
|
)
|
2017-11-10 10:45:09 -08:00
|
|
|
preVaultBalance.add(ETHER.mul(100)).should.be.bignumber.equal(
|
2017-11-09 18:16:40 -08:00
|
|
|
await web3.eth.getBalance(vault)
|
|
|
|
)
|
2017-11-10 10:45:09 -08:00
|
|
|
await presaleContract.sendTransaction({value: ETHER.mul(2)});
|
2017-11-09 18:16:40 -08:00
|
|
|
|
2017-11-10 10:45:09 -08:00
|
|
|
ETHER.mul(100).add(ETHER.mul(2)).should.be.bignumber.equal(
|
2017-11-09 18:16:40 -08:00
|
|
|
await presaleContract.investorBalances(accounts[0])
|
|
|
|
)
|
2017-11-10 10:45:09 -08:00
|
|
|
ETHER.mul(100).add(ETHER.mul(2)).should.be.bignumber.equal(
|
2017-11-09 18:16:40 -08:00
|
|
|
await presaleContract.totalInvestedInWei()
|
|
|
|
)
|
2017-11-10 10:45:09 -08:00
|
|
|
preVaultBalance.add(ETHER.mul(100).add(ETHER.mul(2))).should.be.bignumber.equal(
|
2017-11-09 18:16:40 -08:00
|
|
|
await web3.eth.getBalance(vault)
|
|
|
|
)
|
|
|
|
|
2017-11-10 10:45:09 -08:00
|
|
|
await presaleContract.sendTransaction({value: ETHER.mul(40000-100-2).add(1)})
|
|
|
|
.should.be.rejectedWith(REVERT_MSG);
|
2017-11-09 18:16:40 -08:00
|
|
|
})
|
|
|
|
})
|
2017-11-10 10:45:09 -08:00
|
|
|
|
|
|
|
|
2017-11-09 18:16:40 -08:00
|
|
|
});
|