|
| 1 | +var LifCrowdsale = artifacts.require('./LifCrowdsale.sol'), |
| 2 | + LifToken = artifacts.require('./LifToken.sol'), |
| 3 | + TGEDeployer = artifacts.require('./deploy/TGEDeployer.sol'); |
| 4 | + |
| 5 | +let help = require('../helpers'); |
| 6 | + |
| 7 | +var BigNumber = web3.BigNumber; |
| 8 | + |
| 9 | +require('chai') |
| 10 | + .use(require('chai-bignumber')(BigNumber)) |
| 11 | + .should(); |
| 12 | + |
| 13 | +var { duration } = require('../helpers/increaseTime'); |
| 14 | +const _ = require('lodash'); |
| 15 | + |
| 16 | +const TGEDistribution = require('./TGEDistribution'); |
| 17 | + |
| 18 | +contract('TGE Deployer', function ([deployAddress, foundationWallet, foundersWallet]) { |
| 19 | + it('Deploy a TGE correctly', async function () { |
| 20 | + const startTimestamp = new Date('Sun, 28 Jan 2018 8:0:00 GMT').getTime() / 1000; |
| 21 | + const end1Timestamp = new Date('Sun, 28 Jan 2018 9:0:00 GMT').getTime() / 1000; |
| 22 | + const end2Timestamp = new Date('Sun, 28 Jan 2018 10:0:00 GMT').getTime() / 1000; |
| 23 | + const rate1 = 1000; |
| 24 | + const rate2 = 900; |
| 25 | + const setWeiLockSeconds = duration.hours(1); |
| 26 | + var totalSupply = new BigNumber(0); |
| 27 | + const weiPerUSDinTGE = web3.toWei(1 / 1000); |
| 28 | + |
| 29 | + const deployer = await TGEDeployer.new( |
| 30 | + startTimestamp, end1Timestamp, end2Timestamp, rate1, |
| 31 | + rate2, setWeiLockSeconds, foundationWallet, foundersWallet, |
| 32 | + { from: deployAddress } |
| 33 | + ); |
| 34 | + |
| 35 | + const crowdsale = LifCrowdsale.at(await deployer.crowdsale()); |
| 36 | + const token = LifToken.at(await crowdsale.token()); |
| 37 | + |
| 38 | + help.debug('Data to create Deployer contract:'); |
| 39 | + help.debug(deployer.deployedBytecode); |
| 40 | + help.debug('--------------------------------------------------'); |
| 41 | + |
| 42 | + // Check values |
| 43 | + assert.equal(startTimestamp, parseInt(await crowdsale.startTimestamp.call())); |
| 44 | + assert.equal(end1Timestamp, parseInt(await crowdsale.end1Timestamp.call())); |
| 45 | + assert.equal(end2Timestamp, parseInt(await crowdsale.end2Timestamp.call())); |
| 46 | + assert.equal(rate1, parseInt(await crowdsale.rate1.call())); |
| 47 | + assert.equal(rate2, parseInt(await crowdsale.rate2.call())); |
| 48 | + assert.equal(foundationWallet, parseInt(await crowdsale.foundationWallet.call())); |
| 49 | + assert.equal(foundersWallet, parseInt(await crowdsale.foundersWallet.call())); |
| 50 | + |
| 51 | + var processStage = async function (stage) { |
| 52 | + // Check right amount of contributos and values |
| 53 | + assert.equal(stage.contributors.length, stage.values.length); |
| 54 | + var stageETH = new BigNumber(0); |
| 55 | + |
| 56 | + // Parse ETH to wei |
| 57 | + stage.values.map(function (value, i) { |
| 58 | + stageETH = stageETH.add(stage.values[i]); |
| 59 | + stage.values[i] = web3.toWei(stage.values[i]); |
| 60 | + }); |
| 61 | + |
| 62 | + // Add TGE stage |
| 63 | + const contributorsChunks = _.chunk(stage.contributors, 150); |
| 64 | + const valuesChunks = _.chunk(stage.values, 150); |
| 65 | + var txs = []; |
| 66 | + for (var i = 0; i < contributorsChunks.length; i++) { |
| 67 | + const data = await deployer.contract.addPresaleTokens.getData( |
| 68 | + contributorsChunks[i], valuesChunks[i], stage.rate |
| 69 | + ); |
| 70 | + await deployer.addPresaleTokens( |
| 71 | + contributorsChunks[i], valuesChunks[i], stage.rate, |
| 72 | + { from: deployAddress } |
| 73 | + ); |
| 74 | + txs.push(data); |
| 75 | + } |
| 76 | + |
| 77 | + // Calculate tokens and check total supply |
| 78 | + const stageTokens = new BigNumber(stageETH).mul(stage.rate); |
| 79 | + totalSupply = totalSupply.add(stageTokens); |
| 80 | + help.debug('TXs for stage', stage.name); |
| 81 | + txs.map(function (tx, i) { help.debug('TX [', i, ']', tx); }); |
| 82 | + help.debug('--------------------------------------------------'); |
| 83 | + totalSupply.should.be.bignumber |
| 84 | + .equal(help.lifWei2Lif(await token.totalSupply()), 2); |
| 85 | + }; |
| 86 | + |
| 87 | + await processStage(TGEDistribution[0]); |
| 88 | + await processStage(TGEDistribution[1]); |
| 89 | + await processStage(TGEDistribution[2]); |
| 90 | + await processStage(TGEDistribution[3]); |
| 91 | + await processStage(TGEDistribution[4]); |
| 92 | + |
| 93 | + const finalizeData = await deployer.contract.finish.getData(weiPerUSDinTGE); |
| 94 | + |
| 95 | + await deployer.finish(weiPerUSDinTGE, { from: deployAddress }); |
| 96 | + |
| 97 | + help.debug('Data to finalize Deployer:'); |
| 98 | + help.debug(finalizeData); |
| 99 | + help.debug('--------------------------------------------------'); |
| 100 | + |
| 101 | + assert.equal(foundationWallet, parseInt(await crowdsale.owner.call())); |
| 102 | + assert.equal(weiPerUSDinTGE, parseInt(await crowdsale.weiPerUSDinTGE.call())); |
| 103 | + |
| 104 | + // Check final total supply |
| 105 | + totalSupply.should.be.bignumber |
| 106 | + .equal(help.lifWei2Lif(await token.totalSupply()), 2); |
| 107 | + }); |
| 108 | +}); |
0 commit comments