Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/readme and pyproject classifiers #106

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 24 additions & 11 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@
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!
Issues, feedback, and sharing that you're using Moccasin on social media is always welcome!

# Table of Contents

- [Contributing](#contributing)
- [Table of Contents](#table-of-contents)
- [Setup](#setup)
- [Requirements](#requirements)
- [ZKSync requirements](#zksync-requirements)
- [ZKync requirements](#zkync-requirements)
- [Installing for local development](#installing-for-local-development)
- [Running Tests](#running-tests)
- [Local Tests](#local-tests)
- [Integration Tests](#integration-tests)
- [ZKSync Tests](#zksync-tests)
- [ZKync Tests](#zkync-tests)
- [Live Tests](#live-tests)
- [Code Style Guide](#code-style-guide)
- [Where do you get the `typecheck` and `format` command?](#where-do-you-get-the-typecheck-and-format-command)
- [Thank you!](#thank-you)
Expand All @@ -40,13 +41,13 @@ You must have the following installed to proceed with contributing to this proje
- [just](https://github.com/casey/just)
- You'll know you did it right if you can run `just --version` and you see a response like `just 1.35.0`

### ZKSync requirements
If you wish to run the ZKSync tests, you'll need these as well (ran with `just test-z`)
### ZKync requirements
If you wish to run the ZKync tests, you'll need these as well (ran with `just test-z`)

- [era_test_node](https://github.com/matter-labs/era-test-node)
- You'll know you did it right if you can run `era_test_node --version` and you see a response like `era_test_node 0.1.0 (a178051e8 2024-09-07)`
- [era-compiler-vyper](https://github.com/matter-labs/era-compiler-vyper)
- You'll know you did it right if you can run `zkvyper --version` and you see a response like `Vyper compiler for ZKsync v1.5.4 (LLVM build f9f732c8ebdb88fb8cd4528482a00e4f65bcb8b7)`
- You'll know you did it right if you can run `zkvyper --version` and you see a response like `Vyper compiler for ZKync v1.5.4 (LLVM build f9f732c8ebdb88fb8cd4528482a00e4f65bcb8b7)`

## Installing for local development

Expand Down Expand Up @@ -100,8 +101,6 @@ However, if you run tests and scripts using the `uv` or `just` commands as we wi

## Running Tests

First, you'll need to make sure you have the `anvil1` keystore in your `~/.moccasin/keystores` folder. You can [find it here](./tests/data/keystores/anvil1). Please move it there.

### Local Tests

Run the following:
Expand All @@ -119,15 +118,29 @@ Read the [README.md in the integration folder](./tests/integration/README.md) to
just test-i # Check out the justfile to see the command this runs
```

### ZKSync Tests
### ZKync Tests

These will be the zksync tests that require the [ZKsync requirements](#zksync-requirements) to be installed.
These will be the ZKync tests that require the [ZKync requirements](#ZKync-requirements) to be installed.

```bash
just test-z # Check out the justfile to see the command this runs
```

### Live Tests

A "live test" is sending actual testnet ETH to sepolia. To do this, you'll need:
1. An environment variable `SEPOLIA_ZKSYNC_RPC_URL` set to the sepolia testnet RPC URL
2. A `mox wallet` named `smalltestnet` that has some sepolia ETH
3. A password for your `smalltestnet` wallet in `~/.moccasin/unsafe-passwords/smalltestnet`

Then run:

```bash
uv run pytest tests/live/test_live_verify.py --no-skip
```

> Note: There is almost no reason to run this test.

# Code Style Guide

We will run the `.github/workflows` before merging your PR to ensure that your code is up to standard. Be sure to run the scripts in there before submitting a PR.
Expand All @@ -150,4 +163,4 @@ You can see in `justfile` a list of scripts one can run. To see them all you can

# Thank you!

Thank you for wanting to participate in titanoboa and moccasin!
Thank you for wanting to participate with moccasin!
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
> This tool is in beta, use at your own risk

<p align="center">
<br />
<img src="./docs/source/_static/gh_banner.png" width="100%" alt=""/></a>
Expand All @@ -9,6 +11,10 @@
A fast, pythonic, Vyper smart contract testing and development framework.

[![uv](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/uv/main/assets/badge/v0.json)](https://github.com/astral-sh/uv)
<!-- Add these for 0.3.1 -->
<!-- [![moccasin](https://img.shields.io/pypi/v/moccasin.svg)](https://pypi.org/project/moccasin/)
[![license](https://img.shields.io/pypi/l/moccasin.svg)](https://pypi.python.org/pypi/moccasin)
[![python-versions](https://img.shields.io/pypi/pyversions/moccasin.svg)](https://pypi.python.org/pypi/moccasin) -->

> The smaller bar is better, it means it's faster

Expand Down
14 changes: 13 additions & 1 deletion docs/source/all_moccasin_toml_parameters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ In TOML you can think of each section as a giant JSON object. Each of these are
| | | } |
+----------------------------------+----------------------------------+----------------------------------+



All possible options
--------------------

Expand Down Expand Up @@ -89,4 +91,14 @@ All possible options

# Put whatever else you want in here
[extra_data]
hi = "hello"
hi = "hello"

Environment Variables
---------------------

Additionally, there are a few environment variables that ``moccasin`` will look for, but it's also ok if they are not set. It's important to note, that the `.env` file you set in the config will be ignored for these values.

.. code-block:: bash

MOCCASIN_DEFAULT_FOLDER = "~/.moccasin" # path to the moccasin folder
MOCCASIN_KEYSTORE_PATH = "~/.moccasin/keystore" # path to the keystore
6 changes: 3 additions & 3 deletions docs/source/core_concepts/moccasin_toml.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ Order Of Operations

Whenever you run a script, you'll want to remember this order:

1. Script
2. Command Line
1. Script
2. Command Line
3. ``moccasin.toml``
4. Defaults
4. Defaults

Whatever you place in your python script, will be the value used, even if your command line has a different value. Similarly, any flag passed to the command line will override any values in your ``moccasin.toml``, which will override any default values moccasin sets.

Expand Down
2 changes: 1 addition & 1 deletion docs/source/core_concepts/testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ This is the most basic setup for testing.

Gas Profiling <testing/gas_profiling.rst>
Coverage <testing/coverage.rst>
Fixutres <testing/fixtures.rst>
Fixtures <testing/fixtures.rst>
Testing with boa <testing/titanoboa_testing.rst>
How to prank <testing/pranking.rst>

12 changes: 9 additions & 3 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,21 @@ format-check:
uv run ruff check .

# Run unit and CLI tests, fail on first test failure
# REVIEW: We should refactor the tests so we can use -nauto here
test:
uv run pytest -x --ignore=tests/integration/ --ignore=tests/zksync/
uv run pytest -x --ignore=tests/integration/ --ignore=tests/zksync/

# Run the last failed test
test-lf:
uv run pytest --lf --ignore=tests/integration/ --ignore=tests/zksync/

# Run integration tests, read the README.md in the tests/integration directory for more information
test-i:
uv run pytest tests/integration -x --ignore=tests/zksync/
uv run pytest tests/integration -x --ignore=tests/zksync/

# Run zksync tests
test-z:
uv run pytest tests/zksync -nauto --ignore=tests/integration/
uv run pytest tests/zksync -nauto --ignore=tests/integration/

# Run both unit and integration tests
test-all:
Expand Down
5 changes: 4 additions & 1 deletion moccasin/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ def generate_main_parser_and_sub_parsers() -> (
nargs="?",
)
add_network_args_to_parser(test_parser)
add_account_args_to_parser(test_parser)

# Pytest args
test_parser.add_argument(
Expand Down Expand Up @@ -402,6 +403,7 @@ def generate_main_parser_and_sub_parsers() -> (
parents=[parent_parser],
)
add_network_args_to_parser(console_parser)
add_account_args_to_parser(console_parser)

# ------------------------------------------------------------------
# INSTALL COMMAND
Expand Down Expand Up @@ -595,7 +597,7 @@ def generate_main_parser_and_sub_parsers() -> (
parents=[parent_parser],
)
deployments_parser.add_argument(
"contract_name", help="Name of the contract to get."
"contract_name", help='Name of the contract to get, or "all".'
)
deployments_parser.add_argument(
"--format-level",
Expand All @@ -612,6 +614,7 @@ def generate_main_parser_and_sub_parsers() -> (
"--limit", default=None, help="Limit the number of deployments to get."
)
add_network_args_to_parser(deployments_parser)

# ------------------------------------------------------------------
# UTILS COMMAND
# ------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions moccasin/_sys_path_and_config_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ def _setup_network_and_account_from_config_and_cli(
password=password,
password_file_path=active_network.unsafe_password_file,
)

# Private key overrides the default account
if private_key:
mox_account = MoccasinAccount(
Expand Down
2 changes: 1 addition & 1 deletion moccasin/commands/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def main(args: Namespace) -> int:

with _patch_sys_path(get_sys_paths_list(config)):
if args.contract_or_contract_path:
contract_path = config._find_contract(args.contract_or_contract_path)
contract_path = config.find_contract(args.contract_or_contract_path)
compile_(
contract_path,
project_path.joinpath(config.out_folder),
Expand Down
2 changes: 1 addition & 1 deletion moccasin/commands/config_.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

def main(args: Namespace):
config: Config = get_config()
configuration_file = config.read_moccasin_config()
configuration_file = config.read_config()
logger.info(toml_like_pretty_print(configuration_file))
return 0

Expand Down
6 changes: 3 additions & 3 deletions moccasin/commands/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
get_sys_paths_list,
)
from moccasin.config import initialize_global_config
from moccasin.constants.vars import CONSOLE_HISTORY_FILE, DEFAULT_MOCCASIN_FOLDER
from moccasin.constants.vars import CONSOLE_HISTORY_FILE, MOCCASIN_DEFAULT_FOLDER
from moccasin.logging import logger


Expand All @@ -32,9 +32,9 @@ def main(args: Namespace) -> int:
)

# Ensure the Moccasin folder exists
DEFAULT_MOCCASIN_FOLDER.mkdir(parents=True, exist_ok=True)
MOCCASIN_DEFAULT_FOLDER.mkdir(parents=True, exist_ok=True)

history_file = DEFAULT_MOCCASIN_FOLDER.joinpath(CONSOLE_HISTORY_FILE)
history_file = MOCCASIN_DEFAULT_FOLDER.joinpath(CONSOLE_HISTORY_FILE)
validate_history_file(history_file)
history_file_str = str(history_file)

Expand Down
75 changes: 42 additions & 33 deletions moccasin/commands/deployments.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@

from boa.deployments import Deployment

from moccasin._sys_path_and_config_setup import (
_get_set_active_network_from_cli_and_config,
_patch_sys_path,
get_sys_paths_list,
)
from moccasin.config import Config, get_config, initialize_global_config
from moccasin.logging import logger

Expand Down Expand Up @@ -38,7 +33,7 @@ def main(args: Namespace) -> int:


def print_deployments_from_cli(
contract_name: str,
contract_name: str | None = None,
format_level: int = PrintVerbosity.CONTRACT_ADDRESS_AND_NAME.value,
db_path: str | None = None,
checked: bool = False,
Expand All @@ -51,35 +46,49 @@ def print_deployments_from_cli(
if config is None:
config = get_config()

# Set up the environment (add necessary paths to sys.path, etc.)
with _patch_sys_path(get_sys_paths_list(config)):
active_network = _get_set_active_network_from_cli_and_config(
config, network=network, url=url, fork=fork, db_path=db_path
if contract_name is not None:
if contract_name.strip().lower() == "all":
contract_name = None

if network is None:
network = config.default_network

# Don't activate boa
config.set_active_network(
network, url=url, fork=fork, db_path=db_path, activate_boa=False
)
active_network = config.get_active_network()

if not hasattr(active_network, "chain_id"):
logger.warning(
"No chain_id found in active network, attempting to connect to the network to retrieve the Chain Id"
)
active_network.create_and_set_or_set_boa_env()

if not active_network.save_to_db or not active_network.db_path:
logger.error(
f"Cannot get deployments without a database path on network {active_network.name}.\nPlease specify one or change networks."
)
return []

deployments_list = []
if not isinstance(limit, int) and not isinstance(limit, type(None)):
raise ValueError(f"Limit must be an integer or None, not {type(limit)}.")
if checked:
deployments_list = active_network.get_deployments_checked(
contract_name=contract_name, limit=limit, chain_id=active_network.chain_id
)
else:
deployments_list = active_network.get_deployments_unchecked(
contract_name=contract_name, limit=limit, chain_id=active_network.chain_id
)

if not active_network.save_to_db or not active_network.db_path:
logger.error(
f"Cannot get deployments without a database path on network {active_network.name}.\nPlease specify one or change networks."
)
return []

deployments_list = []

if checked:
deployments_list = active_network.get_deployments_checked(
contract_name, limit=limit
)
else:
deployments_list = active_network.get_deployments_unchecked(
contract_name, limit=limit
)
int_format_level = int(format_level)
if int_format_level > len(PrintVerbosity):
int_format_level = PrintVerbosity.RAW.value

print_deployments(deployments_list, PrintVerbosity(int_format_level))
return deployments_list
return []
int_format_level = int(format_level)
if int_format_level > len(PrintVerbosity):
int_format_level = PrintVerbosity.RAW.value

print_deployments(deployments_list, PrintVerbosity(int_format_level))
return deployments_list


def print_deployments(deployments_list: list[Deployment], format_level: PrintVerbosity):
Expand Down
17 changes: 12 additions & 5 deletions moccasin/commands/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from typing import Any

from moccasin.commands.compile import compile_
from moccasin.config import get_config
from moccasin.config import Config, get_config, initialize_global_config

FUNCTION_SIGNATURES_ALTS = [
"methods",
Expand All @@ -16,14 +16,21 @@

def main(args: Namespace) -> int:
inspect_type = args.inspect_type.replace("-", "_")
inspect_contract(args.contract, inspect_type, print_out=True)
config = initialize_global_config()
inspect_contract(args.contract, inspect_type, config=config, print_out=True)
return 0


def inspect_contract(contract: str, inspect_type: str, print_out: bool = False) -> Any:
config = get_config()
def inspect_contract(
contract: str,
inspect_type: str,
config: Config | None = None,
print_out: bool = False,
) -> Any:
if config is None:
config = get_config()

contract_path = config._find_contract(contract)
contract_path = config.find_contract(contract)
vyper_deployer = compile_(
contract_path, config.get_root().joinpath(config.build_folder)
)
Expand Down
Loading