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

Add documentation on how to do unit tests with web3.py #1324

Merged
merged 2 commits into from
Apr 18, 2019

Conversation

relyt29
Copy link
Contributor

@relyt29 relyt29 commented Apr 11, 2019

What was wrong?

The python ecosystem in general is sorely in need of updated documentation of how to do unit testing of solidity contracts with python. Something along the lines of: https://github.com/ethereum/pyethereum/wiki/Using-pyethereum.tester

How was it fixed?

I wrote said example documentation.

Cute Animal Picture

Copy link
Member

@pipermerriam pipermerriam left a comment

Choose a reason for hiding this comment

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

I'm 👍 on this, however, wondering if you would be up to converting this to use pytest. If we're going to steer people towards anything I'd prefer it be that. I recognize unittest is standard library and thus slightly less complex for example purposes, but I think there's value in demonstrating how this can be done using pytest with fixtures for a very clean testing environment.

If you're not familiar with pytest then potentially @njgheorghita or @kclowes could do this conversion.

@relyt29
Copy link
Contributor Author

relyt29 commented Apr 11, 2019

happy to rewrite this in pytest, give me 10 minutes

@pipermerriam
Copy link
Member

might be nice to actually write this as a file under the ./tests directory and use the include directives to inline the file where you want it displayed. This should ensure that this example test always actually works if someone wishes to copy/paste it from the docs.

@lorenzb
Copy link

lorenzb commented Apr 11, 2019

w00t

One suggestion: it might be useful to log an event from the contract and check its correctness from the example test.

@relyt29
Copy link
Contributor Author

relyt29 commented Apr 11, 2019

right, I intended to do that originally when I added the event and then forgot about it, thanks

@relyt29 relyt29 force-pushed the master branch 4 times, most recently from 006373e to e6bfd26 Compare April 12, 2019 18:14
@relyt29
Copy link
Contributor Author

relyt29 commented Apr 12, 2019

Okay I think this should be good for another review, I added code to check against an emitted event, and moved the code into the tests to be run with the test suite. Apologies if I put the file in the wrong place, I did my best guess and put it in the core/contracts directory.

@pipermerriam
Copy link
Member

Will try to go over this and get it merged monday. Thanks for writing this up.

Copy link
Collaborator

@kclowes kclowes left a comment

Choose a reason for hiding this comment

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

Thank you so much for putting this together! This is awesome.

These docs aren't quite showing up the way that you intended. I added some comments on how to fix. You can run make docs to build them locally.

docs/examples.rst Outdated Show resolved Hide resolved
docs/examples.rst Outdated Show resolved Hide resolved
tests/core/contracts/test_contract_example.py Outdated Show resolved Hide resolved
tests/core/contracts/test_contract_example.py Outdated Show resolved Hide resolved
docs/examples.rst Outdated Show resolved Hide resolved
@relyt29
Copy link
Contributor Author

relyt29 commented Apr 17, 2019

Okay, made changes, thanks for the helpful hint on how to render the documentation locally - I think this should be good for another review

@pipermerriam
Copy link
Member

@kclowes I pushed a commit to this updating the test structure a bit (mostly just personal preference). I'll leave it to you to do final review + merge.

@kclowes
Copy link
Collaborator

kclowes commented Apr 17, 2019

Sweet! 🚀 Thanks @relyt29 and @pipermerriam!

@kclowes kclowes merged commit 5102321 into ethereum:master Apr 18, 2019
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.

4 participants