diff --git a/apps/address-book/package.json b/apps/address-book/package.json index c9238c204..c56161bc0 100644 --- a/apps/address-book/package.json +++ b/apps/address-book/package.json @@ -48,7 +48,6 @@ "@babel/plugin-proposal-class-properties": "^7.4.4", "@babel/preset-env": "^7.4.5", "@babel/preset-react": "^7.0.0", - "@tps/test-helpers": "^0.0.1", "babel-eslint": "^10.0.1", "babel-plugin-styled-components": "^1.10.0", "cross-env": "^5.2.0", diff --git a/apps/allocations/package.json b/apps/allocations/package.json index 1a145cde2..71ccfdd36 100644 --- a/apps/allocations/package.json +++ b/apps/allocations/package.json @@ -11,7 +11,7 @@ "copy-public-assets": "rsync -rtu ./public/ ./dist", "coverage": "cross-env SOLIDITY_COVERAGE=true npm run ganache-cli:test", "frontend": "npm run sync-assets && parcel app/index.html --port 2222", - "ganache-cli:test": "../shared/test-helpers/ganache-cli.sh", + "ganache-cli:test": "sh ../../node_modules/@aragon/test-helpers/ganache-cli.sh", "lint": "solium --dir ./contracts", "precommit": "lint-staged", "prepublishOnly": "truffle compile", diff --git a/apps/discussions/.solcover.js b/apps/discussions/.solcover.js index 954905775..14de52e23 100644 --- a/apps/discussions/.solcover.js +++ b/apps/discussions/.solcover.js @@ -1,7 +1,5 @@ module.exports = { norpc: true, - copyPackages: [], - skipFiles: [ - 'test', - ] -} + skipFiles: ['test'], + deepSkip: true + } \ No newline at end of file diff --git a/apps/discussions/contracts/misc/Migrations.sol b/apps/discussions/contracts/misc/Migrations.sol deleted file mode 100644 index 74cdc21cb..000000000 --- a/apps/discussions/contracts/misc/Migrations.sol +++ /dev/null @@ -1,25 +0,0 @@ -pragma solidity ^0.4.4; - - -contract Migrations { - address public owner; - uint public lastCompletedMigration; - - modifier restricted() { - if (msg.sender == owner) - _; - } - - constructor() public { - owner = msg.sender; - } - - function setCompleted(uint completed) public restricted { - lastCompletedMigration = completed; - } - - function upgrade(address newAddress) public restricted { - Migrations upgraded = Migrations(newAddress); - upgraded.setCompleted(lastCompletedMigration); - } -} diff --git a/apps/discussions/contracts/test/Imports.sol b/apps/discussions/contracts/test/Imports.sol new file mode 100644 index 000000000..398413601 --- /dev/null +++ b/apps/discussions/contracts/test/Imports.sol @@ -0,0 +1,8 @@ +pragma solidity ^0.4.24; +// HACK to workaround truffle artifact loading on dependencies + +// import "@aragon/os/copruentracts/factory/DAOFactory.sol"; + + + // solium-disable-next-line no-empty-blocks +contract Imports {} \ No newline at end of file diff --git a/apps/dot-voting/migrations/.gitkeep b/apps/discussions/migrations/.gitkeep similarity index 100% rename from apps/dot-voting/migrations/.gitkeep rename to apps/discussions/migrations/.gitkeep diff --git a/apps/discussions/migrations/1_initial_migration.js b/apps/discussions/migrations/1_initial_migration.js deleted file mode 100644 index 3cb2d91cb..000000000 --- a/apps/discussions/migrations/1_initial_migration.js +++ /dev/null @@ -1,6 +0,0 @@ -/* global artifacts */ -var Migrations = artifacts.require('./Migrations.sol') - -module.exports = function(deployer) { - deployer.deploy(Migrations) -} diff --git a/apps/discussions/migrations/2_deploy_contracts.js b/apps/discussions/migrations/2_deploy_contracts.js deleted file mode 100644 index e42a42a38..000000000 --- a/apps/discussions/migrations/2_deploy_contracts.js +++ /dev/null @@ -1,6 +0,0 @@ -/* global artifacts */ -var DiscussionApp = artifacts.require('DiscussionApp.sol') - -module.exports = function(deployer) { - deployer.deploy(DiscussionApp) -} diff --git a/apps/discussions/package.json b/apps/discussions/package.json index a01bd4853..b9bdb102e 100644 --- a/apps/discussions/package.json +++ b/apps/discussions/package.json @@ -20,7 +20,6 @@ "@babel/plugin-proposal-class-properties": "^7.4.4", "@babel/preset-env": "^7.4.5", "@aragon/test-helpers": "^2.0.0", - "@tps/test-helpers": "^0.0.1", "babel-eslint": "^10.0.1", "eslint": "^5.16.0", "eslint-config-prettier": "^6.0.0", diff --git a/apps/discussions/test/app.js b/apps/discussions/test/app.js deleted file mode 100644 index 8ec397ec9..000000000 --- a/apps/discussions/test/app.js +++ /dev/null @@ -1,103 +0,0 @@ -/* global artifacts contract before beforeEach it assert */ -const { assertRevert } = require('@aragon/test-helpers/assertThrow') - -const CounterApp = artifacts.require('CounterApp.sol') -const DAOFactory = artifacts.require( - '@aragon/core/contracts/factory/DAOFactory' -) -const EVMScriptRegistryFactory = artifacts.require( - '@aragon/core/contracts/factory/EVMScriptRegistryFactory' -) -const ACL = artifacts.require('@aragon/core/contracts/acl/ACL') -const Kernel = artifacts.require('@aragon/core/contracts/kernel/Kernel') - -const getContract = name => artifacts.require(name) - -const ANY_ADDRESS = '0xffffffffffffffffffffffffffffffffffffffff' - -contract('CounterApp', accounts => { - let APP_MANAGER_ROLE, INCREMENT_ROLE, DECREMENT_ROLE - let daoFact, appBase, app - - const firstAccount = accounts[0] - const secondAccount = accounts[1] - - before(async () => { - const kernelBase = await getContract('Kernel').new(true) // petrify immediately - const aclBase = await getContract('ACL').new() - const regFact = await EVMScriptRegistryFactory.new() - daoFact = await DAOFactory.new( - kernelBase.address, - aclBase.address, - regFact.address - ) - appBase = await CounterApp.new() - - // Setup constants - APP_MANAGER_ROLE = await kernelBase.APP_MANAGER_ROLE() - INCREMENT_ROLE = await appBase.INCREMENT_ROLE() - DECREMENT_ROLE = await appBase.DECREMENT_ROLE() - }) - - beforeEach(async () => { - const daoReceipt = await daoFact.newDAO(firstAccount) - const dao = Kernel.at( - daoReceipt.logs.filter(l => l.event === 'DeployDAO')[0].args.dao - ) - const acl = ACL.at(await dao.acl()) - - await acl.createPermission( - firstAccount, - dao.address, - APP_MANAGER_ROLE, - firstAccount, - { - from: firstAccount, - } - ) - - const receipt = await dao.newAppInstance( - '0x1234', - appBase.address, - '0x', - false, - { from: firstAccount } - ) - - app = CounterApp.at( - receipt.logs.filter(l => l.event === 'NewAppProxy')[0].args.proxy - ) - - await acl.createPermission( - ANY_ADDRESS, - app.address, - INCREMENT_ROLE, - firstAccount, - { - from: firstAccount, - } - ) - await acl.createPermission( - ANY_ADDRESS, - app.address, - DECREMENT_ROLE, - firstAccount, - { - from: firstAccount, - } - ) - }) - - it('should be incremented by any address', async () => { - app.initialize() - await app.increment(1, { from: secondAccount }) - assert.equal(await app.value(), 1) - }) - - it('should not be decremented if already 0', async () => { - app.initialize() - return assertRevert(async () => { - return app.decrement(1) - }) - }) -}) diff --git a/apps/discussions/truffle-config.js b/apps/discussions/truffle-config.js index 1a77c8c89..2968b8266 100644 --- a/apps/discussions/truffle-config.js +++ b/apps/discussions/truffle-config.js @@ -1 +1 @@ -module.exports = require('@tps/test-helpers/truffle-config') +module.exports = require('@aragon/os/truffle-config') diff --git a/apps/dot-voting/.solcover.js b/apps/dot-voting/.solcover.js index c7c9acc8b..8bcb858f6 100644 --- a/apps/dot-voting/.solcover.js +++ b/apps/dot-voting/.solcover.js @@ -1,5 +1,4 @@ module.exports = { - copyPackages: ['@tps/test-helpers/contracts/common'], deepSkip: true, norpc: true, skipFiles: ['test'], diff --git a/apps/dot-voting/package.json b/apps/dot-voting/package.json index 9731f8b94..3a444d8f1 100644 --- a/apps/dot-voting/package.json +++ b/apps/dot-voting/package.json @@ -51,7 +51,6 @@ "@babel/plugin-proposal-class-properties": "^7.4.4", "@babel/preset-env": "^7.4.5", "@babel/preset-react": "^7.0.0", - "@tps/test-helpers": "^0.0.1", "babel-eslint": "^10.0.1", "babel-plugin-styled-components": "^1.10.0", "cross-env": "^5.2.0", diff --git a/apps/dot-voting/truffle-config.js b/apps/dot-voting/truffle-config.js index 2968b8266..21942ae2c 100644 --- a/apps/dot-voting/truffle-config.js +++ b/apps/dot-voting/truffle-config.js @@ -1 +1,4 @@ -module.exports = require('@aragon/os/truffle-config') +module.exports = { + ...require('@aragon/os/truffle-config'), + migrations_directory: 'contracts' // this just disables using migrations +} \ No newline at end of file diff --git a/apps/rewards/package.json b/apps/rewards/package.json index 10eebc8d3..2fd173ad8 100644 --- a/apps/rewards/package.json +++ b/apps/rewards/package.json @@ -52,7 +52,6 @@ "@babel/plugin-proposal-class-properties": "^7.4.4", "@babel/preset-env": "^7.4.5", "@babel/preset-react": "^7.0.0", - "@tps/test-helpers": "^0.0.1", "babel-eslint": "^10.0.1", "babel-plugin-styled-components": "^1.10.0", "cross-env": "^5.2.0", diff --git a/apps/rewards/test/helpers/blockNumber.js b/apps/rewards/test/helpers/blockNumber.js new file mode 100644 index 000000000..4d3f44d71 --- /dev/null +++ b/apps/rewards/test/helpers/blockNumber.js @@ -0,0 +1,8 @@ +module.exports = web3 => () => { + return new Promise((resolve, reject) => { + web3.eth.getBlockNumber(async (err, res) => { + if (err || !res) return reject(err) + resolve(res) + }) + }) +} diff --git a/apps/rewards/test/helpers/mine.js b/apps/rewards/test/helpers/mine.js new file mode 100644 index 000000000..6ea7bf7cb --- /dev/null +++ b/apps/rewards/test/helpers/mine.js @@ -0,0 +1,73 @@ +// TODO: Import these both from aragon/os +const mineBlock = require('./mineBlock') +const getBlock = require('./blockNumber') + +// TODO: Correct errors + +const getWeb3 = () => { + const Web3 = require('web3') + const PrivateKeyProvider = require('truffle-privatekey-provider') + const provider = new PrivateKeyProvider( + 'A8A54B2D8197BC0B19BB8A084031BE71835580A01E70A45A13BABD16C9BC1563', + 'http://localhost:8545' + ) + return new Web3(provider) +} + +// truffle script: can be run with `truffle exec` +const mine = async (cb) => { + const root = this + let activeWeb3 + let argIdx + if (typeof cb !== 'function') { + activeWeb3 = getWeb3() + argIdx = 2 + } else { + activeWeb3 = web3 + argIdx = 4 + } + const mineBlockFn = mineBlock(activeWeb3) + const getBlockFn = getBlock(activeWeb3) + + const mineBlocks = async (blocks) => { + const blockArr = new Array(Number(blocks)).fill(0) + blockArr.forEach(async () => { + try { + await mineBlockFn() + } + catch(e) { + console.error('error: ',e) + } + }) + } + + const mineToBlock = async (blockNumber) => { + while (blockNumber > await getBlockFn()) { + try { + await mineBlockFn() + } + catch(e) { + console.error('error: ',e) + } + } + } + if (!Number(process.argv[argIdx])) { + await mineToBlock(process.argv[argIdx + 1]) + } + else { + await mineBlocks(process.argv[argIdx]) + } + + console.log('\nblock',await getBlockFn(), 'mined') + + if (typeof cb === 'function') { + cb() + } else { + process.exit() + } +} + +module.exports = mine +if (!process.argv[1].includes('truffle')) { + mine() +} diff --git a/package.json b/package.json index 35fb547b4..bb653b59a 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,7 @@ "lint:fix": "lerna exec --scope=@tps/apps-* --stream -- eslint app --fix", "lint:projects": "cd apps/projects && npm run lint", "lint": "npm run lint:contracts && lerna exec --scope=@tps/apps-* --stream -- eslint app", - "mine": "lerna exec --scope=@tps/test-helpers truffle exec ./mine.js", + "mine": "lerna exec --scope=@tps/apps-rewards truffle exec ./test/helpers/mine.js -- --network rpc", "postinstall": "npm run bootstrap", "publish:cd": "lerna run publish:cd --no-ci --stream --no-bail --scope=@tps/apps*", "publish:apps": "lerna run publish", diff --git a/shared/utils/ganache-cli.sh b/shared/utils/ganache-cli.sh new file mode 100755 index 000000000..922a8872d --- /dev/null +++ b/shared/utils/ganache-cli.sh @@ -0,0 +1,105 @@ +#!/usr/bin/env bash + +# Exit script as soon as a command fails. +set -o errexit + +# get_script_dir () { +# SOURCE="${BASH_SOURCE[0]}" +# # While $SOURCE is a symlink, resolve it +# while [ -h "$SOURCE" ]; do +# DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" +# SOURCE="$( readlink "$SOURCE" )" +# # If $SOURCE was a relative symlink (so no "/" as prefix, need to resolve it relative to the symlink base directory +# [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" +# done +# DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" +# echo "$DIR/node_modules/.bin" +# } + +if [ "$SOLIDITY_COVERAGE" = true ]; then + testrpc_port=8555 +else + testrpc_port=8545 +fi + +testrpc_running() { + nc -z localhost "$testrpc_port" +} + +start_testrpc() { + if [ "$SOLIDITY_COVERAGE" = true ]; then + testrpc-sc -i 16 --gasLimit 0xfffffffffff --port "$testrpc_port" >/dev/null & + elif [ "$TRUFFLE_TEST" = true ]; then + ganache-cli -i 15 --gasLimit 50000000 --port "$testrpc_port" >/dev/null & + elif [ "$START_KIT" = true ]; then + aragon devchain --port "$testrpc_port" & + elif [ "$RESTART_KIT" = true ] || [ "$CYPRESS" = true ]; then + aragon devchain --reset --port "$testrpc_port" & + elif [ "$DEV" = true ]; then + aragon devchain --reset --port "$testrpc_port" & + sleep 10 # wait for devchain to start TODO: modify cli to return rather than require interruption + npm run frontend & + elif [ "$NO_CLIENT" = true ]; then + npm run frontend & + aragon devchain --reset --port "$testrpc_port" & + fi + + testrpc_pid=$! +} + +if testrpc_running; then + echo "Killing testrpc instance at port $testrpc_port" + kill -9 "$(lsof -i:"$testrpc_port" -sTCP:LISTEN -t)" +fi + +echo "Starting our own testrpc instance at port $testrpc_port" +start_testrpc +sleep 5 + +# Exit error mode so the testrpc instance always gets killed +set +e +result=0 +if [ "$SOLIDITY_COVERAGE" = true ]; then + solidity-coverage "$@" + result=$? +elif [ "$TRUFFLE_TEST" = true ]; then + truffle test --network rpc "$@" | grep -v 'Compiling' + result=$? +elif [ "$START_KIT" = true ] || [ "$RESTART_KIT" = true ]; then + npm run publish:apps && npm run start:template + result=$? +elif [ "$DEV" = true ]; then + npm run publish:http && npm run start:dev-template + result=$? +elif [ "$NO_CLIENT" = true ]; then + npm run publish:http && npm run start:kit:no:client + result=$? +elif [ "$CYPRESS" = true ]; then + npm run frontend 2> /dev/null & + app_pgid=$! + aragon ipfs install + aragon ipfs start & + wait-on http://localhost:3333 # wait for bulkiest app service to load (Projects) + npm run publish:http && npm run start:dev-template + pushd . && cd .. + git clone https://github.com/aragon/aragon.git a-client + cd a-client + git checkout bdf5d44bf1b3da72130c086b7a802470533058a1 # latest client commit tested thoroughly with OE + npm i + npm run start:local 2> /dev/null & popd + npm run cypress:run + result=$? + kill -9 "$(lsof -i:3000 -sTCP:LISTEN -t)" # kill parcel dev server + kill -9 "$(lsof -i:8080 -sTCP:LISTEN -t)" # kill IPFS daemon + kill -2 -- $app_pgid # kill app file services + kill -9 "$(lsof -i:1111 -sTCP:LISTEN -t)" # kill app service file descriptor + kill -9 "$(lsof -i:2222 -sTCP:LISTEN -t)" # kill app service file descriptor + kill -9 "$(lsof -i:3333 -sTCP:LISTEN -t)" # kill app service file descriptor + kill -9 "$(lsof -i:4444 -sTCP:LISTEN -t)" # kill app service file descriptor + kill -9 "$(lsof -i:5555 -sTCP:LISTEN -t)" # kill app service file descriptor + rm -rf ../a-client +fi + +kill -9 $testrpc_pid + +exit $result diff --git a/templates/dev/package.json b/templates/dev/package.json index c7b03f02a..a5fd3d4e9 100644 --- a/templates/dev/package.json +++ b/templates/dev/package.json @@ -43,15 +43,13 @@ "@aragon/apps-finance": "^3.0.0", "@aragon/apps-payroll": "^1.0.0", "@aragon/apps-token-manager": "^2.1.0", - "@aragon/apps-shared-minime": "1.0.1", "@aragon/templates-shared": "^1.0.0", "@tps/apps-address-book": "^0.0.1", "@tps/apps-allocations": "^0.0.1", "@tps/apps-discussions": "^1.0.0", "@tps/apps-dot-voting": "^0.0.1", "@tps/apps-projects": "^0.0.1", - "@tps/apps-rewards": "^0.0.1", - "@tps/test-helpers": "^0.0.1" + "@tps/apps-rewards": "^0.0.1" }, "devDependencies": { "@aragon/apps-survey": "^1.0.0", diff --git a/templates/open-enterprise/package.json b/templates/open-enterprise/package.json index 93d07db6d..f38313210 100644 --- a/templates/open-enterprise/package.json +++ b/templates/open-enterprise/package.json @@ -68,7 +68,6 @@ }, "devDependencies": { "@aragon/test-helpers": "^2.0.0", - "@tps/test-helpers": "^0.0.1", "bignumber.js": "^7.2.1", "eth-ens-namehash": "^2.0.8", "eth-gas-reporter": "0.1.12",