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

Refactor: Update test-helpers to web3 1.0 and include new utils #30

Closed
wants to merge 6 commits into from

Conversation

0xGabi
Copy link
Contributor

@0xGabi 0xGabi commented Apr 11, 2020

Note: On the last commit 152f97a I applied linting to the repo

@0xGabi 0xGabi requested a review from sohkai April 11, 2020 02:11
@0xGabi 0xGabi marked this pull request as ready for review April 13, 2020 20:09
@@ -0,0 +1,7 @@
const assertBn = (actual, expected, errorMsg) => {
Copy link
Contributor Author

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'
Copy link
Contributor Author

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?

Copy link
Contributor

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.

@@ -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 =>
Copy link
Contributor Author

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.

sleep 3
echo "Running testrpc-sc with pid ${rpc_pid} in port ${PORT}"
}
while ! rpc_running; do
Copy link
Contributor Author

@0xGabi 0xGabi Apr 13, 2020

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 "$@"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Use buidler

Copy link
Contributor

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')
Copy link
Contributor Author

@0xGabi 0xGabi Apr 13, 2020

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

Copy link
Contributor

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')
Copy link
Contributor Author

@0xGabi 0xGabi Apr 13, 2020

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",
Copy link
Contributor Author

@0xGabi 0xGabi Apr 13, 2020

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?

Copy link
Contributor

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"
Copy link
Contributor Author

@0xGabi 0xGabi Apr 13, 2020

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

@@ -0,0 +1,130 @@
module.exports = web3 => {
Copy link
Contributor Author

@0xGabi 0xGabi Apr 13, 2020

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,
Copy link
Contributor

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'
Copy link
Contributor

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
Copy link
Contributor

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

Copy link
Contributor Author

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) => {
Copy link
Contributor

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

Copy link

Choose a reason for hiding this comment

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

Copy link
Contributor

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

getBlockNumber,
getBlock,
sendTransaction,
getTransaction
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's alphabetize :)

return web3.eth.getBlock('latest')
}

function signatures(contract, exclude, web3, names = false, excludeConstant = false) {
Copy link
Contributor

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)),
Copy link
Contributor

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() {
Copy link
Contributor

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
Copy link
Contributor

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) => {
Copy link
Contributor

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!

@sohkai
Copy link
Contributor

sohkai commented Jul 14, 2020

Closing for #43.

@sohkai sohkai closed this Jul 14, 2020
@sohkai sohkai deleted the refactor-tests-helpers branch July 14, 2020 18:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants