Development#

This page describes how to setup development environment. You don’t need to follow the instructions if you just use starknet.py as a package.

Development dependencies#

  • poetry - dependency manager.

  • pyenv - recommended for installing and switching python versions locally.

  • cairo-lang - required to compile contracts (poe compile_contracts)

  • asdf - required to install scarb, that is used for contracts compilation (poe compile_contracts)

Setup#

Starknet devnet#

To install starknet-devnet-rs run the script ./starknet_py/tests/install_devnet.sh.

Environment variables#

In order to be able to run tests on testnet network (starknet_py/tests/e2e/tests_on_networks/), you must set some environmental variables:

  • SEPOLIA_RPC_URL

  • SEPOLIA_ACCOUNT_PRIVATE_KEY

  • SEPOLIA_ACCOUNT_ADDRESS

The best way to set environment variables is to create test-variables.env file in starknet_py/tests/e2e/ directory, so they can be loaded by the python-dotenv library. You can find an example file test-variables.env.template in the same directory with the format of how it should look like.

Dependencies#

poetry install

Contracts#

poe compile_contracts

Git hooks#

Run this snippet to enable lint checks and automatic formatting before commit/push.

cp pre-push ./.git/hooks/
cp pre-commit ./.git/hooks/
chmod +x ./.git/hooks/pre-commit
chmod +x ./.git/hooks/pre-push

Documentation#

Sphinx is used for generating documentation.

# Install additional dependencies for docs
poetry install -E docs

# Generate HTML documentation
poe docs_create

# Open generated HTML documentation
poe docs_open

Tests#

# Run whole suite
poe test

# Run only tests on networks
poe test_ci_on_networks

# Run unit tests and tests on devnet
poe test_ci

# Generate test report in terminal
poe test_report

# Generate HTML report and open it in the browser
poe test_html

Code style guide#

Rules to follow when writing a code:

  1. Check the code with pylint

poe lint
  1. Format the code with black

poe format
  1. Run a typechecker (pyright)

poe typecheck
  1. Add constant values to the constants.py file.

  2. Prefer keyword-only arguments where appropriate.

  3. All public classes providing async api should be marked with the @add_sync_methods decorator.

  4. Error messages should start with a capital letter.

  5. Use Argument x is… instead of X is… when error message starts with argument (property) name.

  6. All sentences (in docstrings/errors) should be ended with a period.

  7. When adding a TODO comment, it must have a corresponding issue to it. The format for the comment is: # TODO (#issue no.): ....

Release checklist#

Perform these actions before releasing a new starknet.py version

  1. Bump package version in pyproject.toml

  2. Re-lock using poetry lock --no-update

  3. Make a PR to development with name of format vMAJOR.MINOR.PATCHES-alpha and merge it making sure that the merge commit message is the same as PR name

  4. Merge development into master without squashing

git checkout master
git merge development
  1. Make a new release on GitHub