-
Notifications
You must be signed in to change notification settings - Fork 13
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
Refactor: Update test-helpers to web3 1.0 and include new utils #30
Conversation
@@ -0,0 +1,7 @@ | |||
const assertBn = (actual, expected, errorMsg) => { |
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.
Move asserts under the same path.
@@ -0,0 +1,2 @@ | |||
export const ANY_ADDRESS = '0xffffffffffffffffffffffffffffffffffffffff' |
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.
Include the two constant used very frequently. Do you think there are others that make sense?
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.
I'm wondering if we shouldn't have an "ACL" scope for some of these utilities, to include the "any" and "burned" addresses.
Maybe a contract-helpers-os
package or similar. We're starting to mix some generic solidity testing utilities with utilities specifically designed to be used on aragonOS.
packages/test-helpers/events.js
Outdated
@@ -8,8 +8,10 @@ const getEventArgument = (receipt, event, arg, index = 0) => | |||
getEventAt(receipt, event, index).args[arg] | |||
const getNewProxyAddress = receipt => | |||
getEventArgument(receipt, 'NewAppProxy', 'proxy') | |||
const getNewDaoAddress = receipt => |
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.
Include a helper to get the DeployDAO
event.
packages/test-helpers/ganache-cli.sh
Outdated
sleep 3 | ||
echo "Running testrpc-sc with pid ${rpc_pid} in port ${PORT}" | ||
} | ||
while ! rpc_running; do |
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.
Add logic to test rpc connection is open using Netcat
start_testrpc | ||
measure_coverage $@ | ||
start_ganache | ||
node_modules/.bin/buidler coverage --network coverage "$@" |
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.
Use buidler
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.
Maybe we can specify these bits as arguments to this script. As it is, we're forcing users to always use buidler.
This is not necessarily bad, but the way I see this script is that it sets up the local ganache environment to run a test or coverage script, whichever script that is.
@@ -1,9 +1,10 @@ | |||
const abi = require('ethereumjs-abi') | |||
|
|||
const createExecutorId = id => `0x${String(id).padStart(8, '0')}` | |||
const { bn } = require('./lib/numbers') |
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.
Put all Aragon helpers in a single file
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.
Ah I mentioned above, but I've been thinking of moving this to a separate package altogether so it's more clear.
We have a lot more helpers than just the ones listed here that are only relevant to aragonOS.
@@ -0,0 +1,5 @@ | |||
const { hash: namehash } = require('eth-ens-namehash') |
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.
Expose namehash
as helper.
@@ -1,20 +1,24 @@ | |||
{ | |||
"name": "@aragon/contract-helpers-test", | |||
"version": "0.0.2", | |||
"name": "@aragon/test-helpers", |
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.
I finally choose to keep using the same test-helpers
namespace. And maybe we do a major release?
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.
I've been thinking that test-helpers
is a bit too generic, since we have frontend and contract testing.
Maybe we can publish under @aragon/contract-test-helpers
? And in the future we can have @aragon/fe-test-helpers
(or similar)?
"solidity-coverage": "^0.6.2" | ||
"ganache-cli": "^6.9.1", | ||
"solidity-coverage": "^0.7.4", | ||
"web3": "^1.0.0" |
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.
I included web3 as peerDependency
to force to update from 0.2.x
packages/test-helpers/lib/web3.js
Outdated
@@ -0,0 +1,130 @@ | |||
module.exports = web3 => { |
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.
I decided to use a single web3 helper file as we have in aragonOS. What do you think?
@@ -0,0 +1,23 @@ | |||
{ | |||
"env": { | |||
"browser": true, |
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.
We most likely shouldn't set browser
to be true—this is primarily for a node environment.
@@ -0,0 +1,2 @@ | |||
export const ANY_ADDRESS = '0xffffffffffffffffffffffffffffffffffffffff' |
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.
I'm wondering if we shouldn't have an "ACL" scope for some of these utilities, to include the "any" and "burned" addresses.
Maybe a contract-helpers-os
package or similar. We're starting to mix some generic solidity testing utilities with utilities specifically designed to be used on aragonOS.
method: 'evm_mine', | ||
id: new Date().getTime() | ||
}) | ||
return web3.eth.getBlock('latest').hash |
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.
We almost definitely need to use an await
on getBlock()
first before accessing hash
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.
Ouch! Good catch
return web3.eth.getBlock('latest') | ||
} | ||
|
||
const advanceTimeAndBlocksBy = async (time, numOfBlocks) => { |
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.
Are these time/block controlling utilities used by the court tests? We should usually shy away from these types of utilities, because they aren't usable in an environment outside of ganache.
If they are, I would still push for them to be scoped in a different namespace, e.g. time-control
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.
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.
Made an issue to add these back in! #46
packages/test-helpers/lib/web3.js
Outdated
getBlockNumber, | ||
getBlock, | ||
sendTransaction, | ||
getTransaction |
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.
Let's alphabetize :)
packages/test-helpers/lib/web3.js
Outdated
return web3.eth.getBlock('latest') | ||
} | ||
|
||
function signatures(contract, exclude, web3, names = false, excludeConstant = false) { |
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.
I'm not super sure this util is relevant as a general util, and this type of thing is usually already done by the contract library that's being used (via an encoding function or otherwise).
What do you think about removing it?
const signedPayload = await web3.eth.sign(address, payload) | ||
const adding0x = x => '0x'.concat(x) | ||
return { | ||
r: adding0x(signedPayload.substr(2, 64)), |
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.
Some comments here would be really useful!
I'm also not sure if the way we have this is fully generic and usable by scenarios where we need to create these signature fields, but good to ask Facu on this.
We may also want to come up with a different name, e.g. deriveSignatureRSV()
or etc.
GAS_LIMIT=${GAS_LIMIT-8000000} | ||
NETWORK_ID=${NETWORK_ID-15} | ||
ACCOUNTS=${ACCOUNTS-200} | ||
rpc_running() { |
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.
There are two rpc_running
definitions now
rpc_pid=$! | ||
echo "Waiting for ganache to launch on port "$PORT"..." | ||
if [ "$SOLIDITY_COVERAGE" = true ]; then | ||
export RUNNING_COVERAGE=true |
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.
Interesting, do we not need to set up the coverage-testrpc if we're using builder?
@@ -0,0 +1,134 @@ | |||
module.exports = (web3) => { |
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.
I ended up not including most of these in #43.
I'm open to adding them—let's confirm a use case first!
Closing for #43. |
Note: On the last commit 152f97a I applied linting to the repo