Skip to main content

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

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

pocket_ic-3.0.1.tar.gz (587.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pocket_ic-3.0.1-py3-none-any.whl (13.6 kB view details)

Uploaded Python 3

File details

Details for the file pocket_ic-3.0.1.tar.gz.

File metadata

  • Download URL: pocket_ic-3.0.1.tar.gz
  • Upload date:
  • Size: 587.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pocket_ic-3.0.1.tar.gz
Algorithm Hash digest
SHA256 4be09f9a45ae7e266f2a0f26105cec30a4c58317330355663248371bfabf42db
MD5 6a3188f71ae8bbb69080cde58c559786
BLAKE2b-256 6cee8628c0ff3cd53f516842ecba8d7669e4367d64eed965220ff72be494a53d

See more details on using hashes here.

Provenance

The following attestation bundles were made for pocket_ic-3.0.1.tar.gz:

Publisher: build.yml on dfinity/pocketic-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pocket_ic-3.0.1-py3-none-any.whl.

File metadata

  • Download URL: pocket_ic-3.0.1-py3-none-any.whl
  • Upload date:
  • Size: 13.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pocket_ic-3.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 86436b9917524c56e3396e3929da83b0dda1c8409ba2cde451974c7ddc3f2f4c
MD5 5de0129239e94f6d4220049ed7ab5c88
BLAKE2b-256 11305c9fedfe6ba30b1051468e3bc3a8c8b6233d8bda4bfd38cb43891eef4308

See more details on using hashes here.

Provenance

The following attestation bundles were made for pocket_ic-3.0.1-py3-none-any.whl:

Publisher: build.yml on dfinity/pocketic-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page