Pytest support for cairo-lang and starknet
Project description
pytest-cairo: pytest support for cairo-lang and starknet
Usage
To install:
$ pip install pytest-cairo
The plugin will automatically run any function with a test
prefix, from files with a test_
prefix and a .cairo
extension.
Example
Consider the following Starknet contract:
# Contents of contract.cairo
%lang starknet
from starkware.cairo.common.cairo_builtins import HashBuiltin
func calculate_inverse{
syscall_ptr : felt*,
pedersen_ptr : HashBuiltin*,
range_check_ptr,
}(val : felt) -> (res : felt):
return (1 / val)
end
We could write a basic test for the function calculate_inverse
:
# Contents of test_contract.cairo
%lang starknet
from starkware.cairo.common.cairo_builtins import HashBuiltin
from contracts.contract import calculate_inverse
@external
func test_calculate_inverse{
syscall_ptr : felt*,
pedersen_ptr : HashBuiltin*,
range_check_ptr,
}() -> ():
let (actual) = calculate_inverse(2)
let expected = 1 / 2
assert actual = expected
return ()
end
Additionally we could use a raises
attribute to assert that the function fails if we pass val=0
:
@external
func test_calculate_inverse_expected_exception{
syscall_ptr : felt*,
pedersen_ptr : HashBuiltin*,
range_check_ptr,
}() -> ():
with_attr raises("assert_not_zero failed"):
calculate_inverse(0)
end
return ()
end
Development
To install development dependencies, run:
$ pip install -r requirements-dev.txt
Run tests with:
$ pytest
or:
$ docker-compose run test
To run tests against all supported interpreters (using docker-compose
):
$ tox
This assumes tox
, docker
and docker-compose
are installed.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pytest-cairo-0.0.3.tar.gz
.
File metadata
- Download URL: pytest-cairo-0.0.3.tar.gz
- Upload date:
- Size: 11.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9cad27b7e4cbddc3b16db82fee679dd971c981645203ba71a4d05eb6d05fde0f |
|
MD5 | 6e750f2b4e50bceafa87f0c876434682 |
|
BLAKE2b-256 | 18491797311b5e96b162ab6c0671029a42451838917fd55de4e66aba99309713 |
File details
Details for the file pytest_cairo-0.0.3-py3-none-any.whl
.
File metadata
- Download URL: pytest_cairo-0.0.3-py3-none-any.whl
- Upload date:
- Size: 8.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8193093a7d475d0eecad88386b6d2bc3f84f131621b8c57cf8f5406241c72eef |
|
MD5 | c4c4b5ac727fbbaf3d4b5938f27ee412 |
|
BLAKE2b-256 | 04d342f13e34085978b77de4da2fe0e31f1a9721a7bc14ce7808d91239c3d561 |