Skip to content

Commit

Permalink
Merge branch 'master' into alchemy-custom-provider
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickAlphaC authored Feb 1, 2022
2 parents c841224 + 6b95022 commit 89ef296
Show file tree
Hide file tree
Showing 6 changed files with 257 additions and 169 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- 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.

### Fixed
- Improve support for Ganache 7 reverted transactions

## [1.17.2](https://github.com/eth-brownie/brownie/tree/v1.17.2) - 2021-12-04
### Changed
Expand Down
251 changes: 125 additions & 126 deletions brownie/data/network-config.yaml
Original file line number Diff line number Diff line change
@@ -1,130 +1,129 @@
live:
- name: Ethereum
networks:
- name: Mainnet (Infura)
chainid: 1
id: mainnet
host: https://mainnet.infura.io/v3/$WEB3_INFURA_PROJECT_ID
explorer: https://api.etherscan.io/api
multicall2: "0x5BA1e12693Dc8F9c48aAD8770482f4739bEeD696"
provider: infura
- name: Ropsten (Infura)
chainid: 3
id: ropsten
host: https://ropsten.infura.io/v3/$WEB3_INFURA_PROJECT_ID
explorer: https://api-ropsten.etherscan.io/api
multicall2: "0x5BA1e12693Dc8F9c48aAD8770482f4739bEeD696"
provider: infura
- name: Rinkeby (Infura)
chainid: 4
id: rinkeby
host: https://rinkeby.infura.io/v3/$WEB3_INFURA_PROJECT_ID
explorer: https://api-rinkeby.etherscan.io/api
multicall2: "0x5BA1e12693Dc8F9c48aAD8770482f4739bEeD696"
provider: infura
- name: Goerli (Infura)
chainid: 5
id: goerli
host: https://goerli.infura.io/v3/$WEB3_INFURA_PROJECT_ID
explorer: https://api-goerli.etherscan.io/api
multicall2: "0x5BA1e12693Dc8F9c48aAD8770482f4739bEeD696"
provider: infura
- name: Kovan (Infura)
chainid: 42
id: kovan
host: https://kovan.infura.io/v3/$WEB3_INFURA_PROJECT_ID
explorer: https://api-kovan.etherscan.io/api
multicall2: "0x5BA1e12693Dc8F9c48aAD8770482f4739bEeD696"
provider: infura
- name: Ethereum Classic
networks:
- name: Mainnet
chainid: 61
id: etc
host: https://www.ethercluster.com/etc
explorer: https://blockscout.com/etc/mainnet/api
- name: Kotti
chainid: 6
id: kotti
host: https://www.ethercluster.com/kotti
explorer: https://blockscout.com/etc/kotti/api
- name: Arbitrum
networks:
- name: Mainnet
chainid: 42161
id: arbitrum-main
host: https://arb1.arbitrum.io/rpc
explorer: https://api.arbiscan.io/api
multicall2: "0x5B5CFE992AdAC0C9D48E05854B2d91C73a003858"
- name: Avalanche
networks:
- chainid: 43114
explorer: https://api.snowtrace.io/api
host: https://api.avax.network/ext/bc/C/rpc
id: avax-main
name: Mainnet
- chainid: 43113
host: https://api.avax-test.network/ext/bc/C/rpc
id: avax-test
name: Testnet
- name: Binance Smart Chain
networks:
- name: Testnet
chainid: 97
id: bsc-test
host: https://data-seed-prebsc-1-s1.binance.org:8545
explorer: https://api-testnet.bscscan.com/api
- name: Mainnet
chainid: 56
id: bsc-main
host: https://bsc-dataseed.binance.org
explorer: https://api.bscscan.com/api
- name: Fantom Opera
networks:
- name: Testnet
chainid: 0xfa2
id: ftm-test
host: https://rpc.testnet.fantom.network
explorer: https://explorer.testnet.fantom.network
- name: Mainnet
chainid: 250
id: ftm-main
host: https://rpcapi.fantom.network
explorer: https://api.ftmscan.com/api
- name: Harmony
networks:
- name: Mainnet (Shard 0)
chainid: 1666600000
host: https://api.harmony.one
id: harmony-main
multicall2: "0x3E01dD8a5E1fb3481F0F589056b428Fc308AF0Fb"
- name: Polygon
networks:
- name: Mainnet (Infura)
chainid: 137
id: polygon-main
host: https://polygon-mainnet.infura.io/v3/$WEB3_INFURA_PROJECT_ID
explorer: https://api.polygonscan.com/api
multicall2: "0xc8E51042792d7405184DfCa245F2d27B94D013b6"
- name: Mumbai Testnet (Infura)
chainid: 80001
id: polygon-test
host: https://polygon-mumbai.infura.io/v3/$WEB3_INFURA_PROJECT_ID
explorer: https://api-testnet.polygonscan.com/api
multicall2: "0x6842E0412AC1c00464dc48961330156a07268d14"
- name: XDai
networks:
- name: Mainnet
chainid: 100
id: xdai-main
host: https://xdai.poanetwork.dev
explorer: https://blockscout.com/xdai/mainnet/api
- name: Testnet
chainid: 77
id: xdai-test
host: https://sokol.poa.network
explorer: https://blockscout.com/poa/sokol/api

- name: Ethereum
networks:
- name: Mainnet (Infura)
chainid: 1
id: mainnet
host: https://mainnet.infura.io/v3/$WEB3_INFURA_PROJECT_ID
explorer: https://api.etherscan.io/api
multicall2: "0x5BA1e12693Dc8F9c48aAD8770482f4739bEeD696"
provider: infura
- name: Ropsten (Infura)
chainid: 3
id: ropsten
host: https://ropsten.infura.io/v3/$WEB3_INFURA_PROJECT_ID
explorer: https://api-ropsten.etherscan.io/api
multicall2: "0x5BA1e12693Dc8F9c48aAD8770482f4739bEeD696"
provider: infura
- name: Rinkeby (Infura)
chainid: 4
id: rinkeby
host: https://rinkeby.infura.io/v3/$WEB3_INFURA_PROJECT_ID
explorer: https://api-rinkeby.etherscan.io/api
multicall2: "0x5BA1e12693Dc8F9c48aAD8770482f4739bEeD696"
provider: infura
- name: Goerli (Infura)
chainid: 5
id: goerli
host: https://goerli.infura.io/v3/$WEB3_INFURA_PROJECT_ID
explorer: https://api-goerli.etherscan.io/api
multicall2: "0x5BA1e12693Dc8F9c48aAD8770482f4739bEeD696"
provider: infura
- name: Kovan (Infura)
chainid: 42
id: kovan
host: https://kovan.infura.io/v3/$WEB3_INFURA_PROJECT_ID
explorer: https://api-kovan.etherscan.io/api
multicall2: "0x5BA1e12693Dc8F9c48aAD8770482f4739bEeD696"
provider: infura
- name: Ethereum Classic
networks:
- name: Mainnet
chainid: 61
id: etc
host: https://www.ethercluster.com/etc
explorer: https://blockscout.com/etc/mainnet/api
- name: Kotti
chainid: 6
id: kotti
host: https://www.ethercluster.com/kotti
explorer: https://blockscout.com/etc/kotti/api
- name: Arbitrum
networks:
- name: Mainnet
chainid: 42161
id: arbitrum-main
host: https://arb1.arbitrum.io/rpc
explorer: https://api.arbiscan.io/api
multicall2: "0x5B5CFE992AdAC0C9D48E05854B2d91C73a003858"
- name: Avalanche
networks:
- chainid: 43114
explorer: https://api.snowtrace.io/api
host: https://api.avax.network/ext/bc/C/rpc
id: avax-main
name: Mainnet
- chainid: 43113
host: https://api.avax-test.network/ext/bc/C/rpc
id: avax-test
name: Testnet
- name: Binance Smart Chain
networks:
- name: Testnet
chainid: 97
id: bsc-test
host: https://data-seed-prebsc-1-s1.binance.org:8545
explorer: https://api-testnet.bscscan.com/api
- name: Mainnet
chainid: 56
id: bsc-main
host: https://bsc-dataseed.binance.org
explorer: https://api.bscscan.com/api
- name: Fantom Opera
networks:
- name: Testnet
chainid: 0xfa2
id: ftm-test
host: https://rpc.testnet.fantom.network
explorer: https://explorer.testnet.fantom.network
- name: Mainnet
chainid: 250
id: ftm-main
host: https://rpc.ftm.tools
explorer: https://api.ftmscan.com/api
- name: Harmony
networks:
- name: Mainnet (Shard 0)
chainid: 1666600000
host: https://api.harmony.one
id: harmony-main
multicall2: "0x3E01dD8a5E1fb3481F0F589056b428Fc308AF0Fb"
- name: Polygon
networks:
- name: Mainnet (Infura)
chainid: 137
id: polygon-main
host: https://polygon-mainnet.infura.io/v3/$WEB3_INFURA_PROJECT_ID
explorer: https://api.polygonscan.com/api
multicall2: "0xc8E51042792d7405184DfCa245F2d27B94D013b6"
- name: Mumbai Testnet (Infura)
chainid: 80001
id: polygon-test
host: https://polygon-mumbai.infura.io/v3/$WEB3_INFURA_PROJECT_ID
explorer: https://api-testnet.polygonscan.com/api
multicall2: "0x6842E0412AC1c00464dc48961330156a07268d14"
- name: XDai
networks:
- name: Mainnet
chainid: 100
id: xdai-main
host: https://xdai.poanetwork.dev
explorer: https://blockscout.com/xdai/mainnet/api
- name: Testnet
chainid: 77
id: xdai-test
host: https://sokol.poa.network
explorer: https://blockscout.com/poa/sokol/api
development:
- name: Ganache-CLI
id: development
Expand Down
88 changes: 55 additions & 33 deletions brownie/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

# network

ERROR_SIG = "0x08c379a0"


class UnknownAccount(Exception):
pass
Expand Down Expand Up @@ -75,50 +77,70 @@ class VirtualMachineError(Exception):
"""

def __init__(self, exc: ValueError) -> None:
self.txid: str = ""
self.source: str = ""
self.revert_type: str = ""
self.pc: Optional[int] = None
self.revert_msg: Optional[str] = None
self.dev_revert_msg: Optional[str] = None

try:
exc = exc.args[0]
except Exception:
pass

if isinstance(exc, dict) and "message" in exc:
if "data" not in exc:
raise ValueError(exc["message"]) from None
if not (isinstance(exc, dict) and "message" in exc):
raise ValueError(str(exc)) from None

if "data" not in exc:
raise ValueError(exc["message"]) from None

self.message: str = exc["message"].rstrip(".")
self.message: str = exc["message"].rstrip(".")

if isinstance(exc["data"], str):
# handle parity exceptions - this logic probably is not perfect
if "0x08c379a0" in exc["data"]:
revert_type, err_msg = [i.strip() for i in exc["data"].split("0x08c379a0", 1)]
err_msg = eth_abi.decode_abi(["string"], HexBytes(err_msg))
err_msg = f"{revert_type} '{err_msg}'"
elif exc["data"].endswith("0x"):
if isinstance(exc["data"], str):
# handle parity exceptions - this logic probably is not perfect
if not exc["data"].startswith(ERROR_SIG):
err_msg = exc["data"]
if err_msg.endswith("0x"):
err_msg = exc["data"][:-2].strip()
else:
err_msg = exc["data"]
raise ValueError(f"{self.message}: {err_msg}") from None

try:
txid, data = next((k, v) for k, v in exc["data"].items() if k.startswith("0x"))
except StopIteration:
raise ValueError(exc["message"]) from None
self.revert_type = "revert"
err_msg = exc["data"][len(ERROR_SIG) :]
(err_msg,) = eth_abi.decode_abi(["string"], HexBytes(err_msg))
self.revert_msg = err_msg

self.txid: str = txid
self.source: str = ""
self.revert_type: str = data["error"]
self.pc: Optional[str] = data.get("program_counter")
if self.pc and self.revert_type == "revert":
self.pc -= 1

self.revert_msg: Optional[str] = data.get("reason")
self.dev_revert_msg = brownie.project.build._get_dev_revert(self.pc)
if self.revert_msg is None and self.revert_type in ("revert", "invalid opcode"):
self.revert_msg = self.dev_revert_msg
elif self.revert_msg == "Failed assertion":
self.revert_msg = self.dev_revert_msg or self.revert_msg

else:
raise ValueError(str(exc)) from None
return

try:
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"]

self.txid = txid
self.source = ""
self.pc = data.get("program_counter")
if self.pc and self.revert_type == "revert":
self.pc -= 1

self.revert_msg = data.get("reason")
self.dev_revert_msg = brownie.project.build._get_dev_revert(self.pc)
if self.revert_msg is None and self.revert_type in ("revert", "invalid opcode"):
self.revert_msg = self.dev_revert_msg
elif self.revert_msg == "Failed assertion":
self.revert_msg = self.dev_revert_msg or self.revert_msg

def __str__(self) -> str:
if not hasattr(self, "revert_type"):
Expand Down
Loading

0 comments on commit 89ef296

Please sign in to comment.