Skip to content

Commit

Permalink
pm-api branch cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
njgheorghita committed Oct 27, 2018
1 parent 34c8830 commit 9de5e00
Show file tree
Hide file tree
Showing 17 changed files with 490 additions and 253 deletions.
14 changes: 7 additions & 7 deletions docs/web3.pm.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ Installation

.. warning:: The PM module is still under development, and not all use-cases are currently supported, so it is not included by default in the web3 instance.

You must install the eth-pm module separately, until it is stable. Install with:

.. code-block:: python
pip install --upgrade ethpm
Attaching
---------

Expand All @@ -34,4 +28,10 @@ Methods

The following methods are available on the ``web3.pm`` namespace.

TODO: autoclass docstrings once ``web3.pm`` is stable.
.. autoclass:: web3.pm.PM
:members:

.. note:: The ``web3.pm.Registry`` class is not designed to be interacted with directly, rather via the ``web3.pm.PM`` api.

.. autoclass:: web3.pm.Registry
:members:
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@
"eth-abi>=1.2.0,<2.0.0",
"eth-account>=0.2.1,<0.4.0",
"eth-utils>=1.2.0,<2.0.0",
"ethpm>=0.1.4a5,<1",
"pytest-ethereum>=0.1.3a1,<1",
"hexbytes>=0.1.0,<1.0.0",
"lru-dict>=1.1.6,<2.0.0",
"eth-hash[pycryptodome]>=0.2.0,<1.0.0",
Expand Down
21 changes: 6 additions & 15 deletions tests/core/pm-module/test_ens_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,18 @@
from eth_utils import (
to_canonical_address,
)
from ethpm import (
ASSETS_DIR,
)

from ens import ENS
from web3 import Web3
from web3.exceptions import (
InvalidAddress,
)

try:
from ethpm import (
ASSETS_DIR,
)
from web3.pm import (
PM,
)
except ImportError:
ethpm_installed = False
else:
ethpm_installed = True
from web3.pm import (
PM,
)


def bytes32(val):
Expand Down Expand Up @@ -128,15 +122,13 @@ def ens(ens_setup, mocker):
return ens_setup


@pytest.mark.skipif(ethpm_installed is False, reason="ethpm is not installed")
def test_ens_must_be_set_before_ens_methods_can_be_used(ens):
w3 = ens.web3
PM.attach(w3, 'pm')
with pytest.raises(InvalidAddress):
w3.pm.set_registry("tester.eth")


@pytest.mark.skipif(ethpm_installed is False, reason="ethpm is not installed")
def test_web3_ens(ens):
w3 = ens.web3
PM.attach(w3, 'pm')
Expand All @@ -155,7 +147,6 @@ def test_web3_ens(ens):
assert manifest_uri.rstrip(b'\x00') == b'1.com'


@pytest.mark.skipif(ethpm_installed is False, reason="ethpm is not installed")
def test_registry_init_with_ens_name(ens):
w3 = ens.web3
PM.attach(w3, 'pm')
Expand Down
34 changes: 12 additions & 22 deletions tests/core/pm-module/test_pm_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,44 @@
from eth_utils import (
to_canonical_address,
)
from ethpm import (
Package,
)
from ethpm.exceptions import (
InsufficientAssetsError,
)
from ethpm.tools import (
get_manifest as get_ethpm_manifest,
)

from web3 import Web3

try:
from ethpm import Package # noqa: E402
from ethpm.tools import get_manifest as get_ethpm_manifest
from ethpm.exceptions import (
InsufficientAssetsError,
)
except ImportError:
ethpm_installed = False
else:
ethpm_installed = True
from web3.pm import (
PM,
)


# Returns web3 instance with `pm` module attached
@pytest.fixture
def web3():
w3 = Web3(Web3.EthereumTesterProvider())
w3.eth.defaultAccount = w3.eth.accounts[0]
try:
from web3.pm import PM # noqa: F811
except ModuleNotFoundError as exc:
assert False, "eth-pm import failed because: %s" % exc
PM.attach(w3, 'pm')
return w3


@pytest.mark.skipif(ethpm_installed is False, reason="ethpm is not installed")
def test_pm_init_with_minimal_manifest(web3):
owned_manifest = get_ethpm_manifest('owned', '1.0.1.json')
pm = web3.pm.get_package_from_manifest(owned_manifest)
assert pm.name == 'owned'


@pytest.mark.skipif(ethpm_installed is False, reason="ethpm is not installed")
def test_get_contract_factory_raises_insufficient_assets_error(web3):
insufficient_owned_manifest = get_ethpm_manifest('owned', '1.0.0.json')
owned_package = web3.pm.get_package_from_manifest(insufficient_owned_manifest)
with pytest.raises(InsufficientAssetsError):
owned_package.get_contract_factory('Owned')


@pytest.mark.skipif(ethpm_installed is False, reason="ethpm is not installed")
def test_get_contract_factory_with_valid_owned_manifest(web3):
owned_manifest = get_ethpm_manifest('owned', '1.0.1.json')
owned_package = web3.pm.get_package_from_manifest(owned_manifest)
Expand All @@ -58,7 +52,6 @@ def test_get_contract_factory_with_valid_owned_manifest(web3):
assert owned_instance.abi == owned_factory.abi


@pytest.mark.skipif(ethpm_installed is False, reason="ethpm is not installed")
def test_get_contract_factory_with_valid_safe_math_lib_manifest(web3):
safe_math_lib_manifest = get_ethpm_manifest('safe-math-lib', '1.0.1.json')
safe_math_package = web3.pm.get_package_from_manifest(safe_math_lib_manifest)
Expand All @@ -70,7 +63,6 @@ def test_get_contract_factory_with_valid_safe_math_lib_manifest(web3):
assert safe_math_instance.functions.safeAdd(1, 2).call() == 3


@pytest.mark.skipif(ethpm_installed is False, reason="ethpm is not installed")
def test_get_contract_factory_with_valid_escrow_manifest(web3):
escrow_manifest = get_ethpm_manifest("escrow", "1.0.2.json")
escrow_package = web3.pm.get_package_from_manifest(escrow_manifest)
Expand All @@ -89,7 +81,6 @@ def test_get_contract_factory_with_valid_escrow_manifest(web3):
assert escrow_instance.functions.sender().call() == web3.eth.accounts[0]


@pytest.mark.skipif(ethpm_installed is False, reason="ethpm is not installed")
def test_deploy_a_standalone_package_integration(web3):
standard_token_manifest = get_ethpm_manifest("standard-token", "1.0.1.json")
token_package = web3.pm.get_package_from_manifest(standard_token_manifest)
Expand All @@ -104,7 +95,6 @@ def test_deploy_a_standalone_package_integration(web3):
assert total_supply == 100


@pytest.mark.skipif(ethpm_installed is False, reason="ethpm is not installed")
def test_pm_init_with_manifest_uri(web3, monkeypatch):
monkeypatch.setenv(
"ETHPM_IPFS_BACKEND_CLASS", "ethpm.backends.ipfs.DummyIPFSBackend"
Expand Down
Loading

0 comments on commit 9de5e00

Please sign in to comment.