-
Notifications
You must be signed in to change notification settings - Fork 79
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
+132
−129
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
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
commit 7bb999576586f914f45afea8c9c5a2e6f87fc7a3
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
packages/toolkit/test-examples/createSingleVote.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||||||
} | ||||||
|
||||||
// Retrieve DAO template from APM. | ||||||
const repo = await getApmRepo( | ||||||
web3, | ||||||
'membership-template.aragonpm.eth', | ||||||
'latest', | ||||||
options | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
) | ||||||
|
||||||
// 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, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
}) | ||||||
|
||||||
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() | ||||||
} | ||||||
) |
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.