Skip to main content

PyTest-Cobra PyPI - Python Version

PyTest plugin for testing Smart Contracts for Ethereum blockchain.

Build Status PyPI Version GitHub License Github Date PyPI Wheel Donate with Ethereum

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

Metadata

Release files for pytest-cobra 1.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytest-cobra 1.0.4
File Size Uploaded
pytest-cobra-1.0.4.tar.gz 50.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-cobra 1.0.4
File Interpreter ABI Platform
pytest_cobra-1.0.4-py3-none-any.whl Python 3 none any Details

Total release size: 58.9 kB

Release files / pytest-cobra-1.0.4.tar.gz

Download URL pytest-cobra-1.0.4.tar.gz
Size 50.0 kB
Tags Source
SHA-256 checksum
How to use checksums
b2825ff4591d963b8ae7281591356b97fdc5f1235a38f2db2bbd4bdabd366e71
BLAKE2b-256 checksum
How to use checksums
4b67886082ff8c6ef6ea23a193f386e211d65de6ee9ab67ed5fb3ebd4fe11b7f
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / pytest_cobra-1.0.4-py3-none-any.whl

Download URL pytest_cobra-1.0.4-py3-none-any.whl
Size 8.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
431c4409f7ee1b5f835a56c31968b8a13e824c7dce8396d6c93d30e20af220f5
BLAKE2b-256 checksum
How to use checksums
823b5b97503e929174476f3c2bb01cc92502daa42c1c1f351f41dc3e966b0f48
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

This release

1.0.4 This release

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page