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 - Initial work - Cobra
License
This project is licensed under the MIT License - see the LICENSE file for details
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
File details
Details for the file pytest-cobra-1.0.3.tar.gz
.
File metadata
- Download URL: pytest-cobra-1.0.3.tar.gz
- Upload date:
- Size: 9.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e95e59aeb57fd155d5aa336e81b9a6097e53c6f7fbb1856903d8f0b0b426381b |
|
MD5 | 894b0065fdffef4623cc548309066740 |
|
BLAKE2b-256 | 2c508d3d8347c13a53cdda2851781d037c190088aa41c1aafd2d4e87f62ca336 |
File details
Details for the file pytest_cobra-1.0.3-py3-none-any.whl
.
File metadata
- Download URL: pytest_cobra-1.0.3-py3-none-any.whl
- Upload date:
- Size: 8.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 22909e3e6b23e4293b9702883b0dc9b69a92ea39199b78768b2e06071dc710a8 |
|
MD5 | 1ae6d85af4f501286de8461c56bf5e18 |
|
BLAKE2b-256 | cbcc91550c4c99af0ff481f4cd6054a4e755c24c0fb25faf50937d3a687953cf |