PocketIC: A Canister Smart Contract Testing Platform
Project description
PocketIC Python: A Canister Testing Library
PocketIC is a local canister testing solution for the Internet Computer.
This testing library works together with the PocketIC server, allowing you to interact with your local IC instances and the canisters thereon.
With PocketIC Python, you can test your canisters with just a few lines of code, either by interacting with an IC instance:
from pocket_ic import PocketIC
pic = PocketIC()
canister_id = pic.create_canister()
pic.add_cycles(canister_id, 2_000_000_000_000) # 2T cycles
pic.install_code(...)
# make canister calls
response = pic.update_call(canister_id, method="greet", ...)
assert(response == 'Hello, PocketIC!')
... or even directly with a canister object:
my_canister = pic.create_and_install_canister_with_candid(...)
# call your canister methods with native Python syntax
response = my_canister.greet()
assert(response == 'Hello, PocketIC!')
Getting Started
Quickstart
- Download the latest PocketIC server from the PocketIC repo that is compatible with the library version you're using.
- Leave the binary in your current working directory, or specify the path to the binary by setting the
POCKET_IC_BIN
environment variable before running your tests. - Run
pip3 install pocket-ic
in your (virtual) environment to get the Python library. - Use
from pocket_ic import PocketIC
in your Python code and start testing!
Examples
To see some working code, see the examples/ folder, or check out the how to use this library guide.
To run an example, clone this repo and run python3 examples/counter_canister/counter_canister_test.py
from the repository's root directory.
To see a minimalistic setup of PocketIC in a Motoko project, check out the ICP Hello World Motoko repository.
Documentation
- How to use this library
- PocketIC repo
- PocketIC server compatibility
- Why PocketIC
- Changelog of PocketIC Python
Contributing
See CONTRIBUTING.md
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 pocket_ic-3.0.0.tar.gz
.
File metadata
- Download URL: pocket_ic-3.0.0.tar.gz
- Upload date:
- Size: 587.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1283ab09c6942088d13e3abd28f5865456e1d9ab9759c9da8e816b222ee50b7b |
|
MD5 | ecabbd624c0d001ee2357b3952ccb560 |
|
BLAKE2b-256 | ea794c0ed6b5b20ec2b7fcb813c2c68cd3e6a783ef1e7333b48490ccf16522d7 |
Provenance
The following attestation bundles were made for pocket_ic-3.0.0.tar.gz
:
Publisher:
build.yml
on dfinity/pocketic-py
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
pocket_ic-3.0.0.tar.gz
- Subject digest:
1283ab09c6942088d13e3abd28f5865456e1d9ab9759c9da8e816b222ee50b7b
- Sigstore transparency entry: 149972651
- Sigstore integration time:
- Predicate type:
File details
Details for the file pocket_ic-3.0.0-py3-none-any.whl
.
File metadata
- Download URL: pocket_ic-3.0.0-py3-none-any.whl
- Upload date:
- Size: 13.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c980dfeb0ca6fd39f6051511463e9f141e95cfb114551f49589429049d6825e3 |
|
MD5 | 1b08cd21cb31454b7b2b4c3b932ad94d |
|
BLAKE2b-256 | e23bddb8797c629947c48b48515807ef045f2492a7787521697bde54b030e7d2 |
Provenance
The following attestation bundles were made for pocket_ic-3.0.0-py3-none-any.whl
:
Publisher:
build.yml
on dfinity/pocketic-py
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
pocket_ic-3.0.0-py3-none-any.whl
- Subject digest:
c980dfeb0ca6fd39f6051511463e9f141e95cfb114551f49589429049d6825e3
- Sigstore transparency entry: 149972653
- Sigstore integration time:
- Predicate type: