IPYEOS project
Project description
Interactive Python for Eos
What Is IPyEos
- IPyEos is a Smart Contracts test framework for Eos
- IPyEos is a Python binding for Eos
Installation
python3 -m pip install ipyeos
on the macOS platform, you may need to install gmp
and zstd
if you don't install them.
brew reinstall gmp
brew reinstall zstd
If your platform is Windows or MacOSX M1/M2, you also need to download an image that includes the ipyeos tool:
docker pull ghcr.io/uuosio/ipyeos:latest
If you have not installed the ipyeos image in Docker, then the ipyeos image will be automatically downloaded the first time you run ipyeos
or eosdebugger
.
On macOS, the recommended software for installing and running Docker is OrbStack. For other platforms, you can use Docker Desktop.
Test Examples
Example 1:
#test.py
import os
from ipyeos.chaintester import ChainTester
chaintester.chain_config['contracts_console'] = True
def test_example():
t = ChainTester(True)
with open('./hello/build/hello/hello.wasm', 'rb') as f:
code = f.read()
with open('./hello/build/hello/hello.abi', 'rb') as f:
abi = f.read()
t.deploy_contract('hello', code, abi)
t.produce_block()
t.push_action('hello', 'hi', {'nm': 'alice'}, {'hello': 'active'})
t.produce_block()
Test:
ipyeos -m pytest -x -s tests/test.py
Restore from snapshot Example
def test_snapshot():
# data_name = './data'
# snapshot_dir = './snapshot-2023-06-18-01-eos-v6-0315729695.bin'
# state_size = 32*1024*1024*1024
if os.path.exists('./data/ddd'):
shutil.rmtree('./data/ddd')
state_size = 10*1024*1024
data_name = './data'
snapshot_dir = './data/snapshot-0000001ba25b3b5af4ba6cacecb68ef4238a50bb7134e56fe985b4355fbf7488.bin'
t = ChainTester(True, data_dir=os.path.join(data_name, 'ddd'), config_dir=os.path.join(data_name, 'cd'), state_size=state_size, snapshot_dir=snapshot_dir)
Accessing Database Object Example
def test_database_object():
# data_name = './data'
# snapshot_dir = './snapshot-2023-06-18-01-eos-v6-0315729695.bin'
# state_size = 32*1024*1024*1024
if os.path.exists('./data/ddd'):
shutil.rmtree('./data/ddd')
state_size = 10*1024*1024
data_name = './data'
snapshot_dir = './data/snapshot-0000001ba25b3b5af4ba6cacecb68ef4238a50bb7134e56fe985b4355fbf7488.bin'
# {'private': '5K3x5DPEbocfZSG8XD3RiyJAfPFH5Bd9ED15wtdEMbqzXCLPbma',
# 'public': 'EOS5K93aPtTdov2zWDqYxVcMQ4GBT1hyEpED8tjzPuLsf31tPySNY'}
# must call set_debug_producer_key and import_producer_key before create ChainTester
eos.set_debug_producer_key('EOS5K93aPtTdov2zWDqYxVcMQ4GBT1hyEpED8tjzPuLsf31tPySNY')
chaintester.import_producer_key('5K3x5DPEbocfZSG8XD3RiyJAfPFH5Bd9ED15wtdEMbqzXCLPbma')
t = ChainTester(True, data_dir=os.path.join(data_name, 'ddd'), config_dir=os.path.join(data_name, 'cd'), state_size=state_size, snapshot_dir=snapshot_dir)
logger.info("+++++producer keys: %s", t.chain.get_producer_public_keys())
t.produce_block()
logger.info("+++++++%s", t.api.get_info())
idx = PermissionObjectIndex(t.db)
perm = idx.find_by_owner('eosio.token', 'active')
print(perm)
# Private key: 5JBW9jddvqHY7inGEK2qWbGLYKeqm32NDYL3fLdYgMjnWxRjXLF
# Public key: EOS6hM1U89jbHWyX8ArHttFzoGe21y7ehXvtN5q7GbDxYEa9NFXH2
t.import_key('5JBW9jddvqHY7inGEK2qWbGLYKeqm32NDYL3fLdYgMjnWxRjXLF')
keys = [KeyWeight(PublicKey.from_base58('EOS6hM1U89jbHWyX8ArHttFzoGe21y7ehXvtN5q7GbDxYEa9NFXH2'), 1)]
perm.auth = Authority(1, keys, [], [])
ret = idx.modify(perm)
print('modify_by_id return:', ret)
idx = PermissionObjectIndex(t.db)
perm = idx.find_by_owner('eosio.token', 'active')
print(perm)
Push Block Example:
def test_push_block():
if os.path.exists('./data/ddd'):
shutil.rmtree('./data/ddd')
state_size = 10*1024*1024
data_name = './data'
snapshot_dir = './data/push_block/snapshot-0000003b83662343c208e965654f4d906ed7fad0372e13c246981cd076d379bb.bin'
t = ChainTester(True, data_dir=os.path.join(data_name, 'ddd'), config_dir=os.path.join(data_name, 'cd'), state_size=state_size, snapshot_dir=snapshot_dir)
t.free()
snapshot_dir = ''
t = ChainTester(True, data_dir=os.path.join(data_name, 'ddd'), config_dir=os.path.join(data_name, 'cd'), state_size=state_size, snapshot_dir=snapshot_dir)
t.chain.abort_block()
info = t.api.get_info()
head_block_num = info['head_block_num']
log = BlockLog('./data/push_block/blocks')
logger.info("%s %s", head_block_num, log.head_block_num())
num_count = log.head_block_num() - head_block_num
for block_num in range(head_block_num+1, head_block_num+num_count+1):
t.chain.push_block(log, block_num)
Building
To build this project, please follow the steps below:
- Clone the source code from the repository:
git clone https://github.com/uuosio/ipyeos --branch main --recursive
-
Build the forked leap source code under the
leap
directory by following the instructions in the build-and-install-from-source documentation. -
Build the Python release package:
cd ipyeos
./build.sh
- Install the Python package
python3 -m pip install dist/pyeos-0.4.9**.whl
Run a Node
eosnode
Run a Debugging Server
eosdebugger
Testing
test example code
#test.py
import os
from ipyeos.chaintester import ChainTester
chaintester.chain_config['contracts_console'] = True
def test_example():
t = ChainTester(True)
with open('./hello/build/hello/hello.wasm', 'rb') as f:
code = f.read()
with open('./hello/build/hello/hello.abi', 'rb') as f:
abi = f.read()
t.deploy_contract('hello', code, abi)
t.produce_block()
t.push_action('hello', 'hi', {'nm': 'alice'}, {'hello': 'active'})
t.produce_block()
ipyeos -m pytest -x -s tests/test.py
Run a Testnet
ipyeos -m ipyeos eosnode --data-dir dd --config-dir cd -p eosio --plugin eosio::producer_plugin --plugin eosio::chain_api_plugin --plugin eosio::producer_api_plugin -e --resource-monitor-space-threshold 99 --http-server-address 127.0.0.1:8889 --contracts-console --access-control-allow-origin="*" --wasm-runtime eos-vm-jit
Also, you can run a test node with eosnode
command directly.
eosnode --data-dir dd --config-dir cd -p eosio --plugin eosio::producer_plugin --plugin eosio::chain_api_plugin --plugin eosio::producer_api_plugin -e --resource-monitor-space-threshold 99 --http-server-address 127.0.0.1:8889 --contracts-console --access-control-allow-origin="*" --wasm-runtime eos-vm-jit
Note
If you encounter the error message during running the above commands like Failed to load libpython3.7m.so!
, try running the following command in your terminal:
export PYTHON_SHARED_LIB_PATH=path/to/libpython[.so|.dylib]
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file ipyeos-0.4.9.tar.gz
.
File metadata
- Download URL: ipyeos-0.4.9.tar.gz
- Upload date:
- Size: 1.1 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f62c883ff347a010c5a8154b12444a51c6c7337e7cb474bd384a67624a014867 |
|
MD5 | 4f0a0add4bd85e4c4b77d4d674e5097b |
|
BLAKE2b-256 | 4577c99fc393b87fc3362d8e33f8cdf15bad1c11fad6b19f6327be13105a32a6 |
File details
Details for the file ipyeos-0.4.9-cp311-cp311-manylinux_2_31_x86_64.whl
.
File metadata
- Download URL: ipyeos-0.4.9-cp311-cp311-manylinux_2_31_x86_64.whl
- Upload date:
- Size: 34.4 MB
- Tags: CPython 3.11, manylinux: glibc 2.31+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dd118c93786386f344cdc40b3f3d949071a1dc3a49b8a5ce8bbb5a951fe3c8b4 |
|
MD5 | bae498912e78ded1a556fd123ac5fd31 |
|
BLAKE2b-256 | efe49b4b278f681818a44527fdf29b382aab7d3522a880045899d6d5d8e0bfb2 |
File details
Details for the file ipyeos-0.4.9-cp311-cp311-macosx_10_15_x86_64.whl
.
File metadata
- Download URL: ipyeos-0.4.9-cp311-cp311-macosx_10_15_x86_64.whl
- Upload date:
- Size: 12.4 MB
- Tags: CPython 3.11, macOS 10.15+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 26448d76b1a316c0ffbdacdc01d5c61c54449ec7d04e2b1ffbaa8f978f2cb444 |
|
MD5 | 51548c8e2f96dba07bb487d3e72ecf87 |
|
BLAKE2b-256 | bae05bb94c260c60e3acb32706bb96347ce90e801c3eb91bdd426367a63054d1 |
File details
Details for the file ipyeos-0.4.9-cp310-cp310-manylinux_2_31_x86_64.whl
.
File metadata
- Download URL: ipyeos-0.4.9-cp310-cp310-manylinux_2_31_x86_64.whl
- Upload date:
- Size: 34.4 MB
- Tags: CPython 3.10, manylinux: glibc 2.31+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e1d93d6358bebb84bc2826dcc357c54d93abb0103b0cda7363ec15bb2637c805 |
|
MD5 | 52bcf92c7e170946e14d211f9922251c |
|
BLAKE2b-256 | 6664d03278262c0027fb07e4c495a19c34d20e01b276b453abf702ba0aa8e7f5 |
File details
Details for the file ipyeos-0.4.9-cp310-cp310-macosx_10_15_x86_64.whl
.
File metadata
- Download URL: ipyeos-0.4.9-cp310-cp310-macosx_10_15_x86_64.whl
- Upload date:
- Size: 12.4 MB
- Tags: CPython 3.10, macOS 10.15+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8e4f7b70b07d7531d22471080a02ec7cc2a979b3b9f3137a617b6271d42e34f3 |
|
MD5 | cf91b3a4419d9e26f6b76f8a560da15a |
|
BLAKE2b-256 | f82844d018111c9df2cd36e64c83760b613ba92f1ac98d3707ec083eff936c64 |
File details
Details for the file ipyeos-0.4.9-cp39-cp39-manylinux_2_31_x86_64.whl
.
File metadata
- Download URL: ipyeos-0.4.9-cp39-cp39-manylinux_2_31_x86_64.whl
- Upload date:
- Size: 34.3 MB
- Tags: CPython 3.9, manylinux: glibc 2.31+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cfa61c038801539c9bd0c68d8124948280e4c31789cca816ca0c2410f36b0a1c |
|
MD5 | 744091321b8e2784eceaf1c518735e09 |
|
BLAKE2b-256 | e7cea5759e5dadfbf28db2097ea03389e1d0a6056a6fd27dbde725edbdf2dd91 |
File details
Details for the file ipyeos-0.4.9-cp39-cp39-macosx_10_15_x86_64.whl
.
File metadata
- Download URL: ipyeos-0.4.9-cp39-cp39-macosx_10_15_x86_64.whl
- Upload date:
- Size: 12.4 MB
- Tags: CPython 3.9, macOS 10.15+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | eebe3f5be166e6be2c99c55868e755b3e0442effea850eed4a509cc1d017f633 |
|
MD5 | f4bd68aa0c7f8a664d7967f9454ca02e |
|
BLAKE2b-256 | 9a32ab5a2791489f5e606960ee9992f6876bb925165a4f785aa6052c5d6cfb5b |
File details
Details for the file ipyeos-0.4.9-cp38-cp38-manylinux_2_31_x86_64.whl
.
File metadata
- Download URL: ipyeos-0.4.9-cp38-cp38-manylinux_2_31_x86_64.whl
- Upload date:
- Size: 34.3 MB
- Tags: CPython 3.8, manylinux: glibc 2.31+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f26360674a6cf9a95a4ffccd03b5566db5548900a63b006673a47f9d55430e60 |
|
MD5 | 30e878af783f03af794f7c9b8e112fef |
|
BLAKE2b-256 | 0787ac9a1774f05181049d2013ee1d4cc922110eaa37df4bab2a305704574275 |
File details
Details for the file ipyeos-0.4.9-cp38-cp38-macosx_10_15_x86_64.whl
.
File metadata
- Download URL: ipyeos-0.4.9-cp38-cp38-macosx_10_15_x86_64.whl
- Upload date:
- Size: 12.4 MB
- Tags: CPython 3.8, macOS 10.15+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1182775dc84649e9c7a27e491b49c2d44dd099ecb2971fac45eaf6ffa0a014cb |
|
MD5 | fbf6c3727aeb3d12439363fbc4fa23b4 |
|
BLAKE2b-256 | 662259dcbe0616d9c536dbe5d099766b23b520e68672c68e4e24533b13f69de6 |