Skip to content

Commit

Permalink
Covers the edge case where the last contribution equals the remains a…
Browse files Browse the repository at this point in the history
…llowance in PreSale
  • Loading branch information
Bros, Ali authored and alibros committed Oct 8, 2017
1 parent 772d37e commit 7369224
Show file tree
Hide file tree
Showing 2 changed files with 165 additions and 0 deletions.
7 changes: 7 additions & 0 deletions contracts/Presale.sol
Expand Up @@ -169,6 +169,13 @@ contract PreSale is TokenSale {
msg.sender.transfer(refundAmount);
closePreSale();
}

// Covergin the edge case where the last contribution equals the remaining cap
uint256 tillCap = remainingCap();
if (tillCap == 0) {
closePreSale();
}

} else {
revert();
}
Expand Down
158 changes: 158 additions & 0 deletions test/preSaleCapEdgeCase.js
@@ -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
});
});

});

0 comments on commit 7369224

Please sign in to comment.