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:
Check the code with pylint
poe lint
Format the code with black
poe format
Run a typechecker (pyright)
poe typecheck
Add constant values to the constants.py file.
Prefer keyword-only arguments where appropriate.
All public classes providing async api should be marked with the @add_sync_methods decorator.
Error messages should start with a capital letter.
Use Argument x is… instead of X is… when error message starts with argument (property) name.
All sentences (in docstrings/errors) should be ended with a period.
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
Bump package version in
pyproject.toml
Re-lock using
poetry lock --no-update
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 nameMerge development into master without squashing
git checkout master
git merge development
Make a new release on GitHub