Skip to content

Commit

Permalink
test: set ethereum contract testing environment
Browse files Browse the repository at this point in the history
  • Loading branch information
als95 authored and junbeomlee committed Jun 5, 2019
1 parent 5889628 commit 41b180d
Show file tree
Hide file tree
Showing 4 changed files with 176 additions and 0 deletions.
52 changes: 52 additions & 0 deletions contracts/ethereum/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"name": "hatch-test",
"version": "1.0.0",
"description": "",
"main": "truffle-config.js",
"scripts": {
"test": "scripts/test.sh",
"lint:sol": "solium -d .",
"lint:sol:fix": "solium -d . --fix",
"coverage": "scripts/coverage.sh"
},
"author": "",
"license": "ISC",
"devDependencies": {
"@haechi-labs/vvisp-contracts": "^1.0.0",
"@haechi-labs/vvisp-utils": "^1.0.0",
"babel-preset-env": "^1.7.0",
"coveralls": "^3.0.1",
"eth-gas-reporter": "^0.1.7",
"ethereumjs-util": "^5.1.2",
"ethjs-abi": "^0.2.1",
"ganache-cli": "6.1.0",
"husky": "^1.2.1",
"lint-staged": "^8.1.0",
"openzeppelin-solidity": "2.1.3",
"openzeppelin-test-helpers": "^0.3.2",
"prettier": "^1.15.3",
"solidity-coverage": "git+https://github.com/rotcivegaf/solidity-coverage.git#5875f5b7bc74d447f3312c9c0e9fc7814b482477",
"solium": "^1.1.6",
"truffle": "^5.0.0",
"web3": "^1.0.0-beta.55"
},
"lint-staged": {
"**/*.js": [
"prettier --write",
"git add"
]
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"prettier": {
"singleQuote": true,
"tabWidth": 2,
"printWidth": 80
},
"dependencies": {
"package.json": "^2.0.1"
}
}
3 changes: 3 additions & 0 deletions contracts/ethereum/scripts/coverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

SOLIDITY_COVERAGE=true scripts/test.sh
81 changes: 81 additions & 0 deletions contracts/ethereum/scripts/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/usr/bin/env bash

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

# Executes cleanup function at script exit.
trap cleanup EXIT

cleanup() {
# Kill the ganache instance that we started (if we started one and if it's still running).
if [ -n "$ganache_pid" ] && ps -p $ganache_pid > /dev/null; then
kill -9 $ganache_pid
fi
}

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

ganache_running() {
nc -z localhost "$ganache_port"
}

start_ganache() {
# We define 10 accounts with balance 1M ether, needed for high-value tests.
local accounts=(
--account="0xb178cf12d4126ea1db48ca32e3ce6743580ca6646391996032fc76652d699972,1000000000000000000000000000"
--account="0xb178cf12d4126ea1db48ca32e3ce6743580ca6646391996032fc76652d699973,1000000000000000000000000000"
--account="0xb178cf12d4126ea1db48ca32e3ce6743580ca6646391996032fc76652d699974,1000000000000000000000000000"
--account="0xb178cf12d4126ea1db48ca32e3ce6743580ca6646391996032fc76652d699975,1000000000000000000000000000"
--account="0xb178cf12d4126ea1db48ca32e3ce6743580ca6646391996032fc76652d699976,1000000000000000000000000000"
--account="0xb178cf12d4126ea1db48ca32e3ce6743580ca6646391996032fc76652d699977,1000000000000000000000000000"
--account="0xb178cf12d4126ea1db48ca32e3ce6743580ca6646391996032fc76652d699978,1000000000000000000000000000"
--account="0xb178cf12d4126ea1db48ca32e3ce6743580ca6646391996032fc76652d699979,1000000000000000000000000000"
--account="0xb178cf12d4126ea1db48ca32e3ce6743580ca6646391996032fc76652d69997a,1000000000000000000000000000"
--account="0xb178cf12d4126ea1db48ca32e3ce6743580ca6646391996032fc76652d69997b,1000000000000000000000000000"
--account="0xb178cf12d4126ea1db48ca32e3ce6743580ca6646391996032fc76652d69997c,1000000000000000000000000000"
--account="0xb178cf12d4126ea1db48ca32e3ce6743580ca6646391996032fc76652d69997e,1000000000000000000000000000"
--account="0xb178cf12d4126ea1db48ca32e3ce6743580ca6646391996032fc76652d69997f,1000000000000000000000000000"
--account="0xb178cf12d4126ea1db48ca32e3ce6743580ca6646391996032fc76652d699981,1000000000000000000000000000"
--account="0xb178cf12d4126ea1db48ca32e3ce6743580ca6646391996032fc76652d699982,1000000000000000000000000000"
--account="0xb178cf12d4126ea1db48ca32e3ce6743580ca6646391996032fc76652d699983,1000000000000000000000000000"
--account="0xb178cf12d4126ea1db48ca32e3ce6743580ca6646391996032fc76652d699984,1000000000000000000000000000"
--account="0xb178cf12d4126ea1db48ca32e3ce6743580ca6646391996032fc76652d699985,1000000000000000000000000000"
--account="0xb178cf12d4126ea1db48ca32e3ce6743580ca6646391996032fc76652d699986,1000000000000000000000000000"
--account="0xb178cf12d4126ea1db48ca32e3ce6743580ca6646391996032fc76652d699987,1000000000000000000000000000"
--account="0xb178cf12d4126ea1db48ca32e3ce6743580ca6646391996032fc76652d699988,1000000000000000000000000000"
--account="0xb178cf12d4126ea1db48ca32e3ce6743580ca6646391996032fc76652d699989,1000000000000000000000000000"
)

if [ "$SOLIDITY_COVERAGE" = true ]; then
node_modules/.bin/testrpc-sc --gasLimit 0xfffffffffff --port "$ganache_port" "${accounts[@]}" > /dev/null &
else
node_modules/.bin/ganache-cli --gasLimit 0xfffffffffff "${accounts[@]}" > /dev/null &
fi
ganache_pid=$!
}

if ganache_running; then
echo "Using existing ganache instance"
else
echo "Starting our own ganache instance"
start_ganache
fi

if [ "$SOLC_NIGHTLY" = true ]; then
echo "Downloading solc nightly"
wget -q https://raw.githubusercontent.com/ethereum/solc-bin/gh-pages/bin/soljson-nightly.js -O /tmp/soljson.js && find . -name soljson.js -exec cp /tmp/soljson.js {} \;
fi

if [ "$SOLIDITY_COVERAGE" = true ]; then
node_modules/.bin/solidity-coverage

if [ "$CONTINUOUS_INTEGRATION" = true ]; then
cat coverage/lcov.info | node_modules/.bin/coveralls
fi
else
node_modules/.bin/truffle test "$@"
fi
40 changes: 40 additions & 0 deletions contracts/ethereum/truffle-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
module.exports = {
networks: {
development: {
host: 'localhost',
port: 8545,
network_id: '*' // eslint-disable-line camelcase
},
coverage: {
host: 'localhost',
network_id: '*', // eslint-disable-line camelcase
port: 8555,
gas: 0xfffffffffff,
gasPrice: 0x01
},
ganache: {
host: 'localhost',
port: 8545,
network_id: '*' // eslint-disable-line camelcase
}
},
compilers: {
solc: {
version: '0.5.0',
settings: {
optimizer: {
enabled: true,
runs: 200
},
evmVersion: 'byzantium'
}
}
},
mocha: {
reporter: 'eth-gas-reporter',
reporterOptions: {
currency: 'KRW',
gasPrice: 5
}
}
};

0 comments on commit 41b180d

Please sign in to comment.