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

Validate ethereum_tester class in web3.EthereumTesterProvider #1217

Merged

Conversation

njgheorghita
Copy link
Contributor

@njgheorghita njgheorghita commented Jan 18, 2019

What was wrong?

Instantiating a provider with PyEVMBackend should be done like web3 = Web3(Web3.EthereumTesterProvider(EthereumTester(PyEVMBackend()))), but can be mistakenly instantiated without the EthereumTester which will cause tx normalization errors.

fixes #1213
fixes #1212

Also dropped the already deprecated web3.soliditySha3 method in this pr.

How was it fixed?

Added a check in EthereumTesterProvider.init() that the ethereum_tester arg is one of

  1. instance of EthereumTester
  2. instance of PyEVMBackend and then auto-wraps it in EthereumTester
  3. raise error

Cute Animal Picture

image

see the ``eth-tester`` library documentation for details.
This provider integrates with the ``eth-tester`` library. The ``eth_tester`` constructor
argument should be an instance of the :class:`~eth_tester.EthereumTester` or
:class:`~eth_tester.PyEVMBackend` class provided by the ``eth-tester`` library.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure if encouraging the use of PyEVMBackend directly is a good idea or not in the docs. Is it better to just promote that eth_tester.EthereumTester is the only way to instantiate an EthereumTesterProvider instance, and the code will be silently forgiving to anybody who mistakenly provides an unwrapped PyEVMBackend?

Copy link
Member

Choose a reason for hiding this comment

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

I think it's good to document it here as not doing so might lead to the alternate surprise of why it works without wrapping the backend. However, maybe noting the PyEVMBackend specifically could be replaced by indicating that any subclass of the BaseBackend class is allowed.

@njgheorghita njgheorghita force-pushed the validate-eth-tester-backend-class branch 2 times, most recently from 69a90e3 to 96d4c2e Compare January 18, 2019 13:09
see the ``eth-tester`` library documentation for details.
This provider integrates with the ``eth-tester`` library. The ``eth_tester`` constructor
argument should be an instance of the :class:`~eth_tester.EthereumTester` or
:class:`~eth_tester.PyEVMBackend` class provided by the ``eth-tester`` library.
Copy link
Member

Choose a reason for hiding this comment

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

I think it's good to document it here as not doing so might lead to the alternate surprise of why it works without wrapping the backend. However, maybe noting the PyEVMBackend specifically could be replaced by indicating that any subclass of the BaseBackend class is allowed.

@@ -30,12 +30,22 @@ class EthereumTesterProvider(BaseProvider):
api_endpoints = None

def __init__(self, ethereum_tester=None, api_endpoints=None):
# do not import eth_tester until runtime, it is not a default dependency
from eth_tester import EthereumTester, PyEVMBackend
Copy link
Member

Choose a reason for hiding this comment

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

Instead of PyEVMBackend this should be the BaseChainBackend class.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@pipermerriam That's what I thought at first as well, but then from what I can tell PyEVMBackend is not a subclass of BaseChainBackend - https://github.com/ethereum/eth-tester/blob/91468f5f79/eth_tester/backends/pyevm/main.py#L295

Copy link
Member

Choose a reason for hiding this comment

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

That's a bug we should remedy. I'll open an issue.

self.ethereum_tester = EthereumTester()
else:
self.ethereum_tester = ethereum_tester
if isinstance(ethereum_tester, EthereumTester):
Copy link
Member

Choose a reason for hiding this comment

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

Instead of nesting this in the else, this could all be one large if/elif/elif clause.

if isinstance(ethereum_tester, EthereumTester):
self.ethereum_tester = ethereum_tester
elif isinstance(ethereum_tester, PyEVMBackend):
self.ethereum_tester = EthereumTester(ethereum_tester)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I find it a little odd to be able to pass the tester or the backend, but no objection 👍

@njgheorghita njgheorghita force-pushed the validate-eth-tester-backend-class branch from 96d4c2e to 93cc27e Compare January 22, 2019 10:00
@njgheorghita njgheorghita merged commit d0a379c into ethereum:master Jan 22, 2019
@njgheorghita njgheorghita deleted the validate-eth-tester-backend-class branch January 22, 2019 10:13
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.

web3.eth.getBlock is broken with PyEVMBackend Deploying a contract is broken with PyEVMBackend()
3 participants