Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Covers the edge case where the last contribution equals the remains a…
…llowance in PreSale
- Loading branch information
Showing
2 changed files
with
165 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
const assertFail = require("./helpers/assertFail"); | ||
const assertions = require("./helpers/assertions"); | ||
const eventsUtil = require("./helpers/eventsUtil"); | ||
const testConfig = require("./helpers/testConfig"); | ||
|
||
contract("Presale cap/limits", function(accounts) { | ||
|
||
before(async function() { | ||
await testConfig.setupForPreSale(accounts); | ||
}); | ||
|
||
it('should initialize contract with expected values', async function() { | ||
await assertions.expectedInitialisation( | ||
testConfig.preSale, | ||
{ | ||
etherEscrowWallet: testConfig.etherEscrowWallet, | ||
reserveWallet: testConfig.reserveWallet, | ||
foundersWallet: testConfig.foundersWallet | ||
}, | ||
{ | ||
preSaleBegin: testConfig.preSaleBegin, | ||
preSaleEnd: testConfig.preSaleEnd, | ||
preSaleCap: testConfig.preSaleCap, | ||
minPresaleContributionEther: testConfig.minPresaleContributionEther, | ||
maxPresaleContributionEther: testConfig.maxPresaleContributionEther, | ||
firstTierDiscountUpperLimitEther: testConfig.firstTierDiscountUpperLimitEther, | ||
secondTierDiscountUpperLimitEther: testConfig.secondTierDiscountUpperLimitEther, | ||
thirdTierDiscountUpperLimitEther: testConfig.thirdTierDiscountUpperLimitEther | ||
} | ||
); | ||
}); | ||
|
||
it('should set the pre-sale cap to 50 ETH', async function() { | ||
|
||
let newPresaleCap = web3.toWei('50', 'ether'); | ||
await testConfig.preSale.setPresaleCap( | ||
newPresaleCap, | ||
{ | ||
from: testConfig.ownerAddress | ||
} | ||
); | ||
|
||
let preSaleCap = (await testConfig.preSale.preSaleCap()).toNumber(); | ||
assert.equal(preSaleCap, web3.toWei(50)); | ||
|
||
let closed = await testConfig.preSale.closed(); | ||
assert.equal(closed, false); | ||
}); | ||
|
||
it('should allow owner to resume the sale', async function(){ | ||
await testConfig.preSale.resumeContribution({ | ||
from: testConfig.ownerAddress | ||
}); | ||
const paused = await testConfig.preSale.paused(); | ||
assert.equal(false, paused); | ||
}); | ||
|
||
it('should accept valid contribution', async function() { | ||
await testConfig.preSale.sendTransaction({ | ||
value: testConfig.minPresaleContributionEther, | ||
from: testConfig.contributorOneAddress | ||
}); | ||
assertions.ether({ | ||
etherEscrowBalance: 25, | ||
presaleBalance: 0, | ||
contributorOneBalance: 75, | ||
contributorTwoBalance: 100, | ||
reserveBalance: 0, | ||
foundersBalance: 0 | ||
}); | ||
await assertions.SHP({ | ||
etherEscrowBalance: 0, | ||
presaleBalance: 0, | ||
contributorOneBalance: 55000, | ||
contributorTwoBalance: 0, | ||
reserveBalance: 0, | ||
foundersBalance: 0, | ||
trusteeBalance: 62500, | ||
bountyBalance: 12500 | ||
}); | ||
let preSaleEtherPaid = (await testConfig.preSale.preSaleEtherPaid()).toNumber(); | ||
assert.equal(preSaleEtherPaid, web3.toWei(25)); | ||
}); | ||
|
||
|
||
it('should accept last contribution if equal to remaining balance and close the sale', async function() { | ||
|
||
let contribution = web3.toWei('25', 'ether'); | ||
await testConfig.preSale.sendTransaction({ | ||
value: contribution, | ||
from: testConfig.contributorTwoAddress | ||
}) | ||
.then(result => { | ||
eventsUtil.eventValidator( | ||
result, | ||
{ | ||
name: "PresaleClosed", | ||
} | ||
); | ||
}); | ||
|
||
assertions.ether({ | ||
etherEscrowBalance: 50, | ||
presaleBalance: 0, | ||
contributorOneBalance: 75, | ||
contributorTwoBalance: 75, | ||
reserveBalance: 0, | ||
foundersBalance: 0 | ||
}); | ||
await assertions.SHP({ | ||
etherEscrowBalance: 0, | ||
presaleBalance: 0, | ||
contributorOneBalance: 55000, | ||
contributorTwoBalance: 55000, | ||
reserveBalance: 0, | ||
foundersBalance: 0, | ||
trusteeBalance: 125000, | ||
bountyBalance: 25000 | ||
}); | ||
|
||
let preSaleEtherPaid = (await testConfig.preSale.preSaleEtherPaid()).toNumber(); | ||
assert.equal(preSaleEtherPaid, web3.toWei(50)); | ||
}); | ||
|
||
it('should not accept ETH when pre-sale has been automatically closed', async function() { | ||
|
||
let closed = await testConfig.preSale.closed(); | ||
assert.equal(closed, true); | ||
|
||
let contribution = web3.toWei('25', 'ether'); | ||
await assertFail(async function() { | ||
await testConfig.preSale.sendTransaction({ | ||
value: contribution, | ||
from: testConfig.contributorTwoAddress | ||
}) | ||
}); | ||
|
||
assertions.ether({ | ||
etherEscrowBalance: 50, | ||
presaleBalance: 0, | ||
contributorOneBalance: 75, | ||
contributorTwoBalance: 75, | ||
reserveBalance: 0, | ||
foundersBalance: 0 | ||
}); | ||
await assertions.SHP({ | ||
etherEscrowBalance: 0, | ||
presaleBalance: 0, | ||
contributorOneBalance: 55000, | ||
contributorTwoBalance: 55000, | ||
reserveBalance: 0, | ||
foundersBalance: 0, | ||
trusteeBalance: 125000, | ||
bountyBalance: 25000 | ||
}); | ||
}); | ||
|
||
}); |