Skip to content

Commit

Permalink
refactor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Federico Martín Alconada Verzini committed Nov 7, 2017
1 parent 57e61ea commit f9eb59f
Show file tree
Hide file tree
Showing 20 changed files with 215 additions and 180 deletions.
3 changes: 2 additions & 1 deletion .solcover.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module.exports = {
port: 8545,
port: 8555,
norpc: true,
// testCommand: 'node ../node_modules/.bin/truffle test --network coverage',
copyNodeModules: true,
skipFiles: ['test-helpers/Message.sol', 'VestedToken.sol']
}
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ matrix:
fast_finish: true
allow_failures:
- env: SOLIDITY_COVERAGE=true
before_script:
- chmod +x ./scripts/ci.sh
script:
- yarn lint
- ./scripts/ci.sh
2 changes: 1 addition & 1 deletion contracts/Crowdsale.sol
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ contract Crowdsale is Pausable {
token = new QiibeeToken();
vault = new RefundVault(wallet);

QiibeeToken(token).pause();
token.pause();

}

Expand Down
3 changes: 2 additions & 1 deletion contracts/QiibeePresale.sol
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ contract QiibeePresale is Crowdsale {
// check limits
uint256 newBalance = balances[beneficiary].add(msg.value);
require(newBalance <= maxInvest && msg.value >= minInvest);
balances[beneficiary] = newBalance;

// spam prevention. TODO: needed for the presale?
require(now.sub(lastCallTime[msg.sender]) >= maxCallFrequency);
Expand Down Expand Up @@ -122,7 +123,7 @@ contract QiibeePresale is Crowdsale {
// @return true if investors can buy at the moment
function validPurchase() internal constant returns (bool) {
require(isAccredited(msg.sender));
super.validPurchase();
return super.validPurchase();
}

/**
Expand Down
22 changes: 22 additions & 0 deletions contracts/test-helpers/CrowdsaleImpl.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
pragma solidity ^0.4.11;


import '../Crowdsale.sol';


contract CrowdsaleImpl is Crowdsale {

function CrowdsaleImpl (
uint256 _startTime,
uint256 _endTime,
uint256 _goal,
uint256 _cap,
uint256 _maxGasPrice,
uint256 _maxCallFrequency,
address _wallet
)
Crowdsale(_startTime, _endTime, _goal, _cap, _maxGasPrice, _maxCallFrequency, _wallet)
{
}

}
22 changes: 22 additions & 0 deletions contracts/test-helpers/QiibeePresaleImpl.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
pragma solidity ^0.4.11;


import '../QiibeePresale.sol';


contract QiibeePresaleImpl is QiibeePresale {

function QiibeePresaleImpl (
uint256 _startTime,
uint256 _endTime,
uint256 _goal,
uint256 _cap,
uint256 _maxGasPrice,
uint256 _maxCallFrequency,
address _wallet
)
QiibeePresale(_startTime, _endTime, _goal, _cap, _maxGasPrice, _maxCallFrequency, _wallet)
{
}

}
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"dependencies": {
"abi-decoder": "^1.0.8",
"bip39": "^2.4.0",
"chai-as-promised": "^7.1.1",
"colors": "^1.1.2",
"ethereumjs-abi": "^0.6.4",
"ethereumjs-wallet": "^0.6.0",
Expand Down
6 changes: 3 additions & 3 deletions scripts/ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -e
if [ "$SOLIDITY_COVERAGE" = true ]; then
yarn run coveralls
else
yarn lint
QB_DEBUG=true yarn test test/token/QiibeeToken.js test/CreatePresale.js test/CreateCrowdsale.js test/Crowdsale.js test/WhitelistedCrowdsale.js
QB_DEBUG=true GEN_TESTS_TIMEOUT=400 GEN_TESTS_QTY=40 yarn test test/CrowdsaleGenTest.js test/PresaleGenTest.js
GEN_TESTS_TIMEOUT=400 GEN_TESTS_QTY=40 yarn test test/PresaleGenTest.js test/CrowdsaleGenTest.js
yarn test test/Crowdsale.js
yarn test test/token/QiibeeToken.js test/QiibeePresale.js test/QiibeeCrowdsale.js test/WhitelistedCrowdsale.js
fi
38 changes: 0 additions & 38 deletions scripts/coverage.sh

This file was deleted.

2 changes: 1 addition & 1 deletion scripts/coveralls.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#! /bin/bash

npm run coverage && cat coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js
npm run test && cat coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js
83 changes: 56 additions & 27 deletions scripts/test.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/usr/bin/env bash

# Exit script as soon as a command fails.
set -o errexit

# Executes cleanup function at script exit.
trap cleanup EXIT

Expand All @@ -10,40 +13,66 @@ cleanup() {
fi
}

if [ "$SOLIDITY_COVERAGE" = true ]; then
testrpc_port=8555
else
testrpc_port=8545
fi

testrpc_running() {
nc -z localhost 8545
nc -z localhost "$testrpc_port"
}

TESTRPC_REDIRECT=/dev/null
start_testrpc() {
if [ "$SOLIDITY_COVERAGE" = true ]; then
node_modules/.bin/testrpc-sc --gasLimit 0xfffffffffff --port "$testrpc_port" \
--account="0xe8280389ca1303a2712a874707fdd5d8ae0437fab9918f845d26fd9919af5a92,10000000000000000000000000000000000000000000000000000000000000000000000000000000" \
--account="0xed095a912033d26dc444d2675b33414f0561af170d58c33f394db8812c87a764,10000000000000000000000000000000000000000000000000000000000000000000000000000000" \
--account="0xf5556ca108835f04cd7d29b4ac66f139dc12b61396b147674631ce25e6e80b9b,10000000000000000000000000000000000000000000000000000000000000000000000000000000" \
--account="0xd1bea55dd05b35be047e409617bc6010b0363f22893b871ceef2adf8e97b9eb9,10000000000000000000000000000000000000000000000000000000000000000000000000000000" \
--account="0xfc452929dc8ffd956ebab936ed0f56d71a8c537b0393ea9da4807836942045c5,10000000000000000000000000000000000000000000000000000000000000000000000000000000" \
--account="0x12b8b2fe49596ab7f439d324797f4b5457b5bd34e9860b08828e4b01af228d93,10000000000000000000000000000000000000000000000000000000000000000000000000000000" \
--account="0x2ed88e3846387d0ae4cca96637df48c201c86079be64d0a17bf492058db6c6eb,10000000000000000000000000000000000000000000000000000000000000000000000000000000" \
--account="0x8c6690649d0b31790fceddd6a59decf2b03686bed940a9b85e8105c5e82f7a86,10000000000000000000000000000000000000000000000000000000000000000000000000000000" \
--account="0xf809d1a2969bec37e7c14628717092befa82156fb2ebf935ac5420bc522f0d29,10000000000000000000000000000000000000000000000000000000000000000000000000000000" \
--account="0x38062255973f02f1b320d8c7762dd286946b3e366f73076995dc859a6346c2ec,10000000000000000000000000000000000000000000000000000000000000000000000000000000" \
--account="0x35b5042e809eab0db3252bad02b67436f64453072128ee91c1d4605de70b27c1,10000000000000000000000000000000000000000000000000000000000000000000000000000000" \
> /dev/null &
else
node_modules/.bin/testrpc --gasLimit 6000000 \
--account="0xe8280389ca1303a2712a874707fdd5d8ae0437fab9918f845d26fd9919af5a92,10000000000000000000000000000000000000000000000000000000000000000000000000000000" \
--account="0xed095a912033d26dc444d2675b33414f0561af170d58c33f394db8812c87a764,10000000000000000000000000000000000000000000000000000000000000000000000000000000" \
--account="0xf5556ca108835f04cd7d29b4ac66f139dc12b61396b147674631ce25e6e80b9b,10000000000000000000000000000000000000000000000000000000000000000000000000000000" \
--account="0xd1bea55dd05b35be047e409617bc6010b0363f22893b871ceef2adf8e97b9eb9,10000000000000000000000000000000000000000000000000000000000000000000000000000000" \
--account="0xfc452929dc8ffd956ebab936ed0f56d71a8c537b0393ea9da4807836942045c5,10000000000000000000000000000000000000000000000000000000000000000000000000000000" \
--account="0x12b8b2fe49596ab7f439d324797f4b5457b5bd34e9860b08828e4b01af228d93,10000000000000000000000000000000000000000000000000000000000000000000000000000000" \
--account="0x2ed88e3846387d0ae4cca96637df48c201c86079be64d0a17bf492058db6c6eb,10000000000000000000000000000000000000000000000000000000000000000000000000000000" \
--account="0x8c6690649d0b31790fceddd6a59decf2b03686bed940a9b85e8105c5e82f7a86,10000000000000000000000000000000000000000000000000000000000000000000000000000000" \
--account="0xf809d1a2969bec37e7c14628717092befa82156fb2ebf935ac5420bc522f0d29,10000000000000000000000000000000000000000000000000000000000000000000000000000000" \
--account="0x38062255973f02f1b320d8c7762dd286946b3e366f73076995dc859a6346c2ec,10000000000000000000000000000000000000000000000000000000000000000000000000000000" \
--account="0x35b5042e809eab0db3252bad02b67436f64453072128ee91c1d4605de70b27c1,10000000000000000000000000000000000000000000000000000000000000000000000000000000" \
> /dev/null &
fi

# when in CI (travis), enable --mem so we can debug testrpc memory usage
# we also need to send testrpc output to stdout instead of /dev/null so we can see it
[ "$CI" = "true" ] && TESTRPC_MEM="--mem" && TESTRPC_REDIRECT=/dev/stdout
testrpc_pid=$!
}

if testrpc_running; then
echo "Using existing testrpc instance"
else
echo "Starting our own testrpc node instance"

testrpc \
$TESTRPC_MEM \
--account="0xe8280389ca1303a2712a874707fdd5d8ae0437fab9918f845d26fd9919af5a92,10000000000000000000000000000000000000000000000000000000000000000000000000000000" \
--account="0xed095a912033d26dc444d2675b33414f0561af170d58c33f394db8812c87a764,10000000000000000000000000000000000000000000000000000000000000000000000000000000" \
--account="0xf5556ca108835f04cd7d29b4ac66f139dc12b61396b147674631ce25e6e80b9b,10000000000000000000000000000000000000000000000000000000000000000000000000000000" \
--account="0xd1bea55dd05b35be047e409617bc6010b0363f22893b871ceef2adf8e97b9eb9,10000000000000000000000000000000000000000000000000000000000000000000000000000000" \
--account="0xfc452929dc8ffd956ebab936ed0f56d71a8c537b0393ea9da4807836942045c5,10000000000000000000000000000000000000000000000000000000000000000000000000000000" \
--account="0x12b8b2fe49596ab7f439d324797f4b5457b5bd34e9860b08828e4b01af228d93,10000000000000000000000000000000000000000000000000000000000000000000000000000000" \
--account="0x2ed88e3846387d0ae4cca96637df48c201c86079be64d0a17bf492058db6c6eb,10000000000000000000000000000000000000000000000000000000000000000000000000000000" \
--account="0x8c6690649d0b31790fceddd6a59decf2b03686bed940a9b85e8105c5e82f7a86,10000000000000000000000000000000000000000000000000000000000000000000000000000000" \
--account="0xf809d1a2969bec37e7c14628717092befa82156fb2ebf935ac5420bc522f0d29,10000000000000000000000000000000000000000000000000000000000000000000000000000000" \
--account="0x38062255973f02f1b320d8c7762dd286946b3e366f73076995dc859a6346c2ec,10000000000000000000000000000000000000000000000000000000000000000000000000000000" \
--account="0x35b5042e809eab0db3252bad02b67436f64453072128ee91c1d4605de70b27c1,10000000000000000000000000000000000000000000000000000000000000000000000000000000" \
--gasLimit 6000000 \
> $TESTRPC_REDIRECT &
testrpc_pid=$!
echo "Starting our own testrpc instance"
start_testrpc
fi

rm -f .node-xmlhttprequest-sync-[0-9]*
rm -f .node-xmlhttprequest-content-[0-9]*
./node_modules/.bin/truffle compile
./node_modules/.bin/truffle test $@
if [ "$SOLIDITY_COVERAGE" = true ]; then
QB_DEBUG=true GEN_TESTS_QTY=0 GAS_PRICE=1 node_modules/.bin/solidity-coverage

if [ "$CONTINUOUS_INTEGRATION" = true ]; then
cat coverage/lcov.info | node_modules/.bin/coveralls
fi
else
rm -f .node-xmlhttprequest-sync-[0-9]*
rm -f .node-xmlhttprequest-content-[0-9]*
node_modules/.bin/truffle compile
node_modules/.bin/truffle test "$@"
fi
44 changes: 0 additions & 44 deletions test/CreatePresale.js

This file was deleted.

20 changes: 1 addition & 19 deletions test/Crowdsale.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* and adapted to the Crowdsale.
*/

const Crowdsale = artifacts.require('Crowdsale.sol');
const Crowdsale = artifacts.require('CrowdsaleImpl.sol');
const QiibeeToken = artifacts.require('QiibeeToken.sol');

const latestTime = require('./helpers/latestTime');
Expand Down Expand Up @@ -38,24 +38,6 @@ contract('Crowdsale', function ([owner, wallet, investor]) {
wallet: wallet
};

// beforeEach(async function () {
// startTime = latestTime() + duration.weeks(1);
// endTime = startTime + duration.weeks(1);
// afterEndTime = endTime + duration.seconds(1);
// crowdsale = await Crowdsale.new(startTime, endTime, goal, cap, maxGasPrice, maxCallFrequency, wallet, {from: owner});

// token = QiibeeToken.at(await crowdsale.token());
// await increaseTimeTestRPC(1);

// assert.equal(startTime, parseInt(await crowdsale.startTime()));
// assert.equal(endTime, parseInt(await crowdsale.endTime()));
// assert.equal(maxGasPrice, parseInt(await crowdsale.maxGasPrice()));
// assert.equal(maxCallFrequency, parseInt(await crowdsale.maxCallFrequency()));
// assert.equal(goal.toString(), (await crowdsale.goal()).toString());
// assert.equal(cap.toString(), (await crowdsale.cap()).toString());
// assert.equal(wallet, await crowdsale.wallet());
// });

async function createCrowdsale(params) {
const startTime = params.start === undefined ? (latestTime() + defaultTimeDelta) : params.start,
endTime = params.endTime === undefined ? (startTime + duration.weeks(1)) : params.endTime,
Expand Down

0 comments on commit f9eb59f

Please sign in to comment.