Skip to content

Commit

Permalink
Merge pull request #1422 from eth-brownie/v1.18.0
Browse files Browse the repository at this point in the history
v1.18.0
  • Loading branch information
iamdefinitelyahuman authored Feb 14, 2022
2 parents 52fdd96 + e7c3f3a commit 3aecd87
Show file tree
Hide file tree
Showing 42 changed files with 259 additions and 252 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/core-ganache-3.7.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
uses: actions/setup-node@v1

- name: Install Ganache
run: npm install -g ganache-cli@6.12.2
run: npm install -g ganache@7.0.2

- name: Setup Python 3.7
uses: actions/setup-python@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/core-ganache-3.8.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
uses: actions/setup-node@v1

- name: Install Ganache
run: npm install -g ganache-cli@6.12.2
run: npm install -g ganache@7.0.2

- name: Setup Python 3.8
uses: actions/setup-python@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/core-ganache-3.9.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
uses: actions/setup-node@v1

- name: Install Ganache
run: npm install -g ganache-cli@6.12.2
run: npm install -g ganache@7.0.2

- name: Setup Python 3.9
uses: actions/setup-python@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/evm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
uses: actions/setup-node@v1

- name: Install Ganache
run: npm install -g ganache-cli@6.12.2
run: npm install -g ganache@7.0.2

- name: Setup Python 3.8
uses: actions/setup-python@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/functionality.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
uses: actions/setup-node@v1

- name: Install Ganache
run: npm install -g ganache-cli@6.12.2
run: npm install -g ganache@7.0.2

- name: Setup Python 3.8
uses: actions/setup-python@v2
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ repos:
- id: isort

- repo: https://github.com/psf/black
rev: 21.9b0
rev: 22.1.0
hooks:
- id: black
name: black
Expand Down
22 changes: 11 additions & 11 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ This changelog format is based on [Keep a Changelog](https://keepachangelog.com/
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased](https://github.com/eth-brownie/brownie)

## [1.18.0](https://github.com/eth-brownie/brownie/tree/v1.18.0) - 2022-02-14
### Added
- Allow to override EVM version per language
- Add support for Ganache 7 CLI flags
- Support Ganache unlimited contract size
- Support for Ganache v7 ([#1409](https://github.com/eth-brownie/brownie/pull/1409), [#1410](https://github.com/eth-brownie/brownie/pull/1410))
- Add `override` argument to contract methods which allows changing the state before the call ([#1412](https://github.com/eth-brownie/brownie/pull/1412))
- Allow to override EVM version per language ([#1418](https://github.com/eth-brownie/brownie/pull/1418))
- Support for Alchemy via `WEB3_ALCHEMY_PROJECT_ID` environment var ([#1401](https://github.com/eth-brownie/brownie/pull/1401))
- Support Ganache unlimited contract size ([#1424](https://github.com/eth-brownie/brownie/pull/1424))

### Changed
- Force files to be opened as UTF-8
- Added a new solidity compiler setting `use_latest_patch` in brownie-config.yaml to use the latest patch version of a compiler based on the pragma version of the contract.
- Add cli flag `-r` for raising exceptions to the caller instead of doing a system exit.
- Added support for alchemy out of the box with a `WEB3_ALCHEMY_PROJECT_ID` after running `brownie networks set_provider alchemy`.
- Add `override` argument to contract methods which allows changing the state before the call, including overwriting balance, nonce, code, and storage of any address.
- Add `persist` argument (default=`True`) to contract methods that controls if the contract should be added to the deployments db. Disabled the deployments for interfaces to make them ephemereal ([#1092](https://github.com/eth-brownie/brownie/issues/1092)). Added a `Contract.remove_deployment(address)` class helper method.
- Added a new solidity compiler setting `use_latest_patch` in `brownie-config.yaml` to use the latest patch version of a compiler based on the pragma version of the contract ([#1383](https://github.com/eth-brownie/brownie/pull/1383))
- Add cli flag `-r` for raising exceptions to the caller instead of doing a system exit ([#1394](https://github.com/eth-brownie/brownie/pull/1394))

### Fixed
- Improve support for Ganache 7 reverted transactions
- Fix incremental compilation failing because of mismatching compiler versions
- Force files to be opened as UTF-8 ([#1377](https://github.com/eth-brownie/brownie/pull/1377))
- Fix incremental compilation failing because of mismatching compiler versions ([#1411](https://github.com/eth-brownie/brownie/pull/1411))

## [1.17.2](https://github.com/eth-brownie/brownie/tree/v1.17.2) - 2021-12-04
### Changed
Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ Brownie is a Python-based development and testing framework for smart contracts
* Property-based and stateful testing via [`hypothesis`](https://github.com/HypothesisWorks/hypothesis/tree/master/hypothesis-python)
* Powerful debugging tools, including python-style tracebacks and custom error strings
* Built-in console for quick project interaction
* Support for [ethPM](https://www.ethpm.com) packages

## Dependencies

* [python3](https://www.python.org/downloads/release/python-368/) version 3.6 or greater, python3-dev
* [ganache-cli](https://github.com/trufflesuite/ganache-cli) - tested with version [6.12.2](https://github.com/trufflesuite/ganache-cli/releases/tag/v6.12.2)
* [python3](https://www.python.org/downloads/release/python-3910/) version 3.7 or greater, python3-dev
* [ganache](https://github.com/trufflesuite/ganache) - tested with version [7.0.2](https://github.com/trufflesuite/ganache/releases/tag/v7.0.2)

## Installation

Expand Down
2 changes: 1 addition & 1 deletion brownie/_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from brownie._expansion import expand_posix_vars
from brownie._singleton import _Singleton

__version__ = "1.17.2"
__version__ = "1.18.0"

BROWNIE_FOLDER = Path(__file__).parent
DATA_FOLDER = Path.home().joinpath(".brownie")
Expand Down
2 changes: 1 addition & 1 deletion brownie/convert/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def to_int(value: Any, type_str: str = "int256") -> Wei:
def to_decimal(value: Any) -> Fixed:
"""Convert a value to a fixed point decimal"""
d: Fixed = Fixed(value)
if d < -(2 ** 127) or d >= 2 ** 127:
if d < -(2**127) or d >= 2**127:
raise OverflowError(f"{value} is outside allowable range for decimal")
if d.quantize(Decimal("1.0000000000")) != d:
raise ValueError("Maximum of 10 decimal points allowed")
Expand Down
2 changes: 1 addition & 1 deletion brownie/convert/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def get_int_bounds(type_str: str) -> Tuple[int, int]:
if size < 8 or size > 256 or size % 8:
raise ValueError(f"Invalid type: {type_str}")
if type_str.startswith("u"):
return 0, 2 ** size - 1
return 0, 2**size - 1
return -(2 ** (size - 1)), 2 ** (size - 1) - 1


Expand Down
8 changes: 8 additions & 0 deletions brownie/data/network-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ live:
host: https://api.harmony.one
id: harmony-main
multicall2: "0x3E01dD8a5E1fb3481F0F589056b428Fc308AF0Fb"
- name: Moonbeam
networks:
- name: Mainnet
chainid: 1284
id: moonbeam-main
host: https://moonbeam.api.onfinality.io/public
explorer: https://api-moonbeam.moonscan.io/api
multicall2: "0x1337BedC9D22ecbe766dF105c9623922A27963EC"
- name: Optimistic Ethereum
networks:
- name: Mainnet
Expand Down
13 changes: 1 addition & 12 deletions brownie/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,18 +116,7 @@ def __init__(self, exc: ValueError) -> None:
txid, data = next((k, v) for k, v in exc["data"].items() if k.startswith("0x"))
self.revert_type = data["error"]
except StopIteration:
data = exc["data"]
result = data.get("result")
if (
not isinstance(result, str)
or not result.startswith(ERROR_SIG)
or "message" not in data
):
raise ValueError(exc["message"]) from None
txid = ""
self.revert_type = data["message"]
if "programCounter" in data:
data["program_counter"] = data["programCounter"]
raise ValueError(exc["message"]) from None

self.txid = txid
self.source = ""
Expand Down
6 changes: 3 additions & 3 deletions brownie/network/gas/strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def get_gas_price(self) -> Generator[Wei, None, None]:
yield last_gas_price

for i in itertools.count(1):
last_gas_price = Wei(last_gas_price * 1.1 ** i)
last_gas_price = Wei(last_gas_price * 1.1**i)
yield min(last_gas_price, self.max_gas_price)


Expand Down Expand Up @@ -164,7 +164,7 @@ def __init__(
self.initial_speed = initial_speed
self.max_speed = max_speed
self.increment = increment
self.max_gas_price = Wei(max_gas_price) or 2 ** 256 - 1
self.max_gas_price = Wei(max_gas_price) or 2**256 - 1

def get_gas_price(self) -> Generator[int, None, None]:
last_gas_price = _fetch_gasnow(self.initial_speed)
Expand Down Expand Up @@ -207,7 +207,7 @@ def __init__(
if graphql_endpoint is None:
graphql_endpoint = f"{web3.provider.endpoint_uri}/graphql" # type: ignore
self.graphql_endpoint = graphql_endpoint
self.max_gas_price = Wei(max_gas_price) or 2 ** 256 - 1
self.max_gas_price = Wei(max_gas_price) or 2**256 - 1

def get_gas_price(self) -> Generator[int, None, None]:
query = "{ pending { transactions { gasPrice }}}"
Expand Down
47 changes: 47 additions & 0 deletions brownie/network/middlewares/ganache7.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from typing import Callable, Dict, List, Optional

from web3 import Web3

from brownie.network.middlewares import BrownieMiddlewareABC


class Ganache7MiddleWare(BrownieMiddlewareABC):
@classmethod
def get_layer(cls, w3: Web3, network_type: str) -> Optional[int]:
if w3.clientVersion.lower().startswith("ganache/v7"):
return -100
else:
return None

def process_request(self, make_request: Callable, method: str, params: List) -> Dict:
result = make_request(method, params)

# reformat failed eth_call / eth_sendTransaction output to mimick that of Ganache 6.x
# yes, this is hacky and awful and in the future we should stop supporting
# the older version of ganache. but doing so will cause unexpected issues
# in projects that are still pinned to the old verion, so for now we support
# both and simply raise a warning of a pending deprecation.
if (
method in ("eth_sendTransaction", "eth_sendRawTransaction")
and "error" in result
and "data" in result["error"]
):
data = result["error"]["data"]
data["error"] = data.pop("message")
data["program_counter"] = data.pop("programCounter")
result["error"]["data"] = {data.pop("hash"): data}

if (
method == "eth_call"
and "error" in result
and result["error"].get("message", "").startswith("VM Exception")
):
# "VM Exception while processing transaction: {reason} {message}"
msg = result["error"]["message"].split(": ", maxsplit=1)[-1]
if msg.startswith("revert"):
data = {"error": "revert", "reason": msg[7:]}
else:
data = {"error": msg, "reason": None}
result["error"]["data"] = {"0x": data}

return result
5 changes: 4 additions & 1 deletion brownie/network/middlewares/hardhat.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ def process_request(self, make_request: Callable, method: str, params: List) ->
result = make_request(method, params)

# modify Hardhat transaction error to mimick the format that Ganache uses
if method in ("eth_call", "eth_sendTransaction") and "error" in result:
if (
method in ("eth_call", "eth_sendTransaction", "eth_sendRawTransaction")
and "error" in result
):
message = result["error"]["message"]
if message.startswith("Error: VM Exception") or message.startswith(
"Error: Transaction reverted"
Expand Down
12 changes: 11 additions & 1 deletion brownie/network/rpc/ganache.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ def launch(cmd: str, **kwargs: Dict) -> None:
cli_flags = CLI_FLAGS["<=6"]
else:
cli_flags = CLI_FLAGS["7"]
# this flag must be true so that reverting tx's return a
# more verbose output similar to what ganache 6 produced
cmd_list.extend(["--chain.vmErrorsOnRPCResponse", "true"])

kwargs.setdefault("evm_version", EVM_DEFAULT) # type: ignore
if kwargs["evm_version"] in EVM_EQUIVALENTS:
Expand Down Expand Up @@ -144,7 +147,14 @@ def revert(snapshot_id: int) -> None:


def unlock_account(address: str) -> None:
web3.provider.make_request("evm_unlockUnknownAccount", [address]) # type: ignore
if web3.clientVersion.lower().startswith("ganache/v7"):
web3.provider.make_request("evm_addAccount", [address, ""]) # type: ignore
web3.provider.make_request( # type: ignore
"personal_unlockAccount",
[address, "", 9999999999],
)
else:
web3.provider.make_request("evm_unlockUnknownAccount", [address]) # type: ignore


def _validate_cmd_settings(cmd_settings: dict) -> dict:
Expand Down
6 changes: 3 additions & 3 deletions brownie/network/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,14 @@ def __init__(
if not self._silent:
output_str = ""
if self.type == 2:
max_gas = tx["maxFeePerGas"] / 10 ** 9
priority_gas = tx["maxPriorityFeePerGas"] / 10 ** 9
max_gas = tx["maxFeePerGas"] / 10**9
priority_gas = tx["maxPriorityFeePerGas"] / 10**9
output_str = (
f" Max fee: {color('bright blue')}{max_gas}{color} gwei"
f" Priority fee: {color('bright blue')}{priority_gas}{color} gwei"
)
elif self.gas_price is not None:
gas_price = self.gas_price / 10 ** 9
gas_price = self.gas_price / 10**9
output_str = f" Gas price: {color('bright blue')}{gas_price}{color} gwei"
print(
f"{output_str} Gas limit: {color('bright blue')}{self.gas_limit}{color}"
Expand Down
Loading

0 comments on commit 3aecd87

Please sign in to comment.