PyTest plugin for testing Smart Contracts for Ethereum blockchain.
Project description
PyTest-Cobra
PyTest plugin for testing Smart Contracts for Ethereum blockchain.
Dependency
This library requires the solc
executable to be present.
Only versions >=0.4.2
are supported and tested though this library may work
with other versions.
solc installation instructions
Install Solidity compiler (solc) using Node Package Manager(npm)
npm install -g solc
or for Ubuntu(Linux)
sudo add-apt-repository ppa:ethereum/ethereum
sudo apt-get update
sudo apt-get install solc
Quickstart
Installation
pip install pytest-cobra
Development
Clone the repository and then run
pip install -e . -r requirements.txt
Usage
Execute your test suite
Example MetaCoin picture
# MetaCoin Testing
# cobra is pytest fixture
def test_metacoin(cobra):
# Getting Contract Factory by name
metacoin = cobra.contract('MetaCoin')
# Getting Contract Instance of MetaCoin
metacoin = metacoin.deploy()
assert metacoin.getBalance(cobra.accounts[0]) == 10000
Running test from Solidity file (.sol)
pytest --cobra MetaCoin.sol
Optional commands
Import path remappings
solc
provides path aliasing allow you to have more reusable project configurations.
pytest --cobra MetaCoin.sol --import_remappings ["zeppeling=/my-zeppelin-checkout-folder"]
Allow paths
pytest --cobra MetaCoin.sol --allow_paths "/home/meheret,/user,/"
Running test from compiled Contracts Json file (.json)
Compile your contracts into a package (soon to be ethPM-compliant)
solc --combined-json abi,bin,bin-runtime contracts/ > MetaCoin.json
Testing Contracts.json
pytest --cobra MetaCoin.json
Running test from Yaml file (.yaml)
Comming Soon
with Cobra Framework
Further help
PyTest
Go check out the PyTest.
Author
# Meheret Tesfaye @meherett.
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 Distribution
Hashes for pytest_cobra-1.0.0a1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b9036d63be77bd512607d2744a698ae3aca9a1125b824eaff8f51aac023898f |
|
MD5 | 330cbd3f9bb56a6aef29169bd4bdaa2a |
|
BLAKE2b-256 | abcc48e631e4487469ac8917faba69532414dadb38e2a2efec5218b7b1333954 |