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

test-helpers: re-organize, update to web3 1.0, and add utilities from dao-templates, react-boilerplate #43

Merged
merged 16 commits into from
Jul 15, 2020

Conversation

sohkai
Copy link
Contributor

@sohkai sohkai commented Jul 14, 2020

Replaces #30 with a more aggressive re-organization. Takes the useful utilities from dao-templates and aragon-react-boilerplate (fixes #28).

dcda933 is the primary commit with changes to add new or refactor existing utilities.

Utilities from @aragon/contract-helpers-test are now grouped into separate sections:

  • root: base utilities for Ethereum-related interactions
  • asserts: Ethereum-related assertions
  • aragon-os: aragonOS-related utilities
  • aragon-os/asserts: aragonOS-related assertions

It now also includes the concept of a "configuration", shamelessly inspired by Open Zeppelin's own test helpers, that will detect the global truffle environment or allow a user to override and inject their own.

Future PRs:

  • Test with real repos
  • Write exhaustive documentation (similar to the mock contracts)

? await blockOrPromise()
: await blockOrPromise
} catch (error) {
if (isGeth(ctx)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This part is a bit sketchy and taken from dao-templates.

I think this should still work on an Istanbul context, but I won't know until we try 😄.

In any case, my philosophy here is to ensure we can use the same utilities regardless of ganache or a real chain and we can certainly come back to this to fix it if it doesn't end up working well.

Copy link
Contributor

@facuspagnuolo facuspagnuolo left a comment

Choose a reason for hiding this comment

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

LGTM!

Comment on lines 6 to 7
bn(actual).toString(),
bn(expected).toString(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Bear in mind this may not work for different versions of BN, I prefer being flexible here. Calling .toString() to any type of BN seems safer to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in 9bebc4d.

Comment on lines +6 to +7
function normalizeArg(arg) {
if (isBN(arg)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

There were some versions of web3-utils that do not include isBN.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is likely from the 0.2 series—I think since the 1.0 series started, and they moved over the bn.js, this has existed.

return arg.toString()
} else if (isAddress(arg)) {
return toChecksumAddress(arg)
}
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 contemplate the case of comparing contracts with addresses: see #35 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh interesting, so that's why that was there. I'll add it back!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in 762277e.

Copy link
Contributor

@0xGabi 0xGabi left a comment

Choose a reason for hiding this comment

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

I like the new structure!

@sohkai sohkai merged commit 5697f60 into master Jul 15, 2020
@sohkai sohkai deleted the test-helpers-reorganize branch July 15, 2020 16:51
@@ -0,0 +1,13 @@
const EMPTY_BYTES = '0x'
const ZERO_BYTES32 =
'0x0000000000000000000000000000000000000000000000000000000000000000'
Copy link

Choose a reason for hiding this comment

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

What about '0x' + '0'.repeat(64)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Works as well! We can do so for addresses as well :).

Can you push a PR?

Copy link

Choose a reason for hiding this comment

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

Sure, I’ll do!

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.

Move dao creation as used in aragon-react-boilerplate to contract-helpers and use in all templates
4 participants