Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Federico Martín Alconada Verzini committed Nov 8, 2017
1 parent 292ce83 commit 0968b34
Show file tree
Hide file tree
Showing 2 changed files with 161 additions and 73 deletions.
54 changes: 50 additions & 4 deletions test/Crowdsale.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ contract('Crowdsale', function ([owner, wallet, investor]) {
};

async function createCrowdsale(params) {
const startTime = params.start === undefined ? (latestTime() + defaultTimeDelta) : params.start,
const startTime = params.startTime === undefined ? (latestTime() + defaultTimeDelta) : params.startTime,
endTime = params.endTime === undefined ? (startTime + duration.weeks(1)) : params.endTime,
goal = params.goal === undefined ? defaults.goal : params.goal,
cap = params.cap === undefined ? defaults.cap : params.cap,
Expand All @@ -50,6 +50,26 @@ contract('Crowdsale', function ([owner, wallet, investor]) {
return await Crowdsale.new(startTime, endTime, goal, cap, maxGasPrice, maxCallFrequency, wallet, {from: owner});
}

describe('create crowdsale tests', function () {
it('can NOT create crowdsale with endTime bigger than startTime', async function () {
const startTime = latestTime() + duration.weeks(1),
endTime = startTime - duration.weeks(1);
try {
await createCrowdsale({startTime: startTime, endTime: endTime});
} catch(e) {
assertExpectedException(e);
}
});

it('can NOT create crowdsale with maxCallFrequency less than zero', async function () {
try {
await createCrowdsale({maxCallFrequency: defaults.maxCallFrequency*(-1)});
} catch(e) {
assertExpectedException(e);
}
});
});

it('should be token owner', async function () {
const crowdsale = await createCrowdsale({}),
token = QiibeeToken.at(await crowdsale.token()),
Expand Down Expand Up @@ -90,6 +110,16 @@ contract('Crowdsale', function ([owner, wallet, investor]) {
}
});

it('should reject payments if beneficiary address is zero', async function () {
const crowdsale = await createCrowdsale({});
await increaseTimeTestRPCTo(await crowdsale.startTime());
try {
await crowdsale.buyTokens(help.zeroAddress, {value: value, from: investor});
} catch (e) {
assertExpectedException(e);
}
});

it('should accept payments after start', async function () {
const crowdsale = await createCrowdsale({});
await increaseTimeTestRPCTo(await crowdsale.startTime());
Expand All @@ -114,13 +144,29 @@ contract('Crowdsale', function ([owner, wallet, investor]) {

});

describe('finalize crowdsale tests', function () {

it('should reject finalize if crowdsale is already finalized', async function () {
const crowdsale = await createCrowdsale({});
await increaseTimeTestRPCTo(await crowdsale.startTime());
await crowdsale.sendTransaction({value: defaults.goal, from: investor});
await increaseTimeTestRPCTo(await crowdsale.endTime() + duration.seconds(1));
await crowdsale.finalize({from: owner});
try {
await crowdsale.finalize({from: owner});
} catch(e) {
assertExpectedException(e);
}
});

});
// RefundableCrowdsale.sol
describe('refundable crowdsale tests', function () {

it('should fail creating crowdsale with zero goal', async function () {
it('can NOT create crowdsale with goal less than zero', async function () {
try {
await createCrowdsale({goal: 0});
} catch (e) {
await createCrowdsale({goal: defaults.goal.mul(-1)});
} catch(e) {
assertExpectedException(e);
}
});
Expand Down
180 changes: 111 additions & 69 deletions test/PresaleGenTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,19 @@ contract('QiibeePresale property-based test', function(accounts) {
});
});

it('should allow accredited investors to buy tokens', async function () {
await runGeneratedPresaleAndCommands({
commands: [
{ type: 'waitTime','seconds':duration.days(1)},
{ type: 'addAccredited', investor: 4, rate: 6000, cliff: 600, vesting: 600, minInvest: 1, maxInvest: 2, fromAccount: 0 },
{ type: 'presaleSendTransaction', beneficiary: 3, account: 4, eth: 1 },
],
presale: {
maxGasPrice: 50000000000, maxCallFrequency: 600, goal: 36000, cap: 240000, foundationWallet: 10, owner: 0
}
});
});

it('should allow accredited investors to buy non-vested tokens', async function () {
await runGeneratedPresaleAndCommands({
commands: [
Expand Down Expand Up @@ -224,87 +237,101 @@ contract('QiibeePresale property-based test', function(accounts) {
});
});

it('should NOT be able to add investor to accredited list with rate zero', async function () {
await runGeneratedPresaleAndCommands({
commands: [
{ type: 'waitTime','seconds':duration.days(1)},
{ type: 'addAccredited', investor: 4, rate: 0, cliff: 600, vesting: 600, minInvest: 1, maxInvest: 2, fromAccount: 2 },
],
presale: {
maxGasPrice: 50000000000, maxCallFrequency: 600, goal: 36000, cap: 240000, foundationWallet: 10, owner: 0
}
describe('add to accredited list', function () {
it('should NOT be able to add investor to accredited list with rate zero', async function () {
await runGeneratedPresaleAndCommands({
commands: [
{ type: 'waitTime','seconds':duration.days(1)},
{ type: 'addAccredited', investor: 4, rate: 0, cliff: 600, vesting: 600, minInvest: 1, maxInvest: 2, fromAccount: 2 },
],
presale: {
maxGasPrice: 50000000000, maxCallFrequency: 600, goal: 36000, cap: 240000, foundationWallet: 10, owner: 0
}
});
});
});

it('should NOT be able to add investor to accredited list with cliff less than zero', async function () {
await runGeneratedPresaleAndCommands({
commands: [
{ type: 'waitTime','seconds':duration.days(1)},
{ type: 'addAccredited', investor: 4, rate: 0, cliff: -600, vesting: 600, minInvest: 1, maxInvest: 2, fromAccount: 2 },
],
presale: {
maxGasPrice: 50000000000, maxCallFrequency: 600, goal: 36000, cap: 240000, foundationWallet: 10, owner: 0
}
it('should NOT be able to add investor to accredited list with cliff less than zero', async function () {
await runGeneratedPresaleAndCommands({
commands: [
{ type: 'waitTime','seconds':duration.days(1)},
{ type: 'addAccredited', investor: 4, rate: 6000, cliff: -600, vesting: 600, minInvest: 1, maxInvest: 2, fromAccount: 2 },
],
presale: {
maxGasPrice: 50000000000, maxCallFrequency: 600, goal: 36000, cap: 240000, foundationWallet: 10, owner: 0
}
});
});
});

it('should NOT be able to add investor to accredited list with vesting less than zero', async function () {
await runGeneratedPresaleAndCommands({
commands: [
{ type: 'waitTime','seconds':duration.days(1)},
{ type: 'addAccredited', investor: 4, rate: 0, cliff: 600, vesting: -600, minInvest: 1, maxInvest: 2, fromAccount: 2 },
],
presale: {
maxGasPrice: 50000000000, maxCallFrequency: 600, goal: 36000, cap: 240000, foundationWallet: 10, owner: 0
}
it('should be able to add investor to accredited list with zero cliff', async function () {
await runGeneratedPresaleAndCommands({
commands: [
{ type: 'waitTime','seconds':duration.days(1)},
{ type: 'addAccredited', investor: 4, rate: 6000, cliff: 0, vesting: 600, minInvest: 1, maxInvest: 2, fromAccount: 2 },
],
presale: {
maxGasPrice: 50000000000, maxCallFrequency: 600, goal: 36000, cap: 240000, foundationWallet: 10, owner: 0
}
});
});
});

it('should NOT be able to add investor to accredited list with maxInvest less than zero', async function () {
await runGeneratedPresaleAndCommands({
commands: [
{ type: 'waitTime','seconds':duration.days(1)},
{ type: 'addAccredited', investor: 4, rate: 0, cliff: 600, vesting: 600, minInvest: 1, maxInvest: -2, fromAccount: 2 },
],
presale: {
maxGasPrice: 50000000000, maxCallFrequency: 600, goal: 36000, cap: 240000, foundationWallet: 10, owner: 0
}
it('should NOT be able to add investor to accredited list with vesting less than zero', async function () {
await runGeneratedPresaleAndCommands({
commands: [
{ type: 'waitTime','seconds':duration.days(1)},
{ type: 'addAccredited', investor: 4, rate: 6000, cliff: 600, vesting: -600, minInvest: 1, maxInvest: 2, fromAccount: 2 },
],
presale: {
maxGasPrice: 50000000000, maxCallFrequency: 600, goal: 36000, cap: 240000, foundationWallet: 10, owner: 0
}
});
});
});

it('should NOT be able to add investor to accredited list with minInvest zero', async function () {
await runGeneratedPresaleAndCommands({
commands: [
{ type: 'waitTime','seconds':duration.days(1)},
{ type: 'addAccredited', investor: 4, rate: 0, cliff: 600, vesting: 600, minInvest: 0, maxInvest: 2, fromAccount: 2 },
],
presale: {
maxGasPrice: 50000000000, maxCallFrequency: 600, goal: 36000, cap: 240000, foundationWallet: 10, owner: 0
}
it('should NOT be able to add investor to accredited list with maxInvest less than zero', async function () {
await runGeneratedPresaleAndCommands({
commands: [
{ type: 'waitTime','seconds':duration.days(1)},
{ type: 'addAccredited', investor: 4, rate: 6000, cliff: 600, vesting: 600, minInvest: 1, maxInvest: -2, fromAccount: 2 },
],
presale: {
maxGasPrice: 50000000000, maxCallFrequency: 600, goal: 36000, cap: 240000, foundationWallet: 10, owner: 0
}
});
});
});

it('should NOT be able to add investor to accredited list if not owner', async function () {
await runGeneratedPresaleAndCommands({
commands: [
{ type: 'waitTime','seconds':duration.days(1)},
{ type: 'addAccredited', investor: 4, rate: 6000, cliff: 600, vesting: 600, minInvest: 1, maxInvest: 2, fromAccount: 2 },
],
presale: {
maxGasPrice: 50000000000, maxCallFrequency: 600, goal: 36000, cap: 240000, foundationWallet: 10, owner: 0
}
it('should NOT be able to add investor to accredited list with minInvest zero', async function () {
await runGeneratedPresaleAndCommands({
commands: [
{ type: 'waitTime','seconds':duration.days(1)},
{ type: 'addAccredited', investor: 4, rate: 6000, cliff: 600, vesting: 600, minInvest: 0, maxInvest: 2, fromAccount: 2 },
],
presale: {
maxGasPrice: 50000000000, maxCallFrequency: 600, goal: 36000, cap: 240000, foundationWallet: 10, owner: 0
}
});
});
});

it('should NOT be able to add investor to accredited list if address is zero', async function () {
await runGeneratedPresaleAndCommands({
commands: [
{ type: 'waitTime','seconds':duration.days(1)},
{ type: 'addAccredited', investor: 'zero', rate: 6000, cliff: 600, vesting: 600, minInvest: 1, maxInvest: 2, fromAccount: 0 },
],
presale: {
maxGasPrice: 50000000000, maxCallFrequency: 600, goal: 36000, cap: 240000, foundationWallet: 10, owner: 0
}
it('should NOT be able to add investor to accredited list if not owner', async function () {
await runGeneratedPresaleAndCommands({
commands: [
{ type: 'waitTime','seconds':duration.days(1)},
{ type: 'addAccredited', investor: 4, rate: 6000, cliff: 600, vesting: 600, minInvest: 1, maxInvest: 2, fromAccount: 2 },
],
presale: {
maxGasPrice: 50000000000, maxCallFrequency: 600, goal: 36000, cap: 240000, foundationWallet: 10, owner: 0
}
});
});

it('should NOT be able to add investor to accredited list if address is zero', async function () {
await runGeneratedPresaleAndCommands({
commands: [
{ type: 'waitTime','seconds':duration.days(1)},
{ type: 'addAccredited', investor: 'zero', rate: 6000, cliff: 600, vesting: 600, minInvest: 1, maxInvest: 2, fromAccount: 0 },
],
presale: {
maxGasPrice: 50000000000, maxCallFrequency: 600, goal: 36000, cap: 240000, foundationWallet: 10, owner: 0
}
});
});
});

Expand Down Expand Up @@ -333,6 +360,21 @@ contract('QiibeePresale property-based test', function(accounts) {
await runGeneratedPresaleAndCommands(presaleAndCommands);
});

it('should NOT finish presale if it has already been finalized', async function() {
let presaleAndCommands = {
commands: [
{ type: 'waitTime','seconds':duration.days(4)},
{ type: 'finalizePresale', fromAccount: 1 },
{ type: 'finalizePresale', fromAccount: 2 }
],
presale: {
maxGasPrice: 50000000000, maxCallFrequency: 600, goal: 36000, cap: 240000, foundationWallet: 10, owner: 0
}
};

await runGeneratedPresaleAndCommands(presaleAndCommands);
});

it('should handle the exception correctly when trying to finalize the presale before the presale has ended', async function() {
let presaleAndCommands = {
commands: [
Expand Down

0 comments on commit 0968b34

Please sign in to comment.