Skip to content

Commit

Permalink
Merge branch 'master' into fix/consistent_at
Browse files Browse the repository at this point in the history
  • Loading branch information
benber86 authored Jan 27, 2025
2 parents 508bafb + a8d5a6c commit 98291b9
Show file tree
Hide file tree
Showing 163 changed files with 7,720 additions and 1,973 deletions.
2 changes: 1 addition & 1 deletion .env.unsafe.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
# Meaning, you should never store private keys associated with real funds in here!
MAINNET_ENDPOINT=xxx
SEPOLIA_ENDPOINT=xxx
SEPOLIA_PKEY=xxx
SEPOLIA_PKEY=xxx
2 changes: 1 addition & 1 deletion .github/workflows/integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
- name: Install Requirements
run: |
pip install -r dev-requirements.txt
pip install .
pip install .[forking-recommended]
- name: Run Fork Mode Tests
run: pytest -n auto tests/integration/fork/
Expand Down
37 changes: 37 additions & 0 deletions .github/workflows/release-pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# upload to pypi using the pypa publish action
# https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries

name: Publish to PyPI

on:
release:
types: [published] # releases and pre-releases (release candidates)

jobs:
publish-pypi:
runs-on: ubuntu-latest

# https://docs.pypi.org/trusted-publishers/using-a-publisher/
permissions:
# IMPORTANT: this permission is mandatory for trusted publishing
id-token: write
# Specifying a GitHub environment is optional, but strongly encouraged
environment: "pypi release"

steps:
- uses: actions/checkout@v4

- name: Python
uses: actions/setup-python@v5
with:
python-version: "3.11"

- name: Install dependencies
run: |
pip install build
- name: Build
run: python -m build

- name: Publish
uses: pypa/gh-action-pypi-publish@release/v1
6 changes: 3 additions & 3 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ build:
# rust: "1.64"
# golang: "1.19"

# Build documentation in the docs/ directory with Sphinx
sphinx:
configuration: docs/source/conf.py
# Build documentation in the docs/ directory with mkdocs
mkdocs:
configuration: mkdocs.yml

# Explicitly set the version of Python and its requirements
python:
Expand Down
24 changes: 16 additions & 8 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Contributing

Thank you for wanting to contribute! This project reviews PRs that have an associated issue with
them. If you have not make an issue for your PR, please make one first.
Thank you for wanting to contribute! This project reviews PRs that have an associated issue with
them. If you have not make an issue for your PR, please make one first.

Issues, feedback, and sharing that you're using Titanoboa and Vyper on social media is always welcome!

Expand All @@ -21,7 +21,7 @@ Issues, feedback, and sharing that you're using Titanoboa and Vyper on social me

## Requirements

You must have the following installed to proceed with contributing to this project.
You must have the following installed to proceed with contributing to this project.

- [git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)
- You'll know you did it right if you can run `git --version` and you see a response like `git version x.x.x`
Expand All @@ -32,7 +32,7 @@ You must have the following installed to proceed with contributing to this proje
- Linux and/or MacOS
- This project is not tested on Windows, so it is recommended to use a Linux or MacOS machine, or use a tool like [WSL](https://learn.microsoft.com/en-us/windows/wsl/install) for windows users.

## Installing for local development
## Installing for local development

Follow the steps to clone the repo for you to make changes to this project.

Expand All @@ -50,7 +50,10 @@ cd titanoboa
```bash
python -m venv venv
source venv/bin/activate
# Install dev requirements
pip install -r dev-requirements.txt
# Install prod requirements (in the pyproject.tom)
pip install .
```

*Note: When you delete your terminal/shell, you will need to reactivate this virtual environment again each time. To exit this python virtual environment, type `deactivate`*
Expand All @@ -64,11 +67,16 @@ git checkout -b <branch_name>
And start making your changes! Once you're done, you can commit your changes and push them to your forked repo.

```bash
git add .
git commit -m 'your commit message'
git commit -a
git push <your_forked_github>
```

4. Run the linter

```bash
make lint
```

## Running Tests

Once you have your environment setup, you can run the tests to make sure everything is working as expected. You'll need to have your virtual environment activated to run the tests.
Expand All @@ -85,7 +93,7 @@ This will skip the integration tests, which need extra "stuff".

### Integration tests

Once you have setup your virtual environment, to run integration tests, you'll need to add environment variables.
Once you have setup your virtual environment, to run integration tests, you'll need to add environment variables.

You can see the `.env.unsafe.example` for environment variables you'll want to use.

Expand All @@ -110,4 +118,4 @@ pytest tests/integration/ -x

# Thank you!

Thank you for wanting to participate in titanoboa!
Thank you for wanting to participate in titanoboa!
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pip install git+https://github.com/vyperlang/titanoboa

Sometimes, using [pypy](https://www.pypy.org/download.html) can result in a substantial performance improvement for computation heavy contracts. `Pypy` can usually be used as a drop-in replacement for `CPython`.

To get a performance boost for mainnet forking, install with the `forking-recommended` extra (`pip install "git+https://github.com/vyperlang/titanoboa#egg=titanoboa[forking-recommended]"`, or `pip install titanoboa[forking-recommended]`). This installs `plyvel` to cache RPC results between sessions, and `ujson` which improves json performance.
To get a performance boost for mainnet forking, install with the `forking-recommended` extra (`pip install "git+https://github.com/vyperlang/titanoboa#egg=titanoboa[forking-recommended]"`, or `pip install titanoboa[forking-recommended]`). This installs `requests-cache` to cache certain HTTP requests between sessions, and `ujson` which improves json performance.

If you are running titanoboa on a local [Vyper](https://github.com/vyperlang/vyper) project folder, you might need to run `python setup.py install` on your [Vyper](https://github.com/vyperlang/vyper) project if you encounter errors such as `ModuleNotFoundError: No module named 'vyper.version'`

Expand Down Expand Up @@ -199,10 +199,10 @@ Cast current deployed addresses to vyper contract

```python
>>> import boa
>>> boa.env.set_network_env("<rpc server address>")
>>> boa.set_network_env("<rpc server address>")
>>> from eth_account import Account
>>> # in a real codebase, always load private keys safely from an encrypted store!
>>> boa.env.add_account(Account(<a private key>))
>>> boa.env.add_account(Account.from_key("<a private key>"))
>>> c = boa.load("examples/ERC20.vy", "My Token", "TKN", 10**18, 10)
>>> c.name()
'My Token'
Expand Down
45 changes: 36 additions & 9 deletions boa/__init__.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
import contextlib
import sys

import boa.explorer
from boa.contracts.base_evm_contract import BoaError
from boa.contracts.vyper.vyper_contract import check_boa_error_matches
from boa.dealer import deal
from boa.debugger import BoaDebug
from boa.environment import Env
from boa.explorer import Etherscan, _set_etherscan, get_etherscan
from boa.interpret import (
from_etherscan,
load,
load_abi,
load_partial,
load_vyi,
loads,
loads_abi,
loads_partial,
loads_vyi,
)
from boa.network import NetworkEnv
from boa.precompile import precompile
from boa.test.strategies import fuzz
from boa.util.open_ctx import Open
from boa.verifiers import get_verifier, set_verifier, verify
from boa.vm.py_evm import enable_pyevm_verbose_logging, patch_opcode

# turn off tracebacks if we are in repl
Expand All @@ -30,32 +37,52 @@

@contextlib.contextmanager
def swap_env(new_env):
old_env = env
try:
set_env(new_env)
with set_env(new_env):
yield
finally:
set_env(old_env)


def _set_env(new):
global env
env = new
Env._singleton = new


def set_env(new_env):
global env
env = new_env
get_env = lambda: env # noqa: E731
return Open(get_env, _set_env, new_env)

Env._singleton = new_env

def fork(
url: str, block_identifier: int | str = "safe", allow_dirty: bool = False, **kwargs
):
global env
if env.evm.is_state_dirty and not allow_dirty:
raise Exception(
"Cannot fork with dirty state. Set allow_dirty=True to override."
)

new_env = Env()
new_env.fork(url=url, block_identifier=block_identifier, deprecated=False, **kwargs)
return set_env(new_env)


def set_browser_env(address=None):
"""Set the environment to use the browser's network in Jupyter/Colab"""
# import locally because jupyter is generally not installed
from boa.integrations.jupyter import BrowserEnv

set_env(BrowserEnv(address))
return set_env(BrowserEnv(address))


def set_network_env(url):
"""Set the environment to use a custom network URL"""
set_env(NetworkEnv.from_url(url))
return set_env(NetworkEnv.from_url(url))


def set_etherscan(*args, **kwargs):
explorer = Etherscan(*args, **kwargs)
return Open(get_etherscan, _set_etherscan, explorer)


def reset_env():
Expand Down
Loading

0 comments on commit 98291b9

Please sign in to comment.