Skip to content

Commit

Permalink
Merge branch 'master' into feat/add-chiado-testnet
Browse files Browse the repository at this point in the history
  • Loading branch information
iamdefinitelyahuman authored Jan 29, 2024
2 parents 2d5d0ea + 6879c9a commit e0d1ec2
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 17 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Optimisim (fixed explorer support)
- Gnosis Chain
- Chiado (Gnosis testnet)
- Base chain

### Fixed
- Force using utf-8 for reading contracts
- Fix verification for same named files ([#1677](https://github.com/eth-brownie/brownie/pull/1677))

## [1.19.3](https://github.com/eth-brownie/brownie/tree/v1.19.3) - 2023-01-29
### Added
Expand Down
27 changes: 23 additions & 4 deletions brownie/data/network-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -136,21 +136,21 @@ live:
- name: Mainnet
chainid: 1284
id: moonbeam-main
host: https://moonbeam.api.onfinality.io/public
host: https://rpc.api.moonbeam.network
explorer: https://api-moonbeam.moonscan.io/api
multicall2: "0x1337BedC9D22ecbe766dF105c9623922A27963EC"
- name: Moonbase Alpha
chainid: 1287
id: moonbeam-test
host: https://moonbeam-alpha.api.onfinality.io/public
host: https://rpc.api.moonbase.moonbeam.network
explorer: https://api-moonbase.moonscan.io/api
multicall2: "0x37084d0158C68128d6Bc3E5db537Be996f7B6979"
- name: Moonriver
networks:
- name: Mainnet
chainid: 1285
id: moonriver-main
host: https://moonriver.api.onfinality.io/public
host: https://rpc.api.moonriver.moonbeam.network
explorer: https://api-moonriver.moonscan.io/api
multicall2: "0xaef00a0cf402d9dedd54092d9ca179be6f9e5ce3"
- name: Optimistic Ethereum
Expand Down Expand Up @@ -200,6 +200,13 @@ live:
host: https://zkevm-rpc.com
id: zkevm-main
name: Polygon zkEVM mainnet
- name: Base
networks:
- chainid: 8453
explorer: https://api.basescan.org/api
host: https://mainnet.base.org
id: base-main
name: Base mainnet



Expand Down Expand Up @@ -342,4 +349,16 @@ development:
accounts: 10
evm_version: istanbul
mnemonic: brownie
fork: zkevm-main
fork: zkevm-main
- name: Ganache-CLI Base-Mainnet Fork)
id: base-main-fork
cmd: ganache-cli
host: http://127.0.0.1
timeout: 120
cmd_settings:
port: 8545
gas_limit: 20000000
accounts: 10
evm_version: istanbul
mnemonic: brownie
fork: base-main
3 changes: 2 additions & 1 deletion brownie/network/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@
"snowtrace": "SNOWTRACE_TOKEN",
"aurorascan": "AURORASCAN_TOKEN",
"moonscan": "MOONSCAN_TOKEN",
"gnosisscan": "GNOSISSCAN_TOKEN"
"gnosisscan": "GNOSISSCAN_TOKEN",
"base": "BASESCAN_TOKEN"
}


Expand Down
2 changes: 1 addition & 1 deletion brownie/network/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ def _add_contract(contract: Any) -> None:


def _remove_contract(contract: Any) -> None:
del _contract_map[contract.address]
_contract_map.pop(contract.address, None)


def _get_deployment(
Expand Down
14 changes: 14 additions & 0 deletions brownie/network/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,20 @@ def _expand_trace(self) -> None:
last["address"], trace[i]["stack"][-2][-40:], trace[i]["stack"][-3]
)

# If the function signature is not available for decoding return data attach
# the encoded data.
# If the function signature is available this will be overridden by setting
# `return_value` a few lines below.
if trace[i]["depth"] and opcode == "RETURN":
subcall: dict = next(
i for i in self._subcalls[::-1] if i["to"] == last["address"] # type: ignore
)

if opcode == "RETURN":
returndata = _get_memory(trace[i], -1)
if returndata.hex() not in ("", "0x"):
subcall["returndata"] = returndata.hex()

try:
pc = last["pc_map"][trace[i]["pc"]]
except (KeyError, TypeError):
Expand Down
27 changes: 18 additions & 9 deletions brownie/project/flattener.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,23 @@ def __init__(
self.dependencies: DefaultDict[str, Set[str]] = defaultdict(set)
self.compiler_settings = compiler_settings
self.contract_name = contract_name
self.contract_file = Path(primary_source_fp).name
self.contract_file = self.path_to_name(primary_source_fp)
self.remappings = remappings

self.traverse(primary_source_fp)

license_search = LICENSE_PATTERN.search(self.sources[Path(primary_source_fp).name])
license_search = LICENSE_PATTERN.search(self.path_to_name(primary_source_fp))
self.license = license_search.group(1) if license_search else "NONE"

@classmethod
def path_to_name(cls, pth: str) -> str:
"""Turn the full-path of every Solidity file to a unique shorten name.
Note, that sometimes there could be several different files with the same name in a project,
so these files should keep uniq name to correct verification.
"""
return 'contracts/' + pth.split('/contracts/')[1]

def traverse(self, fp: str) -> None:
"""Traverse a contract source files dependencies.
Expand All @@ -42,8 +51,9 @@ def traverse(self, fp: str) -> None:
fp: The contract source file to traverse, if it's already been traversed, return early.
"""
# if already traversed file, return early
name = self.path_to_name(fp)
fp_obj = Path(fp)
if fp_obj.name in self.sources:
if name in self.sources:
return

# read in the source file
Expand All @@ -56,18 +66,17 @@ def traverse(self, fp: str) -> None:
# replacement function for re.sub, we just sanitize the path
repl = ( # noqa: E731
lambda m: f'import{m.group("prefix")}'
+ f'"{Path(sanitize(m.group("path"))).name}"'
+ f'{m.group("suffix")}'
+ f'"{self.path_to_name(sanitize(m.group("path")))}"'
+ f'{m.group("suffix")}'
)

self.sources[fp_obj.name] = IMPORT_PATTERN.sub(repl, source)
self.sources[name] = IMPORT_PATTERN.sub(repl, source)
if fp_obj.name not in self.dependencies:
self.dependencies[fp_obj.name] = set()
self.dependencies[name] = set()

# traverse dependency files - can circular imports happen?
for m in IMPORT_PATTERN.finditer(source):
import_path = sanitize(m.group("path"))
self.dependencies[fp_obj.name].add(Path(import_path).name)
self.dependencies[name].add(self.path_to_name(import_path))
self.traverse(import_path)

@property
Expand Down
2 changes: 1 addition & 1 deletion brownie/project/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,7 @@ def _load_sources(project_path: Path, subfolder: str, allow_json: bool) -> Dict:
continue
if next((i for i in path.relative_to(project_path).parts if i.startswith("_")), False):
continue
with path.open() as fp:
with path.open(encoding='utf-8') as fp:
source = fp.read()

if hasattr(hooks, "brownie_load_source"):
Expand Down
6 changes: 6 additions & 0 deletions docs/init.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ To initialize an empty project, start by creating a new folder. From within that

An empty :ref:`project structure<structure>` is created within the folder.

To initialize an empty project inside a new empty or existing folder type:

::

$ brownie init -f

Creating a Project from a Template
==================================

Expand Down
2 changes: 1 addition & 1 deletion docs/tests-coverage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,6 @@ Some things to keep in mind that can help to reduce your test runtime when evalu
1. Coverage is analyzed on a per-transaction basis, and the results are cached. If you repeat an identical transaction, Brownie will not analyze it the 2nd time. Keep this in mind when designing and sequencing setup fixtures.
2. For tests that involve many calls to the same getter method, use the :func:`no_call_coverage <pytest.mark.no_call_coverage>` marker to significantly speed execution.
3. Omit very complex tests altogether with the :func:`skip_coverage <pytest.mark.skip_coverage>` marker.
4. If possible, always run your tests in parralel with :ref:`xdist<xdist>`.
4. If possible, always run your tests in parallel with :ref:`xdist<xdist>`.

You can use the ``--durations`` flag to view a profile of your slowest tests. You may find good candidates for optimization, or the use of the :func:`no_call_coverage <pytest.mark.no_call_coverage>` and :func:`skip_coverage <pytest.mark.skip_coverage>` fixtures.

0 comments on commit e0d1ec2

Please sign in to comment.