Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run tests without subprocess and split tests and examples #1105

Merged
merged 3 commits into from
Jan 22, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Run tests without subprocess and split tests and examples
dapplion committed Dec 19, 2019
commit 7bb999576586f914f45afea8c9c5a2e6f87fc7a3
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -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"
114 changes: 0 additions & 114 deletions packages/toolkit/examples/encode.js

This file was deleted.

3 changes: 2 additions & 1 deletion packages/toolkit/package.json
Original file line number Diff line number Diff line change
@@ -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",
119 changes: 119 additions & 0 deletions packages/toolkit/test-examples/createSingleVote.test.js
Original file line number Diff line number Diff line change
@@ -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,
}
Copy link
Contributor

@0xGabi 0xGabi Jan 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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,
}
const options = {
web3,
provider: web3.eth.currentProvider,
apm: {
ipfs: {
rpc: { protocol: 'http', host: 'localhost', port: 5001, default: true },
gateway: 'http://localhost:8080/ipfs',
},
ensRegistryAddress: '0x5f6f7e8cc7346a11ca2def8f827b7a0b612c56a1',
},
}


// Retrieve DAO template from APM.
const repo = await getApmRepo(
web3,
'membership-template.aragonpm.eth',
'latest',
options
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
options
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.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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
apm: options,
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()
}
)
13 changes: 0 additions & 13 deletions packages/toolkit/test/examples/encode.test.js

This file was deleted.