diff --git a/.travis.yml b/.travis.yml index 26359fb8e..e62e9764f 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 = "12" && 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 a17075701..23424d2c1 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..cd4c8e345 --- /dev/null +++ b/packages/toolkit/test-examples/createSingleVote.test.js @@ -0,0 +1,128 @@ +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 = { + provider: web3.eth.currentProvider, + apm: { + ipfs: { + rpc: { + protocol: 'http', + host: 'localhost', + port: 5001, + default: true, + }, + gateway: 'http://localhost:8080/ipfs', + }, + ensRegistryAddress, + }, + ensRegistryAddress, + } + + // Retrieve DAO template from APM. + const repo = await getApmRepo( + web3, + 'membership-template.aragonpm.eth', + 'latest', + options.apm + ) + + // 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.appId === + '0x9fa3927f639745e587912d4b0fea7ef9013bf93fb907d29faeab57417ba6e1d4' + ) + 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.apm, + }) + + 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 870a00173..000000000 --- a/packages/toolkit/test/examples/encode.test.js +++ /dev/null @@ -1,14 +0,0 @@ -import test from 'ava' -import execa from 'execa' - -// eslint-disable-next-line ava/no-skip-test -test.skip('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() -})