Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dfinity/pocketic-py
PocketIC Python: A Canister Testing Library for the Internet Computer
https://github.com/dfinity/pocketic-py
canister canisters dfinity icp internet-computer internet-computer-protocol python smart-contract smart-contracts testing testing-tools
Last synced: 5 days ago
JSON representation
PocketIC Python: A Canister Testing Library for the Internet Computer
- Host: GitHub
- URL: https://github.com/dfinity/pocketic-py
- Owner: dfinity
- License: other
- Created: 2023-08-21T07:46:07.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-09-05T15:29:00.000Z (2 months ago)
- Last Synced: 2024-10-14T13:16:41.388Z (24 days ago)
- Topics: canister, canisters, dfinity, icp, internet-computer, internet-computer-protocol, python, smart-contract, smart-contracts, testing, testing-tools
- Language: Python
- Homepage: https://internetcomputer.org/
- Size: 725 KB
- Stars: 11
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Codeowners: CODEOWNERS
Awesome Lists containing this project
- awesome-internet-computer - pocketic-py - A canister testing library that supports deterministic, programmatic canister testing in Python. (Developer Tooling / Testing)
README
# PocketIC Python: A Canister Testing Library
[PocketIC](https://github.com/dfinity/pocketic) is a local canister testing solution for the [Internet Computer](https://internetcomputer.org/).
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:
```python
from pocket_ic import PocketICpic = 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:
```python
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](https://github.com/dfinity/pocketic).
* 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/](https://github.com/dfinity/pocketic-py/tree/main/examples) folder, or check out the [how to use this library](https://github.com/dfinity/pocketic-py/blob/main/HOWTO.md) 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](https://github.com/dfinity/icp-hello-world-motoko/blob/main/README.md#testing-your-project) repository.## Documentation
* [How to use this library](https://github.com/dfinity/pocketic-py/blob/main/HOWTO.md)
* [PocketIC repo](https://github.com/dfinity/pocketic)
* [PocketIC server compatibility](https://docs.google.com/document/d/1VYmHUTjrgbzRHtsAyRrI5cj-gWGs7ktTnutPvUMJioU/edit?usp=sharing)
* [Why PocketIC](https://github.com/dfinity/pocketic#why-pocketic)
* [Changelog of PocketIC Python](https://github.com/dfinity/pocketic-py/blob/main/CHANGELOG.md)## Contributing
See [CONTRIBUTING.md](https://github.com/dfinity/pocketic-py/blob/main/CONTRIBUTING.md)