Package: ipyeos
Interactive Python for EosWhat Is IPyEosIPyEos is a Smart Contracts test framework for EosIPyEos is a Python binding for EosInstallationpython3 -m pip install ipyeoson the macOS platform, you may need to installgmpandzstdif you don't install them.brewreinstallgmp
brewreinstallzstdIf your platform is Windows or MacOSX M1/M2, you also need to download an image that includes the ipyeos tool:dockerpullghcr.io/uuosio/ipyeos:latestIf you have not installed the ipyeos image in Docker, then the ipyeos image will be automatically downloaded the first time you runipyeosoreosdebugger.On macOS, the recommended software for installing and running Docker isOrbStack. For other platforms, you can useDocker Desktop.Test ExamplesExample 1:#test.pyimportosfromipyeos.chaintesterimportChainTesterchaintester.chain_config['contracts_console']=Truedeftest_example():t=ChainTester(True)withopen('./hello/build/hello/hello.wasm','rb')asf:code=f.read()withopen('./hello/build/hello/hello.abi','rb')asf: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.pyRestore from snapshot Exampledeftest_snapshot():# data_name = './data'# snapshot_dir = './snapshot-2023-06-18-01-eos-v6-0315729695.bin'# state_size = 32*1024*1024*1024ifos.path.exists('./data/ddd'):shutil.rmtree('./data/ddd')state_size=10*1024*1024data_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 Exampledeftest_database_object():# data_name = './data'# snapshot_dir = './snapshot-2023-06-18-01-eos-v6-0315729695.bin'# state_size = 32*1024*1024*1024ifos.path.exists('./data/ddd'):shutil.rmtree('./data/ddd')state_size=10*1024*1024data_name='./data'snapshot_dir='./data/snapshot-0000001ba25b3b5af4ba6cacecb68ef4238a50bb7134e56fe985b4355fbf7488.bin'# {'private': '5K3x5DPEbocfZSG8XD3RiyJAfPFH5Bd9ED15wtdEMbqzXCLPbma',#  'public': 'EOS5K93aPtTdov2zWDqYxVcMQ4GBT1hyEpED8tjzPuLsf31tPySNY'}# must call set_debug_producer_key and import_producer_key before create ChainTestereos.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: EOS6hM1U89jbHWyX8ArHttFzoGe21y7ehXvtN5q7GbDxYEa9NFXH2t.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:deftest_push_block():ifos.path.exists('./data/ddd'):shutil.rmtree('./data/ddd')state_size=10*1024*1024data_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_numforblock_numinrange(head_block_num+1,head_block_num+num_count+1):t.chain.push_block(log,block_num)BuildingTo build this project, please follow the steps below:Clone the source code from the repository:gitclonehttps://github.com/uuosio/ipyeos--branchmain--recursiveBuild the forked leap source code under theleapdirectory by following the instructions in thebuild-and-install-from-sourcedocumentation.Build the Python release package:cdipyeos
./build.shInstall the Python packagepython3-mpipinstalldist/pyeos-0.4.9**.whlRun a NodeeosnodeRun a Debugging ServereosdebuggerTestingtest example code#test.pyimportosfromipyeos.chaintesterimportChainTesterchaintester.chain_config['contracts_console']=Truedeftest_example():t=ChainTester(True)withopen('./hello/build/hello/hello.wasm','rb')asf:code=f.read()withopen('./hello/build/hello/hello.abi','rb')asf: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.pyRun a Testnetipyeos-mipyeoseosnode--data-dirdd--config-dircd-peosio--plugineosio::producer_plugin--plugineosio::chain_api_plugin--plugineosio::producer_api_plugin-e--resource-monitor-space-threshold99--http-server-address127.0.0.1:8889--contracts-console--access-control-allow-origin="*"--wasm-runtimeeos-vm-jitAlso, you can run a test node witheosnodecommand directly.eosnode--data-dirdd--config-dircd-peosio--plugineosio::producer_plugin--plugineosio::chain_api_plugin--plugineosio::producer_api_plugin-e--resource-monitor-space-threshold99--http-server-address127.0.0.1:8889--contracts-console--access-control-allow-origin="*"--wasm-runtimeeos-vm-jitNoteIf you encounter the error message during running the above commands likeFailed to load libpython3.7m.so!, try running the following command in your terminal:exportPYTHON_SHARED_LIB_PATH=path/to/libpython[.so|.dylib]LicenseMIT