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 26, 2018
1 parent 34c8830 commit 859dadd
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 75 deletions.
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.4a1,<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 @@ -5,22 +5,16 @@
)

from ens import ENS
from ethpm import (
ASSETS_DIR,
)
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
37 changes: 9 additions & 28 deletions tests/core/pm-module/test_pm_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,17 @@
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


# Returns web3 instance with `pm` module attached
@pytest.fixture
Expand All @@ -31,22 +29,19 @@ def web3():
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 +53,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 +64,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 +82,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 @@ -102,14 +94,3 @@ def test_deploy_a_standalone_package_integration(web3):
erc20 = web3.eth.contract(address=address, abi=ERC20.abi)
total_supply = erc20.functions.totalSupply().call()
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"
)
dummy_standard_token_uri = "ipfs://QmVu9zuza5mkJwwcFdh2SXBugm1oSgZVuEKkph9XLsbUwg"
pkg = web3.pm.get_package_from_uri(dummy_standard_token_uri)
assert isinstance(pkg, Package)
assert pkg.name == "standard-token"
45 changes: 13 additions & 32 deletions tests/core/pm-module/test_registry_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,23 @@
to_canonical_address,
)

from ethpm import (
ASSETS_DIR,
)
from ethpm.contract import (
LinkableContract,
)
from ethpm.exceptions import (
CannotHandleURI,
)
import pytest_ethereum as pte
from web3 import Web3
from web3.exceptions import (
PMError,
)

try:
from ethpm import (
ASSETS_DIR,
)
from ethpm.contract import (
LinkableContract,
)
from ethpm.exceptions import (
CannotHandleURI,
)
import pytest_ethereum as pte
from web3.pm import (
Registry,
)
except ImportError:
ethpm_installed = False
else:
ethpm_installed = True
from web3.pm import (
Registry,
)


@pytest.fixture
Expand All @@ -44,7 +38,6 @@ def w3():


# Solidity registry
@pytest.mark.skipif(ethpm_installed is False, reason="ethpm is not installed")
def test_with_solidity_registry_manifest(w3):
manifest_path = ASSETS_DIR / 'registry' / "1.0.2.json"
manifest = json.loads(manifest_path.read_text())
Expand All @@ -71,13 +64,11 @@ def vy_registry(twig_deployer, w3):


# `Registry` class tests
@pytest.mark.skipif(ethpm_installed is False, reason="ethpm is not installed")
def test_registry_init(vy_registry, w3):
# update to get_package_from_uri
assert vy_registry.registry.functions.owner().call() == w3.eth.accounts[0]


@pytest.mark.skipif(ethpm_installed is False, reason="ethpm is not installed")
def test_registry_releases_properly(vy_registry):
vy_registry.release(b"package", b"1.0.0", b"google.com")
release_data = vy_registry.get_release_data(b'package', b'1.0.0')
Expand All @@ -86,7 +77,6 @@ def test_registry_releases_properly(vy_registry):
assert release_data[2][:10] == b'google.com'


@pytest.mark.skipif(ethpm_installed is False, reason="ethpm is not installed")
def test_registry_get_all_package_names(vy_registry):
vy_registry.release(b"package1", b"1.0.0", b"p1.v1.0.0.com")
vy_registry.release(b"package1", b"1.0.1", b"p1.v1.0.1.com")
Expand Down Expand Up @@ -117,7 +107,6 @@ def test_registry_get_all_package_names(vy_registry):
)


@pytest.mark.skipif(ethpm_installed is False, reason="ethpm is not installed")
def test_registry_get_release_count(vy_registry):
vy_registry.release(b"package1", b"1.0.0", b"p1.v1.0.0.com")
vy_registry.release(b"package1", b"1.0.1", b"p1.v1.0.1.com")
Expand All @@ -133,7 +122,6 @@ def test_registry_get_release_count(vy_registry):
vy_registry.get_release_count(b'nope')


@pytest.mark.skipif(ethpm_installed is False, reason="ethpm is not installed")
def test_registry_get_all_package_versions(vy_registry):
vy_registry.release(b"package", b"1.0.0", b"p1.v1.0.0.com")
vy_registry.release(b"package", b"1.0.1", b"p1.v1.0.1.com")
Expand Down Expand Up @@ -164,28 +152,24 @@ def test_registry_get_all_package_versions(vy_registry):
)


@pytest.mark.skipif(ethpm_installed is False, reason="ethpm is not installed")
def test_registry_transfer_owner(vy_registry, w3):
vy_registry.transfer_owner(w3.eth.accounts[1])
assert vy_registry.registry.functions.owner().call() == w3.eth.accounts[1]


# web3.pm integration
@pytest.mark.skipif(ethpm_installed is False, reason="ethpm is not installed")
def test_pm_deploy_and_set_registry(w3):
assert not hasattr(w3.pm, 'registry')
w3.pm.deploy_and_set_registry()
assert isinstance(w3.pm.registry, Registry)


@pytest.mark.skipif(ethpm_installed is False, reason="ethpm is not installed")
def test_pm_set_registry(vy_registry, w3):
assert not hasattr(w3.pm, 'registry')
w3.pm.set_registry(address=to_canonical_address(vy_registry.address))
assert isinstance(w3.pm.registry, Registry)


@pytest.mark.skipif(ethpm_installed is False, reason="ethpm is not installed")
def test_pm_must_set_registry_before_registry_interaction_functions(w3):
with pytest.raises(PMError):
w3.pm.release_package(b'package', b'1.0.0', b'google.com')
Expand All @@ -195,23 +179,20 @@ def test_pm_must_set_registry_before_registry_interaction_functions(w3):
w3.pm.get_package(b'package', b'1.0.0')


@pytest.mark.skipif(ethpm_installed is False, reason="ethpm is not installed")
def test_pm_release_package(w3):
w3.pm.deploy_and_set_registry()
w3.pm.release_package(b'package', b'1.0.0', b'google.com')
package_data = w3.pm.get_release_data(b'package', b'1.0.0')
assert package_data[0][:7] == b'package'


@pytest.mark.skipif(ethpm_installed is False, reason="ethpm is not installed")
def test_pm_release_package_raises_exception_with_invalid_from_address(vy_registry, w3):
w3.pm.deploy_and_set_registry()
w3.eth.defaultAccount = w3.eth.accounts[1]
with pytest.raises(PMError):
w3.pm.release_package(b'package', b'1.0.0', b'google.com')


@pytest.mark.skipif(ethpm_installed is False, reason="ethpm is not installed")
def test_pm_get_package(w3):
w3.pm.deploy_and_set_registry()
w3.pm.release_package(b'package', b'1.0.0', b'google.com')
Expand Down
3 changes: 3 additions & 0 deletions web3/pm.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ def deploy_and_set_registry(self):
"""
Deploys a new instance of a Registry.vy and sets that Registry to ``web3.pm``.
(py-ethpm/ethpm/assets/vyper_registry/registry.v.py)
To tie your registry to an ENS name, use web3's ENS module, ie.
w3.ens.setup_address(ens_name, w3.pm.registry.address)
"""
self.registry = Registry.deploy_new_instance(self.web3)

Expand Down

0 comments on commit 859dadd

Please sign in to comment.