From 7bb999576586f914f45afea8c9c5a2e6f87fc7a3 Mon Sep 17 00:00:00 2001 From: dapplion Date: Thu, 19 Dec 2019 02:49:50 +0100 Subject: [PATCH 1/2] Run tests without subprocess and split tests and examples --- .travis.yml | 1 + package.json | 1 + packages/toolkit/examples/encode.js | 114 ----------------- packages/toolkit/package.json | 3 +- .../test-examples/createSingleVote.test.js | 119 ++++++++++++++++++ packages/toolkit/test/examples/encode.test.js | 13 -- 6 files changed, 123 insertions(+), 128 deletions(-) delete mode 100644 packages/toolkit/examples/encode.js create mode 100644 packages/toolkit/test-examples/createSingleVote.test.js delete mode 100644 packages/toolkit/test/examples/encode.test.js diff --git a/.travis.yml b/.travis.yml index 5e1a0378d..52c4135f4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,6 +19,7 @@ script: - npm run lint - npm run pretest - npm run test:coverage + - npm run test:integration - npm run posttest after_success: - test $TRAVIS_NODE_VERSION = "11" && npm run report-coverage diff --git a/package.json b/package.json index 27699aac7..57b7428d8 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "posttest": "node scripts/teardown-integration-tests.js", "test": "lerna run --parallel test", "test:coverage": "lerna run --parallel test:coverage", + "test:integration": "lerna run --parallel test:integration", "report-coverage": "codecov", "release": "lerna version", "publish:nightly": "lerna publish from-package --dist-tag nightly --yes" diff --git a/packages/toolkit/examples/encode.js b/packages/toolkit/examples/encode.js deleted file mode 100644 index c9348c205..000000000 --- a/packages/toolkit/examples/encode.js +++ /dev/null @@ -1,114 +0,0 @@ -const Web3 = require('web3') -const { encodeCallScript } = require('@aragon/test-helpers/evmScript') -const { - newDao, - getApmRepo, - getInstalledApps, - encodeActCall, - exec -} = require('../dist/index') - -async function main() { - - // Connect web3. - const web3 = new Web3( - new Web3.providers.WebsocketProvider(`ws://localhost:8545`) - ) - - // Retrieve web3 accounts. - const accounts = await web3.eth.getAccounts() - const acc0 = accounts[0] - // console.log(`accounts`, accounts) - - // Construct options to be used in upcoming calls to the toolkit. - // NOTE: These are pretty useful to see where the toolkit's interface could be improved. - // Ideally, none of this should be necessary. - const options = { - web3, - provider: web3.eth.currentProvider, - registryAddress: '0x5f6f7e8cc7346a11ca2def8f827b7a0b612c56a1', - ipfs: { - rpc: { - protocol: 'http', - host: 'localhost', - port: 5001, - default: true, - }, - gateway: 'http://localhost:8080/ipfs', - } - } - options.ensRegistryAddress = options.registryAddress - options['ens-registry'] = options.registryAddress - // console.log(`options`, options) - - // Retrieve DAO template from APM. - const repo = await getApmRepo( - web3, - 'membership-template.aragonpm.eth', - 'latest', - options - ) - // console.log(`repo`, repo) - - // Create a membership DAO. - console.log(`Creating DAO...`) - const daoAddress = await newDao({ - repo, - web3, - newInstanceMethod: 'newTokenAndInstance', - newInstanceArgs: [ - 'Token name', - 'TKN', - 'daoname' + Math.floor(Math.random() * 1000000), - [acc0], - ['500000000000000000', '50000000000000000', '604800'], - '1296000', - true, - ], - deployEvent: 'DeployDao', - }) - console.log(` Created DAO:`, daoAddress) - - // Retrieve Voting app. - console.log(`Retrieving apps...`) - const apps = await getInstalledApps(daoAddress, options) - const votingAddress = apps.find(app => app.name === "Voting").proxyAddress - console.log(` Voting app`, votingAddress) - - // Encode a bunch of votes. - console.log(`Encoding multiple votes...`) - const actions = [] - const emptyScript = '0x00' - const newVoteSignature = 'newVote(bytes,string)' - for(let i = 0; i < 10; i++) { - actions.push({ - to: votingAddress, - calldata: await encodeActCall(newVoteSignature, [emptyScript, `Vote metadata ${i}`]) - }) - } - // console.log(`actions`, actions) - - // Encode all actions into a single EVM script. - console.log(`Encoding votes into an EVM script...`) - const script = encodeCallScript(actions) - // console.log(`script`, script) - - // Create a single vote with all the other votes encoded in the script. - console.log(`Creating bundled vote with EVM script...`) - const tx = await exec({ - web3, - dao: daoAddress, - app: votingAddress, - method: 'newVote', - params: [script, "Execute multiple votes"], - apm: options - }) - // console.log(`tx`, tx) - - console.log(`\nDone!\n`) - console.log(`\nRun aragon start, and go to http://localhost:3000/#/${daoAddress}/${votingAddress} to verify that the vote containing multiple votes was created.`) - - process.exit() -} - -main() diff --git a/packages/toolkit/package.json b/packages/toolkit/package.json index d5f75895f..5dee918f0 100644 --- a/packages/toolkit/package.json +++ b/packages/toolkit/package.json @@ -17,7 +17,8 @@ "test:clean": "rm -rf ./.tmp && npm run test:reset-cache", "test:reset-cache": "ava --reset-cache", "test:update-snapshots": "npm run test:clean && npm run test -- --update-snapshots", - "test:coverage": "nyc --all --reporter text --reporter text-summary --reporter lcovonly npm run test" + "test:coverage": "nyc --all --reporter text --reporter text-summary --reporter lcovonly npm run test", + "test:integration": "ava --verbose ./test-examples/*.test.js" }, "keywords": [ "aragon", diff --git a/packages/toolkit/test-examples/createSingleVote.test.js b/packages/toolkit/test-examples/createSingleVote.test.js new file mode 100644 index 000000000..9c3a75de2 --- /dev/null +++ b/packages/toolkit/test-examples/createSingleVote.test.js @@ -0,0 +1,119 @@ +import test from 'ava' +import Web3 from 'web3' +import { encodeCallScript } from '@aragon/test-helpers/evmScript' +import { + newDao, + getApmRepo, + getInstalledApps, + encodeActCall, + exec, +} from '../dist/index' + +test.serial( + 'Create a single vote with multiple votes encoded in an EVM script', + async t => { + // Connect web3. + const web3 = new Web3( + new Web3.providers.WebsocketProvider(`ws://localhost:8545`) + ) + + // Retrieve web3 accounts. + const accounts = await web3.eth.getAccounts() + const acc0 = accounts[0] + + // Construct options to be used in upcoming calls to the toolkit. + // NOTE: These are pretty useful to see where the toolkit's interface could be improved. + // Ideally, none of this should be necessary. + const ensRegistryAddress = '0x5f6f7e8cc7346a11ca2def8f827b7a0b612c56a1' + const options = { + web3, + provider: web3.eth.currentProvider, + ipfs: { + rpc: { protocol: 'http', host: 'localhost', port: 5001, default: true }, + gateway: 'http://localhost:8080/ipfs', + }, + registryAddress: ensRegistryAddress, + ensRegistryAddress, + 'ens-registry': ensRegistryAddress, + } + + // Retrieve DAO template from APM. + const repo = await getApmRepo( + web3, + 'membership-template.aragonpm.eth', + 'latest', + options + ) + + // Create a membership DAO. + console.log(`Creating DAO...`) + const daoAddress = await newDao({ + repo, + web3, + newInstanceMethod: 'newTokenAndInstance', + newInstanceArgs: [ + 'Token name', + 'TKN', + 'daoname' + Math.floor(Math.random() * 1000000), + [acc0], + ['500000000000000000', '50000000000000000', '604800'], + '1296000', + true, + ], + deployEvent: 'DeployDao', + }) + console.log(`Created DAO: ${daoAddress}`) + + // Retrieve Voting app. + console.log(`Retrieving apps...`) + const apps = await getInstalledApps(daoAddress, options) + const votingApp = apps.find(app => app.name === 'Voting') + if (!votingApp) + throw Error( + `Voting app not found: ${apps.map(({ name }) => name).join(', ')}` + ) + const votingAddress = votingApp.proxyAddress + console.log(`Retrieved voting app: ${votingAddress}`) + + // Encode a bunch of votes. + console.log(`Encoding multiple votes...`) + const actions = [] + const emptyScript = '0x00' + const newVoteSignature = 'newVote(bytes,string)' + for (let i = 0; i < 10; i++) { + actions.push({ + to: votingAddress, + calldata: await encodeActCall(newVoteSignature, [ + emptyScript, + `Vote metadata ${i}`, + ]), + }) + } + + // Encode all actions into a single EVM script. + console.log(`Encoding votes into an EVM script...`) + const script = encodeCallScript(actions) + + // Create a single vote with all the other votes encoded in the script. + console.log(`Creating bundled vote with EVM script...`) + const tx = await exec({ + web3, + dao: daoAddress, + app: votingAddress, + method: 'newVote', + params: [script, 'Execute multiple votes'], + apm: options, + }) + + console.log(` +Done! Transaction ${tx.receipt.transactionHash} executed +Run aragon start, and go to + + http://localhost:3000/#/${daoAddress}/${votingAddress} + +to verify that the vote containing multiple votes was created. +`) + + t.pass() + } +) diff --git a/packages/toolkit/test/examples/encode.test.js b/packages/toolkit/test/examples/encode.test.js deleted file mode 100644 index 58b9f3e8d..000000000 --- a/packages/toolkit/test/examples/encode.test.js +++ /dev/null @@ -1,13 +0,0 @@ -import test from 'ava' -import execa from 'execa' - -test('runs the encode example without errors', async t => { - const subprocess = execa('node', ['examples/encode.js']) - - // Uncomment to see script running during testing. - // subprocess.stdout.pipe(process.stdout) - - await subprocess - - t.pass() -}) From caf10a4654cf5ea9623d444bbd53065023ad7a23 Mon Sep 17 00:00:00 2001 From: Gabriel Date: Wed, 22 Jan 2020 12:52:45 -0300 Subject: [PATCH 2/2] Fix test --- .../test-examples/createSingleVote.test.js | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/packages/toolkit/test-examples/createSingleVote.test.js b/packages/toolkit/test-examples/createSingleVote.test.js index 9c3a75de2..cd4c8e345 100644 --- a/packages/toolkit/test-examples/createSingleVote.test.js +++ b/packages/toolkit/test-examples/createSingleVote.test.js @@ -26,15 +26,20 @@ test.serial( // Ideally, none of this should be necessary. const ensRegistryAddress = '0x5f6f7e8cc7346a11ca2def8f827b7a0b612c56a1' const options = { - web3, provider: web3.eth.currentProvider, - ipfs: { - rpc: { protocol: 'http', host: 'localhost', port: 5001, default: true }, - gateway: 'http://localhost:8080/ipfs', + apm: { + ipfs: { + rpc: { + protocol: 'http', + host: 'localhost', + port: 5001, + default: true, + }, + gateway: 'http://localhost:8080/ipfs', + }, + ensRegistryAddress, }, - registryAddress: ensRegistryAddress, ensRegistryAddress, - 'ens-registry': ensRegistryAddress, } // Retrieve DAO template from APM. @@ -42,7 +47,7 @@ test.serial( web3, 'membership-template.aragonpm.eth', 'latest', - options + options.apm ) // Create a membership DAO. @@ -67,7 +72,11 @@ test.serial( // Retrieve Voting app. console.log(`Retrieving apps...`) const apps = await getInstalledApps(daoAddress, options) - const votingApp = apps.find(app => app.name === 'Voting') + const votingApp = apps.find( + app => + app.appId === + '0x9fa3927f639745e587912d4b0fea7ef9013bf93fb907d29faeab57417ba6e1d4' + ) if (!votingApp) throw Error( `Voting app not found: ${apps.map(({ name }) => name).join(', ')}` @@ -102,7 +111,7 @@ test.serial( app: votingAddress, method: 'newVote', params: [script, 'Execute multiple votes'], - apm: options, + apm: options.apm, }) console.log(`