Skip to content

Commit

Permalink
adapt and fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Federico Martín Alconada Verzini committed Nov 9, 2017
1 parent 5ceb757 commit 93081a9
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 30 deletions.
8 changes: 5 additions & 3 deletions contracts/Crowdsale.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ import "./QiibeeToken.sol";
@title Crowdsale for the QBX Token Generation Event
Implementation of kind of an 'abstract' QBX Token Generation Event (TGE). This contract will be
used by QiibeePresale.sol and QiibeeCrowdsale.
used by QiibeePresale.sol and QiibeeCrowdsale.sol
This TGE includes is capped and has a spam prevention technique:
This TGE is capped and has a spam prevention technique:
* investors can make purchases with a minimum request inverval of X seconds given by minBuyingRequestInterval.
* investors are limited in the gas price
In case of the goal not being reached by purchases made during the 4-week period the token will
not start operating and all funds sent during that period will be made available to be claimed
by the originating addresses.
The function buyTokens() is not minting tokens. This function should be overriden to add that logic.
*/

contract Crowdsale is Pausable {
Expand Down Expand Up @@ -114,7 +116,7 @@ contract Crowdsale is Pausable {
}

/**
* @dev Must be overridden to add buy token minting logic. The overriding function
* @dev Must be overridden to add token minting logic. The overriding function
* should call super.finalization() to ensure the chain of buy tokens is
* executed entirely.
*/
Expand Down
37 changes: 12 additions & 25 deletions test/PresaleGenTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,20 +164,7 @@ contract('QiibeePresale property-based test', function(accounts) {
await runGeneratedPresaleAndCommands({
commands: [
{ type: 'waitTime','seconds':duration.days(1)},
{ type: 'addAccredited', investor: 4, rate: 6000, cliff: 600, vesting: 600, minInvest: 1, maxCumulativeInvest: 2, fromAccount: 0 },
{ type: 'presaleSendTransaction', beneficiary: 3, account: 4, eth: 1 },
],
presale: {
maxGasPrice: 50000000000, minBuyingRequestInterval: 600, goal: 36000, cap: 240000, foundationWallet: 10, owner: 0
}
});
});

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, maxCumulativeInvest: 2, fromAccount: 0 },
{ type: 'addAccredited', investor: 4, rate: 6000, cliff: 600, vesting: 600, revokable: false, burnsOnTokens: false, minInvest: 1, maxCumulativeInvest: 2, fromAccount: 0 },
{ type: 'presaleSendTransaction', beneficiary: 3, account: 4, eth: 1 },
],
presale: {
Expand All @@ -190,7 +177,7 @@ contract('QiibeePresale property-based test', function(accounts) {
await runGeneratedPresaleAndCommands({
commands: [
{ type: 'waitTime','seconds':duration.days(1)},
{ type: 'addAccredited', investor: 4, rate: 6000, cliff: 0, vesting: 0, minInvest: 1, maxCumulativeInvest: 2, fromAccount: 0 },
{ type: 'addAccredited', investor: 4, rate: 6000, cliff: 0, vesting: 0, revokable: false, burnsOnTokens: false, minInvest: 1, maxCumulativeInvest: 2, fromAccount: 0 },
{ type: 'presaleSendTransaction', beneficiary: 3, account: 4, eth: 1 },
],
presale: {
Expand All @@ -203,7 +190,7 @@ contract('QiibeePresale property-based test', function(accounts) {
await runGeneratedPresaleAndCommands({
commands: [
{ type: 'waitTime','seconds':duration.days(1)},
{ type: 'addAccredited', investor: 4, rate: 6000, cliff: 600, vesting: 600, minInvest: 1, maxCumulativeInvest: 2, fromAccount: 0 },
{ type: 'addAccredited', investor: 4, rate: 6000, cliff: 600, vesting: 600, revokable: false, burnsOnTokens: false, minInvest: 1, maxCumulativeInvest: 2, fromAccount: 0 },
{ type: 'presaleBuyTokens', beneficiary: 3, account: 4, eth: 3 },
],
presale: {
Expand All @@ -216,7 +203,7 @@ contract('QiibeePresale property-based test', function(accounts) {
await runGeneratedPresaleAndCommands({
commands: [
{ type: 'waitTime','seconds':duration.days(1)},
{ type: 'addAccredited', investor: 4, rate: 6000, cliff: 600, vesting: 600, minInvest: 1, maxCumulativeInvest: 2, fromAccount: 0 },
{ type: 'addAccredited', investor: 4, rate: 6000, cliff: 600, vesting: 600, revokable: false, burnsOnTokens: false, minInvest: 1, maxCumulativeInvest: 2, fromAccount: 0 },
{ type: 'presaleBuyTokens', beneficiary: 3, account: 4, eth: 0.5 },
],
presale: {
Expand All @@ -242,7 +229,7 @@ contract('QiibeePresale property-based test', function(accounts) {
await runGeneratedPresaleAndCommands({
commands: [
{ type: 'waitTime','seconds':duration.days(1)},
{ type: 'addAccredited', investor: 4, rate: 0, cliff: 600, vesting: 600, minInvest: 1, maxCumulativeInvest: 2, fromAccount: 2 },
{ type: 'addAccredited', investor: 4, rate: 0, cliff: 600, vesting: 600, revokable: false, burnsOnTokens: false, minInvest: 1, maxCumulativeInvest: 2, fromAccount: 2 },
],
presale: {
maxGasPrice: 50000000000, minBuyingRequestInterval: 600, goal: 36000, cap: 240000, foundationWallet: 10, owner: 0
Expand All @@ -254,7 +241,7 @@ contract('QiibeePresale property-based test', function(accounts) {
await runGeneratedPresaleAndCommands({
commands: [
{ type: 'waitTime','seconds':duration.days(1)},
{ type: 'addAccredited', investor: 4, rate: 6000, cliff: -600, vesting: 600, minInvest: 1, maxCumulativeInvest: 2, fromAccount: 2 },
{ type: 'addAccredited', investor: 4, rate: 6000, cliff: -600, vesting: 600, revokable: false, burnsOnTokens: false, minInvest: 1, maxCumulativeInvest: 2, fromAccount: 2 },
],
presale: {
maxGasPrice: 50000000000, minBuyingRequestInterval: 600, goal: 36000, cap: 240000, foundationWallet: 10, owner: 0
Expand All @@ -266,7 +253,7 @@ contract('QiibeePresale property-based test', function(accounts) {
await runGeneratedPresaleAndCommands({
commands: [
{ type: 'waitTime','seconds':duration.days(1)},
{ type: 'addAccredited', investor: 4, rate: 6000, cliff: 0, vesting: 600, minInvest: 1, maxCumulativeInvest: 2, fromAccount: 2 },
{ type: 'addAccredited', investor: 4, rate: 6000, cliff: 0, vesting: 600, revokable: false, burnsOnTokens: false, minInvest: 1, maxCumulativeInvest: 2, fromAccount: 2 },
],
presale: {
maxGasPrice: 50000000000, minBuyingRequestInterval: 600, goal: 36000, cap: 240000, foundationWallet: 10, owner: 0
Expand All @@ -278,7 +265,7 @@ contract('QiibeePresale property-based test', function(accounts) {
await runGeneratedPresaleAndCommands({
commands: [
{ type: 'waitTime','seconds':duration.days(1)},
{ type: 'addAccredited', investor: 4, rate: 6000, cliff: 600, vesting: -600, minInvest: 1, maxCumulativeInvest: 2, fromAccount: 2 },
{ type: 'addAccredited', investor: 4, rate: 6000, cliff: 600, vesting: -600, revokable: false, burnsOnTokens: false, minInvest: 1, maxCumulativeInvest: 2, fromAccount: 2 },
],
presale: {
maxGasPrice: 50000000000, minBuyingRequestInterval: 600, goal: 36000, cap: 240000, foundationWallet: 10, owner: 0
Expand All @@ -290,7 +277,7 @@ contract('QiibeePresale property-based test', function(accounts) {
await runGeneratedPresaleAndCommands({
commands: [
{ type: 'waitTime','seconds':duration.days(1)},
{ type: 'addAccredited', investor: 4, rate: 6000, cliff: 600, vesting: 600, minInvest: 1, maxCumulativeInvest: -2, fromAccount: 2 },
{ type: 'addAccredited', investor: 4, rate: 6000, cliff: 600, vesting: 600, revokable: false, burnsOnTokens: false, minInvest: 1, maxCumulativeInvest: -2, fromAccount: 2 },
],
presale: {
maxGasPrice: 50000000000, minBuyingRequestInterval: 600, goal: 36000, cap: 240000, foundationWallet: 10, owner: 0
Expand All @@ -302,7 +289,7 @@ contract('QiibeePresale property-based test', function(accounts) {
await runGeneratedPresaleAndCommands({
commands: [
{ type: 'waitTime','seconds':duration.days(1)},
{ type: 'addAccredited', investor: 4, rate: 6000, cliff: 600, vesting: 600, minInvest: 0, maxCumulativeInvest: 2, fromAccount: 2 },
{ type: 'addAccredited', investor: 4, rate: 6000, cliff: 600, vesting: 600, revokable: false, burnsOnTokens: false, minInvest: 0, maxCumulativeInvest: 2, fromAccount: 2 },
],
presale: {
maxGasPrice: 50000000000, minBuyingRequestInterval: 600, goal: 36000, cap: 240000, foundationWallet: 10, owner: 0
Expand All @@ -314,7 +301,7 @@ contract('QiibeePresale property-based test', function(accounts) {
await runGeneratedPresaleAndCommands({
commands: [
{ type: 'waitTime','seconds':duration.days(1)},
{ type: 'addAccredited', investor: 4, rate: 6000, cliff: 600, vesting: 600, minInvest: 1, maxCumulativeInvest: 2, fromAccount: 2 },
{ type: 'addAccredited', investor: 4, rate: 6000, cliff: 600, vesting: 600, revokable: false, burnsOnTokens: false, minInvest: 1, maxCumulativeInvest: 2, fromAccount: 2 },
],
presale: {
maxGasPrice: 50000000000, minBuyingRequestInterval: 600, goal: 36000, cap: 240000, foundationWallet: 10, owner: 0
Expand All @@ -326,7 +313,7 @@ contract('QiibeePresale property-based test', function(accounts) {
await runGeneratedPresaleAndCommands({
commands: [
{ type: 'waitTime','seconds':duration.days(1)},
{ type: 'addAccredited', investor: 'zero', rate: 6000, cliff: 600, vesting: 600, minInvest: 1, maxCumulativeInvest: 2, fromAccount: 0 },
{ type: 'addAccredited', investor: 'zero', rate: 6000, cliff: 600, vesting: 600, revokable: false, burnsOnTokens: false, minInvest: 1, maxCumulativeInvest: 2, fromAccount: 0 },
],
presale: {
maxGasPrice: 50000000000, minBuyingRequestInterval: 600, goal: 36000, cap: 240000, foundationWallet: 10, owner: 0
Expand Down
7 changes: 5 additions & 2 deletions test/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ async function runPresaleSendTransactionCommand(command, state) {
frequencyExceeded ||
gasExceeded ||
capExceeded;

try {
const tx = await state.presaleContract.sendTransaction({value: weiCost, from: account});
assert.equal(false, shouldThrow, 'sendTransaction should have thrown but it did not');
Expand Down Expand Up @@ -360,6 +361,8 @@ async function runAddAccreditedCommand(command, state) {
rate = command.rate,
cliff = command.cliff,
vesting = command.vesting,
revokable = command.revokable,
burnsOnTokens = command.burnsOnTokens,
minInvest = command.minInvest,
maxCumulativeInvest = command.maxCumulativeInvest;

Expand All @@ -374,11 +377,11 @@ async function runAddAccreditedCommand(command, state) {
command.fromAccount != state.owner;

try {
await state.presaleContract.addAccreditedInvestor(investor, rate, cliff, vesting, help.toWei(minInvest), help.toWei(maxCumulativeInvest), {from: account});
await state.presaleContract.addAccreditedInvestor(investor, rate, cliff, vesting, revokable, burnsOnTokens, help.toWei(minInvest), help.toWei(maxCumulativeInvest), {from: account});
help.debug(colors.green('SUCCESS adding accredited investor'));

assert.equal(false, shouldThrow, 'add to whitelist should have thrown but it did not');
state.accredited[command.investor] = {rate: rate, cliff: cliff, vesting: vesting, minInvest: help.toWei(minInvest), maxCumulativeInvest: help.toWei(maxCumulativeInvest)};
state.accredited[command.investor] = {rate: rate, cliff: cliff, vesting: vesting, revokable, burnsOnTokens, minInvest: help.toWei(minInvest), maxCumulativeInvest: help.toWei(maxCumulativeInvest)};
} catch(e) {
assertExpectedException(e, shouldThrow, hasZeroAddress, state, command);
help.debug(colors.yellow('FAILURE adding accredited investor'));
Expand Down
2 changes: 2 additions & 0 deletions test/generators.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ module.exports = {
rate: jsc.integer(0, 20000),
cliff: jsc.integer(0, 20000),
vesting: jsc.integer(0, 20000),
revokable: jsc.bool,
burnsOnTokens: jsc.bool,
minInvest: jsc.integer(0, 1000000000),
maxCumulativeInvest: jsc.integer(0, 1000000000),
fromAccount: accountGen,
Expand Down

0 comments on commit 93081a9

Please sign in to comment.