From c7a9dff50db3a3f82f19f83e05119e1c0b5807ad Mon Sep 17 00:00:00 2001 From: Ben Hauser Date: Wed, 29 Apr 2020 01:13:26 +0400 Subject: [PATCH 1/4] feat: use BrownieEnvironmentWarning instead of generic UserWarning --- brownie/exceptions.py | 8 ++++++++ brownie/network/contract.py | 13 ++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/brownie/exceptions.py b/brownie/exceptions.py index c9a2cb381..84d99fe36 100644 --- a/brownie/exceptions.py +++ b/brownie/exceptions.py @@ -123,3 +123,11 @@ class UnsupportedLanguage(Exception): class InvalidPackage(Exception): pass + + +class BrownieCompilerWarning(Warning): + pass + + +class BrownieEnvironmentWarning(Warning): + pass diff --git a/brownie/network/contract.py b/brownie/network/contract.py index 20db5a5b7..cd2f525d5 100644 --- a/brownie/network/contract.py +++ b/brownie/network/contract.py @@ -24,6 +24,8 @@ get_type_strings, ) from brownie.exceptions import ( + BrownieCompilerWarning, + BrownieEnvironmentWarning, ContractExists, ContractNotFound, UndeployedLibrary, @@ -564,7 +566,8 @@ def from_explorer( warnings.warn( "No Etherscan API token set. You may experience issues with rate limiting. " "Visit https://etherscan.io/register to obtain a token, and then store it " - "as the environment variable $ETHERSCAN_TOKEN" + "as the environment variable $ETHERSCAN_TOKEN", + BrownieEnvironmentWarning, ) if not silent: @@ -600,7 +603,8 @@ def from_explorer( if not silent: warnings.warn( f"{address}: target compiler '{data['result'][0]['CompilerVersion']}' is " - "unsupported by Brownie. Some functionality will not be available." + "unsupported by Brownie. Some functionality will not be available.", + BrownieCompilerWarning, ) return cls.from_abi(name, address, abi) @@ -615,7 +619,10 @@ def from_explorer( build.update(abi=abi, natspec=implementation_contract._build["natspec"]) if not _verify_deployed_code(address, build["deployedBytecode"], build["language"]): - warnings.warn(f"{address}: Locally compiled and on-chain bytecode do not match!") + warnings.warn( + f"{address}: Locally compiled and on-chain bytecode do not match!", + BrownieCompilerWarning, + ) del build["pcMap"] self = cls.__new__(cls) From bbcfadafe138c7fb9f173b2a6e77a611b9359219 Mon Sep 17 00:00:00 2001 From: Ben Hauser Date: Wed, 29 Apr 2020 11:55:07 +0400 Subject: [PATCH 2/4] fix: warning instead of raising when dev block height > 0 --- brownie/network/main.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/brownie/network/main.py b/brownie/network/main.py index 8c37958f2..7d4f5b6d2 100644 --- a/brownie/network/main.py +++ b/brownie/network/main.py @@ -1,10 +1,12 @@ #!/usr/bin/python3 +import warnings from typing import Optional, Tuple, Union from brownie import project from brownie._config import CONFIG from brownie.convert import Wei +from brownie.exceptions import BrownieEnvironmentWarning from .account import Accounts from .rpc import Rpc, _notify_registry @@ -24,8 +26,6 @@ def connect(network: str = None, launch_rpc: bool = True) -> None: raise ConnectionError(f"Already connected to network '{CONFIG.active_network['id']}'") try: active = CONFIG.set_active_network(network) - if "host" not in active: - raise KeyError(f"No host in brownie-config.json for network '{active['id']}'") host = active["host"] if ":" not in host.split("//", maxsplit=1)[-1]: @@ -38,7 +38,10 @@ def connect(network: str = None, launch_rpc: bool = True) -> None: if CONFIG.network_type == "development" and launch_rpc and not rpc.is_active(): if is_connected(): if web3.eth.blockNumber != 0: - raise ValueError("Local RPC Client has a block height > 0") + warnings.warn( + f"Development network has a block height of {web3.eth.blockNumber}", + BrownieEnvironmentWarning, + ) rpc.attach(host) else: rpc.launch(active["cmd"], **active["cmd_settings"]) From 15abb8071222968b7fb57fbf3da439c2bc5751eb Mon Sep 17 00:00:00 2001 From: Ben Hauser Date: Wed, 29 Apr 2020 12:47:59 +0400 Subject: [PATCH 3/4] docs: add warning classes --- docs/api-brownie.rst | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/docs/api-brownie.rst b/docs/api-brownie.rst index fc9e19efe..c5803c7ff 100644 --- a/docs/api-brownie.rst +++ b/docs/api-brownie.rst @@ -18,7 +18,10 @@ The ``brownie`` package is the main package containing all of Brownie's function ``brownie.exceptions`` ====================== -The ``exceptions`` module contains all Brownie ``Exception`` classes. +The ``exceptions`` module contains all Brownie :class:`Exception` and :class:`Warning` classes. + +Exceptions +---------- .. py:exception:: brownie.exceptions.CompilerError @@ -74,7 +77,7 @@ The ``exceptions`` module contains all Brownie ``Exception`` classes. .. py:exception:: brownie.exceptions.UnknownAccount - Raised when the :func:`Accounts ` container cannot locate a specified `Account ` object. + Raised when the :func:`Accounts ` container cannot locate a specified :func:`Account ` object. .. py:exception:: brownie.exceptions.UnsetENSName @@ -86,7 +89,7 @@ The ``exceptions`` module contains all Brownie ``Exception`` classes. .. py:exception:: brownie.exceptions.RPCConnectionError - Raised when the RPC process is active and `web3 ` is connected, but Brownie is unable to communicate with it. + Raised when the RPC process is active and :func:`web3 ` is connected, but Brownie is unable to communicate with it. .. py:exception:: brownie.exceptions.RPCProcessError @@ -100,6 +103,17 @@ The ``exceptions`` module contains all Brownie ``Exception`` classes. Raised when a contract call causes the EVM to revert. +Warnings +-------- + +.. py:exception:: brownie.exceptions.BrownieCompilerWarning + + Raised by :func:`Contract.from_explorer ` when a contract cannot be compiled, or compiles successfully but produces unexpected bytecode. + +.. py:exception:: brownie.exceptions.BrownieEnvironmentWarning + + Raised on unexpected environment conditions. + ``brownie._config`` =================== @@ -118,7 +132,7 @@ ConfigDict .. py:class:: brownie._config.ConfigDict - Subclass of `dict `_ that prevents adding new keys when locked. Used to hold config file settings. + Subclass of :class:`dict` that prevents adding new keys when locked. Used to hold config file settings. .. code-block:: python @@ -132,7 +146,7 @@ ConfigDict Internal Methods .. py:classmethod:: ConfigDict._lock - Locks the :func:`ConfigDict `. When locked, attempts to add a new key will raise a ``KeyError``. + Locks the :func:`ConfigDict `. When locked, attempts to add a new key will raise a :class:`KeyError`. .. code-block:: python @@ -155,7 +169,7 @@ ConfigDict Internal Methods .. py:classmethod:: ConfigDict._copy - Returns a copy of the object as a ``dict``. + Returns a copy of the object as a :class:`dict`. ``brownie._singleton`` ====================== From 40a6c69b5223a70b58afd8ef85b93fd79a22cdf5 Mon Sep 17 00:00:00 2001 From: Ben Hauser Date: Wed, 29 Apr 2020 12:48:21 +0400 Subject: [PATCH 4/4] docs: add web3py intersphinx references --- docs/api-network.rst | 14 +++++++------- docs/conf.py | 1 + docs/core-contracts.rst | 6 +++--- docs/core-types.rst | 2 +- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/docs/api-network.rst b/docs/api-network.rst index 159c0a02d..1c910cca6 100644 --- a/docs/api-network.rst +++ b/docs/api-network.rst @@ -62,7 +62,7 @@ The ``main`` module contains methods for conncting to or disconnecting from the * If no argument is given, the current default is displayed. * If an integer value is given, this will be the default gas limit. - * If set to ``auto``, the gas limit is determined automatically via ``web3.eth.estimateGas``. + * If set to ``auto``, the gas limit is determined automatically via :meth:`web3.eth.estimateGas `. Returns ``False`` if the gas limit is set automatically, or an ``int`` if it is set to a fixed value. @@ -81,7 +81,7 @@ The ``main`` module contains methods for conncting to or disconnecting from the Gets and optionally sets the default gas price. * If an integer value is given, this will be the default gas price. - * If set to ``auto``, the gas price is determined automatically via ``web3.eth.getPrice``. + * If set to ``auto``, the gas price is determined automatically via :attr:`web3.eth.gasPrice `. Returns ``False`` if the gas price is set automatically, or an ``int`` if it is set to a fixed value. @@ -204,7 +204,7 @@ Account .. py:class:: brownie.network.account.Account - An ethereum address that you control the private key for, and so can send transactions from. Generated automatically from ``web3.eth.accounts`` and stored in the :func:`Accounts ` container. + An ethereum address that you control the private key for, and so can send transactions from. Generated automatically from :attr:`web3.eth.accounts ` and stored in the :func:`Accounts ` container. .. code-block:: python @@ -318,7 +318,7 @@ LocalAccount .. py:class:: brownie.network.account.LocalAccount - Functionally identical to :func:`Account `. The only difference is that a ``LocalAccount`` is one where the private key was directly inputted, and so is not found in ``web3.eth.accounts``. + Functionally identical to :func:`Account `. The only difference is that a ``LocalAccount`` is one where the private key was directly inputted, and so is not found in :attr:`web3.eth.accounts `. .. note:: Resetting the RPC client will delete all ``LocalAccount`` objects from the :func:`Account ` container. @@ -2122,16 +2122,16 @@ TransactionReceipt Methods ``brownie.network.web3`` ======================== -The ``web3`` module contains a slightly modified version of the web3.py ``Web3`` class that is used throughout various Brownie modules for RPC communication. +The ``web3`` module contains a slightly modified version of the web3.py :class:`Web3 ` class that is used throughout various Brownie modules for RPC communication. Web3 ---- -See the `Web3 API documentation `_ for detailed information on all the methods and attributes available here. This document only outlines methods that differ from the normal ``Web3`` public interface. +See the `Web3 API documentation `_ for detailed information on all the methods and attributes available here. This document only outlines methods that differ from the normal :class:`Web3 ` public interface. .. py:class:: brownie.network.web3.Web3 - Brownie subclass of ``Web3``. An instance is created at ``brownie.network.web3.web`` and available for import from the main package. + Brownie subclass of :class:`Web3 `. An instance is created at ``brownie.network.web3.web`` and available for import from the main package. .. code-block:: python diff --git a/docs/conf.py b/docs/conf.py index 1883e379f..30917c6d4 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -196,4 +196,5 @@ def setup(sphinx): "hypothesis": ("https://hypothesis.readthedocs.io/en/latest", None), "pytest": ("https://docs.pytest.org/en/latest/", None), "python": ("https://docs.python.org/3.8/", None), + "web3py": ("https://web3py.readthedocs.io/en/stable/", None), } diff --git a/docs/core-contracts.rst b/docs/core-contracts.rst index 199bf7b8c..ed3637278 100644 --- a/docs/core-contracts.rst +++ b/docs/core-contracts.rst @@ -140,15 +140,15 @@ Transaction Parameters When executing a transaction to a contract, you can optionally include a :py:class:`dict ` of transaction parameters as the final input. It may contain the following values: * ``from``: the :func:`Account ` that the transaction it sent from. If not given, the transaction is sent from the account that deployed the contract. - * ``gas_limit``: The amount of gas provided for transaction execution, in wei. If not given, the gas limit is determined using ``web3.eth.estimateGas``. - * ``gas_price``: The gas price for the transaction, in wei. If not given, the gas price is set according to ``web3.eth.getPrice``. + * ``gas_limit``: The amount of gas provided for transaction execution, in wei. If not given, the gas limit is determined using :meth:`web3.eth.estimateGas `. + * ``gas_price``: The gas price for the transaction, in wei. If not given, the gas price is set according to :attr:`web3.eth.gasPrice `. * ``amount``: The amount of Ether to include with the transaction, in wei. All integer values can also be given as strings that will be converted by :func:`Wei `. .. note:: - To maintain compatibility with ``web3.eth.sendTransaction``, you can use ``gas``, ``gasPrice`` and ``value`` as aliases for ``gas_limit``, ``gas_price``, and ``amount``. + To maintain compatibility with :meth:`web3.eth.sendTransaction `, you can use ``gas``, ``gasPrice`` and ``value`` as aliases for ``gas_limit``, ``gas_price``, and ``amount``. Calls ----- diff --git a/docs/core-types.rst b/docs/core-types.rst index c655d8fdf..4b96899df 100644 --- a/docs/core-types.rst +++ b/docs/core-types.rst @@ -57,7 +57,7 @@ The :func:`Fixed ` class is used to handle Vype True -Attempting to assign, compare or perform arithmetic against a float raises a ``TypeError``. +Attempting to assign, compare or perform arithmetic against a float raises a :class:`TypeError`. .. code-block:: python