Skip to content

Commit ec968a5

Browse files
committed
Fix test command: no MVM is created when funds are exactly the soft cap amount
Only when there is excess over the soft cap the MVM is created
1 parent 86d8429 commit ec968a5

File tree

3 files changed

+70
-3
lines changed

3 files changed

+70
-3
lines changed

test/Crowdsale.js

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var LifCrowdsale = artifacts.require('./LifCrowdsale.sol'),
2-
LifToken = artifacts.require('./LifToken.sol');
2+
LifToken = artifacts.require('./LifToken.sol'),
3+
LifMarketValidationMechanism = artifacts.require('./LifMarketValidationMechanism.sol');
34

45
let help = require('./helpers');
56

@@ -400,4 +401,56 @@ contract('LifToken Crowdsale', function(accounts) {
400401
}
401402
});
402403

404+
/// finalize
405+
it('finalize creates the MVM', async function() {
406+
const start = latestTime() + defaultTimeDelta,
407+
end1 = start + defaultTimeDelta,
408+
end2 = end1 + defaultTimeDelta,
409+
beneficiary = accounts[6],
410+
crowdsale = await createCrowdsale({
411+
start: start,
412+
end1: end1,
413+
end2: end2
414+
}),
415+
weiPerUsd = 10000,
416+
weiAmount = 10000001 * weiPerUsd; // exactly USD 1 more than the minimum for the MVM
417+
418+
await crowdsale.setWeiPerUSDinTGE(weiPerUsd);
419+
await increaseTimeTestRPCTo(start + 2);
420+
await crowdsale.buyTokens(beneficiary, {value: weiAmount, from: accounts[5]});
421+
422+
await increaseTimeTestRPCTo(end2 + 2);
423+
await crowdsale.finalize();
424+
425+
const MVMAddress = await crowdsale.MVM.call();
426+
assert(MVMAddress !== help.zeroAddress);
427+
428+
const MVM = LifMarketValidationMechanism.at(MVMAddress),
429+
MVMInitialWei = await MVM.initialWei();
430+
MVMInitialWei.should.be.bignumber.equal(1 * weiPerUsd);
431+
});
432+
433+
it('finalize not over soft cap does not create the MVM', async function() {
434+
const start = latestTime() + defaultTimeDelta,
435+
end1 = start + defaultTimeDelta,
436+
end2 = end1 + defaultTimeDelta,
437+
beneficiary = accounts[6],
438+
crowdsale = await createCrowdsale({
439+
start: start,
440+
end1: end1,
441+
end2: end2
442+
}),
443+
weiPerUsd = 10000,
444+
weiAmount = 10000000 * weiPerUsd; // exactly the soft cap
445+
446+
await crowdsale.setWeiPerUSDinTGE(weiPerUsd);
447+
await increaseTimeTestRPCTo(start + 2);
448+
await crowdsale.buyTokens(beneficiary, {value: weiAmount, from: accounts[5]});
449+
450+
await increaseTimeTestRPCTo(end2 + 2);
451+
await crowdsale.finalize();
452+
453+
const MVMAddress = await crowdsale.MVM.call();
454+
assert(MVMAddress === help.zeroAddress, 'no MVM should have been created: ' + MVMAddress);
455+
});
403456
});

test/CrowdsaleGenTest.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,18 @@ contract('LifCrowdsale Property-based test', function(accounts) {
749749
});
750750
});
751751

752+
it('runs fine when funding over soft cap with no excess wei and finalize', async function() {
753+
await runGeneratedCrowdsaleAndCommands({
754+
commands: [
755+
{'type':'fundCrowdsaleOverSoftCap','account':6,'softCapExcessWei':0,'finalize':true}
756+
],
757+
crowdsale: {
758+
rate1: 10, rate2: 23, foundationWallet: 4, foundersWallet: 10,
759+
setWeiLockSeconds: 3405, owner: 5
760+
}
761+
});
762+
});
763+
752764
it('distributes tokens correctly on any combination of bids', async function() {
753765
// stateful prob based tests can take a long time to finish when shrinking...
754766
this.timeout(GEN_TESTS_TIMEOUT * 1000);

test/commands.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ async function runFundCrowdsaleBelowSoftCap(command, state) {
646646
// it might be that the funding was already over the soft cap, so let's check
647647
let softCap = await state.crowdsaleContract.maxFoundationCapUSD.call();
648648

649-
if (currentUSDFunding.gte(softCap)) {
649+
if (currentUSDFunding.gt(softCap)) {
650650
assert(state.MVM);
651651
const capFor48Months = await state.crowdsaleContract.MVM24PeriodsCapUSD.call();
652652
if (currentUSDFunding.gte(capFor48Months)) {
@@ -679,6 +679,8 @@ async function runFundCrowdsaleOverSoftCap(command, state) {
679679

680680
state = await startCrowdsaleAndBuyTokens(command.account, eth, weiPerUSD, state);
681681

682+
currentUSDFunding = state.weiRaised.div(weiPerUSD);
683+
682684
if (command.finalize) {
683685
// wait for crowdsale end2Timestamp
684686
if (latestTime() < state.crowdsaleData.end2Timestamp) {
@@ -692,7 +694,7 @@ async function runFundCrowdsaleOverSoftCap(command, state) {
692694
assert.equal(true, state.crowdsaleFunded,
693695
'crowdwsale should be funded after fund over soft cap command');
694696

695-
if ((currentUSDFunding > softCap) || (command.softCapExcessWei > 0)) {
697+
if (currentUSDFunding.gt(softCap)) {
696698
assert(state.MVM, 'there is MVM b/c funding is over the soft cap');
697699
assert.equal(24, parseInt(await state.MVM.totalPeriods()));
698700
assert.equal(state.crowdsaleData.foundationWallet, await state.MVM.foundationAddr());

0 commit comments

Comments
 (0)