Skip to content

Commit

Permalink
Support ganache 7 cli flags
Browse files Browse the repository at this point in the history
  • Loading branch information
danhper committed Jan 26, 2022
1 parent c3dd4a7 commit 944e358
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 15 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ 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)
### Added
- Add support for Ganache 7 CLI flags
### 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.
Expand Down
57 changes: 42 additions & 15 deletions brownie/network/rpc/ganache.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/python3

import datetime
import re
import sys
import warnings
from subprocess import DEVNULL, PIPE
Expand All @@ -16,19 +17,36 @@
from brownie.network.web3 import web3

CLI_FLAGS = {
"port": "--port",
"gas_limit": "--gasLimit",
"accounts": "--accounts",
"evm_version": "--hardfork",
"fork": "--fork",
"mnemonic": "--mnemonic",
"account_keys_path": "--acctKeys",
"block_time": "--blockTime",
"default_balance": "--defaultBalanceEther",
"time": "--time",
"unlock": "--unlock",
"network_id": "--networkId",
"chain_id": "--chainId",
"7": {
"port": "--server.port",
"gas_limit": "--miner.blockGasLimit",
"accounts": "--wallet.totalAccounts",
"evm_version": "--hardfork",
"fork": "--fork.url",
"mnemonic": "--wallet.mnemonic",
"account_keys_path": "--wallet.accountKeysPath",
"block_time": "--miner.blockTime",
"default_balance": "--wallet.defaultBalance",
"time": "--chain.time",
"unlock": "--wallet.unlockedAccounts",
"network_id": "--chain.networkId",
"chain_id": "--chain.chainId",
},
"<=6": {
"port": "--port",
"gas_limit": "--gasLimit",
"accounts": "--accounts",
"evm_version": "--hardfork",
"fork": "--fork",
"mnemonic": "--mnemonic",
"account_keys_path": "--acctKeys",
"block_time": "--blockTime",
"default_balance": "--defaultBalanceEther",
"time": "--time",
"unlock": "--unlock",
"network_id": "--networkId",
"chain_id": "--chainId",
},
}

EVM_VERSIONS = ["byzantium", "constantinople", "petersburg", "istanbul"]
Expand All @@ -46,6 +64,15 @@ def launch(cmd: str, **kwargs: Dict) -> None:
else:
cmd += ".cmd"
cmd_list = cmd.split(" ")
ganache_version_proc = psutil.Popen(cmd_list + ["--version"], stdout=PIPE)
ganache_version_stdout, _ = ganache_version_proc.communicate()
ganache_version = int(re.search(r"v([0-9]+)\.", ganache_version_stdout.decode()).group(1))

if ganache_version <= 6:
cli_flags = CLI_FLAGS["<=6"]
else:
cli_flags = CLI_FLAGS["7"]

kwargs.setdefault("evm_version", EVM_DEFAULT) # type: ignore
if kwargs["evm_version"] in EVM_EQUIVALENTS:
kwargs["evm_version"] = EVM_EQUIVALENTS[kwargs["evm_version"]] # type: ignore
Expand All @@ -57,10 +84,10 @@ def launch(cmd: str, **kwargs: Dict) -> None:
for address in value:
if isinstance(address, int):
address = HexBytes(address.to_bytes(20, "big")).hex()
cmd_list.extend([CLI_FLAGS[key], address])
cmd_list.extend([cli_flags[key], address])
else:
try:
cmd_list.extend([CLI_FLAGS[key], str(value)])
cmd_list.extend([cli_flags[key], str(value)])
except KeyError:
warnings.warn(
f"Ignoring invalid commandline setting for ganache-cli: "
Expand Down

0 comments on commit 944e358

Please sign in to comment.