Skip to content

Commit

Permalink
Merge pull request humanprotocol#215 from hCaptcha/fix/dist
Browse files Browse the repository at this point in the history
Update web3 and py-evm using trinity
  • Loading branch information
uivlis authored Jul 31, 2020
2 parents ef68280 + 0e867ff commit 529f294
Show file tree
Hide file tree
Showing 12 changed files with 1,521 additions and 54 deletions.
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ src
.vscode
docker-compose
build/
node_modules/
coverage/
coverage.json
minio/
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
sudo: required
language: python
python:
- '3.6'
- '3.8'
services:
- docker
script:
Expand Down
17 changes: 11 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
FROM ubuntu:focal
ENV LANG C.UTF-8
ENV DEBIAN_FRONTEND noninteractive
ENV PYTHONPATH "/usr/lib/python3.6/:/usr/local/lib/python3.6/dist-packages/:/work:/work/banhammer:/work/hmt-servers"
ENV PYTHONUNBUFFERED True

WORKDIR /work

RUN apt-get update -y && \
apt-get install -y automake bash black build-essential curl git jq libffi-dev libgmp-dev libtool mypy nodejs npm \
pandoc pkg-config python3-boto python3-dev python3-pip
pandoc pkg-config python3-boto python3-dev python3-pip libsnappy-dev

ENV PYTHONPATH "/usr/lib/python3.8/:/usr/local/lib/python3.8/dist-packages/:/work:/work/banhammer:/work/hmt-servers"

COPY package.json /work/
RUN npm install
COPY package.json package-lock.json /work/
RUN cd /work && npm install
ENV PATH="/work/node_modules/.bin/:${PATH}"

COPY requirements.txt /work/
RUN pip3 install -r requirements.txt
# Pin to specific version that's guaranteed to work
RUN pip3 install pipenv
COPY Pipfile Pipfile.lock /work/
RUN pipenv install --system --deploy --pre

ENV SOLC_VERSION="v0.6.2"
RUN python3 -m solcx.install ${SOLC_VERSION}
Expand Down
19 changes: 19 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]

[packages]
trinity = {git = "https://github.com/ethereum/trinity.git", ref = "master"}
py-solc-x = {git = "https://github.com/iamdefinitelyahuman/py-solc-x.git", ref = "master"}
boto3 = "*"
hmt-basemodels = "*"
Sphinx = {git = "https://github.com/sphinx-doc/sphinx.git", ref = "master"}

[requires]
python_version = "3.8"

[pipenv]
allow_prereleases = true
1,448 changes: 1,448 additions & 0 deletions Pipfile.lock

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion bin/ci
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ set -exu
docker-compose build
docker-compose run --no-deps -e CI=true job './bin/lint'
docker-compose run -w /work job
docker-compose run -w /work contracts
./bin/stop
./bin/generate-docs
14 changes: 3 additions & 11 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ services:
- ESCROW_AWS_DEFAULT_REGION=us-west-2
- DEBUG=true
- USE_ESCROW_S3_STORAGE=True
command: sh -c "rm /deployed-hmtoken/hmt.address.json; curl --retry 10 --retry-connrefused --retry-max-time 10 http://ganache:8545; npm install; npm run compile; /work/bin/wait_then_run"
depends_on:
- minio
- ganache
links:
- ganache
- ipfs
Expand All @@ -30,18 +30,10 @@ services:
- eth_kvstore_addr:/deployed-kvstore
- ./minio:/data
- .:/work

contracts:
environment:
- ETH_HOST=ganache
- ETH_PORT=8545
command: sh -c "npm install; npm run test"
image: hcaptcha/hmt-escrow:latest
links:
- ganache
command: sh -c "rm /deployed-hmtoken/hmt.address.json; curl --retry 10 --retry-connrefused --retry-max-time 10 http://ganache:8545; cd /work && npm install && npm run test; ./bin/wait_then_run"

ganache:
image: trufflesuite/ganache-cli:v6.9.1
image: trufflesuite/ganache-cli:latest
command: node ./build/cli.node.js --noVMErrorsOnRPCResponse -m goat --hostname 0.0.0.0 --unlock 0x1413862c2b7054cdbfdc181b83962cb0fc11fd92 -g 1000
ports:
- 8545:8545
Expand Down
34 changes: 21 additions & 13 deletions hmt_escrow/eth_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@
import unittest

from solcx import compile_files
from web3 import Web3, HTTPProvider, EthereumTesterProvider
from web3 import Web3
from web3.providers import HTTPProvider
from web3.providers.eth_tester import EthereumTesterProvider
from web3.types import TxReceipt
from eth_typing import Address, ChecksumAddress, HexAddress, HexStr
from web3.contract import Contract
from web3.middleware import geth_poa_middleware
from web3.utils.transactions import wait_for_transaction_receipt
from web3._utils.transactions import wait_for_transaction_receipt
from hmt_escrow.kvstore_abi import abi as kvstore_abi
from typing import Dict, List, Tuple, Optional, Any

Expand Down Expand Up @@ -53,13 +57,13 @@ def get_w3() -> Web3:
endpoint = os.getenv("HMT_ETH_SERVER", "http://localhost:8545")
if not endpoint:
LOG.error("Using EthereumTesterProvider as we have no HMT_ETH_SERVER")
provider = HTTPProvider(endpoint) if endpoint else EthereumTesterProvider
provider = HTTPProvider(endpoint) if endpoint else EthereumTesterProvider()
w3 = Web3(provider)
w3.middleware_stack.inject(geth_poa_middleware, layer=0)
w3.middleware_onion.inject(geth_poa_middleware, layer=0)
return w3


def handle_transaction(txn_func, *args, **kwargs) -> AttributeDict:
def handle_transaction(txn_func, *args, **kwargs) -> TxReceipt:
"""Handles a transaction that updates the contract state by locally
signing, building, sending the transaction and returning a transaction
receipt.
Expand Down Expand Up @@ -119,7 +123,7 @@ def get_hmtoken(hmtoken_addr=HMTOKEN_ADDR) -> Contract:
"""Retrieve the HMToken contract from a given address.
>>> type(get_hmtoken())
<class 'web3.utils.datatypes.Contract'>
<class 'web3._utils.datatypes.Contract'>
Returns:
Contract: returns the HMToken solidity contract.
Expand Down Expand Up @@ -148,7 +152,7 @@ def get_escrow(escrow_addr: str) -> Contract:
>>> job.launch(rep_oracle_pub_key)
True
>>> type(get_escrow(job.job_contract.address))
<class 'web3.utils.datatypes.Contract'>
<class 'web3._utils.datatypes.Contract'>
Args:
escrow_addr (str): an ethereum address of the escrow contract.
Expand All @@ -162,11 +166,14 @@ def get_escrow(escrow_addr: str) -> Contract:
contract_interface = get_contract_interface(
"{}/Escrow.sol:Escrow".format(CONTRACT_FOLDER)
)
escrow = w3.eth.contract(address=escrow_addr, abi=contract_interface["abi"])
escrow = w3.eth.contract(
address=ChecksumAddress(HexAddress(HexStr(escrow_addr))),
abi=contract_interface["abi"],
)
return escrow


def get_factory(factory_addr: Optional[str]) -> Contract:
def get_factory(factory_addr: str) -> Contract:
"""Retrieve the EscrowFactory contract from a given address.
>>> credentials = {
Expand All @@ -175,7 +182,7 @@ def get_factory(factory_addr: Optional[str]) -> Contract:
... }
>>> job = Job(credentials=credentials, escrow_manifest=manifest)
>>> type(get_factory(job.factory_contract.address))
<class 'web3.utils.datatypes.Contract'>
<class 'web3._utils.datatypes.Contract'>
Args:
factory_addr (str): the ethereum address of the Escrow contract.
Expand All @@ -189,7 +196,8 @@ def get_factory(factory_addr: Optional[str]) -> Contract:
"{}/EscrowFactory.sol:EscrowFactory".format(CONTRACT_FOLDER)
)
escrow_factory = w3.eth.contract(
address=factory_addr, abi=contract_interface["abi"]
address=ChecksumAddress(HexAddress(HexStr(factory_addr))),
abi=contract_interface["abi"],
)
return escrow_factory

Expand Down Expand Up @@ -220,7 +228,7 @@ def deploy_factory(gas: int = GAS_LIMIT, **credentials) -> str:
txn_info = {"gas_payer": gas_payer, "gas_payer_priv": gas_payer_priv, "gas": gas}
txn_receipt = handle_transaction(txn_func, *func_args, **txn_info)
contract_addr = txn_receipt["contractAddress"]
return contract_addr
return str(contract_addr)


def get_pub_key_from_addr(wallet_addr: str) -> bytes:
Expand Down Expand Up @@ -274,7 +282,7 @@ def get_pub_key_from_addr(wallet_addr: str) -> bytes:
return bytes(addr_pub_key, encoding="utf-8")


def set_pub_key_at_addr(pub_key: str) -> Dict[str, Any]:
def set_pub_key_at_addr(pub_key: str) -> TxReceipt:
"""
Given a public key, this function will use the eth-kvstore to reach out to the blockchain
and set the key `hmt_pub_key` on the callers kvstore collection of values, equivalent to the
Expand Down
27 changes: 15 additions & 12 deletions hmt_escrow/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from web3 import Web3
from web3.contract import Contract
from web3.types import Wei
from eth_keys import keys
from eth_utils import decode_hex

Expand Down Expand Up @@ -61,7 +62,7 @@ def status(escrow_contract: Contract, gas_payer: str, gas: int = GAS_LIMIT) -> E
"""
status_ = escrow_contract.functions.getStatus().call(
{"from": gas_payer, "gas": gas}
{"from": gas_payer, "gas": Wei(gas)}
)
return Status(status_ + 1)

Expand Down Expand Up @@ -95,7 +96,7 @@ def manifest_url(
"""
return escrow_contract.functions.getManifestUrl().call(
{"from": gas_payer, "gas": gas}
{"from": gas_payer, "gas": Wei(gas)}
)


Expand Down Expand Up @@ -128,15 +129,15 @@ def manifest_hash(
"""
return escrow_contract.functions.getManifestHash().call(
{"from": gas_payer, "gas": gas}
{"from": gas_payer, "gas": Wei(gas)}
)


def is_trusted_handler(
escrow_contract: Contract, handler_addr: str, gas_payer: str, gas: int = GAS_LIMIT
) -> bool:
return escrow_contract.functions.isTrustedHandler(handler_addr).call(
{"from": gas_payer, "gas": gas}
{"from": gas_payer, "gas": Wei(gas)}
)


Expand All @@ -152,7 +153,9 @@ def launcher(escrow_contract: Contract, gas_payer: str, gas: int = GAS_LIMIT) ->
str: returns the address of who launched the job.
"""
return escrow_contract.functions.getLauncher().call({"from": gas_payer, "gas": gas})
return escrow_contract.functions.getLauncher().call(
{"from": gas_payer, "gas": Wei(gas)}
)


class Job:
Expand Down Expand Up @@ -996,7 +999,7 @@ def balance(self, gas: int = GAS_LIMIT) -> int:
"""
return self.job_contract.functions.getBalance().call(
{"from": self.gas_payer, "gas": gas}
{"from": self.gas_payer, "gas": Wei(gas)}
)

def manifest(self, priv_key: bytes) -> Dict:
Expand Down Expand Up @@ -1094,7 +1097,7 @@ def final_results(self, priv_key: bytes, gas: int = GAS_LIMIT) -> Dict:
"""
final_results_url = self.job_contract.functions.getFinalResultsUrl().call(
{"from": self.gas_payer, "gas": gas}
{"from": self.gas_payer, "gas": Wei(gas)}
)
return download(final_results_url, priv_key)

Expand Down Expand Up @@ -1256,7 +1259,7 @@ def _factory_contains_escrow(
"""
factory_contract = get_factory(factory_addr)
return factory_contract.functions.hasEscrow(escrow_addr).call(
{"from": self.gas_payer, "gas": gas}
{"from": self.gas_payer, "gas": Wei(gas)}
)

def _init_factory(
Expand All @@ -1276,7 +1279,7 @@ def _init_factory(
... }
>>> job = Job(credentials, manifest)
>>> type(job.factory_contract)
<class 'web3.utils.datatypes.Contract'>
<class 'web3._utils.datatypes.Contract'>
Initializing a new Job instance with a factory address succeeds.
>>> factory_addr = deploy_factory(**credentials)
Expand All @@ -1303,7 +1306,7 @@ def _init_factory(
raise Exception("Unable to get address from factory")

if not factory:
factory = get_factory(factory_addr)
factory = get_factory(str(factory_addr))
return factory

def _bulk_paid(self, gas: int = GAS_LIMIT) -> int:
Expand Down Expand Up @@ -1340,7 +1343,7 @@ def _bulk_paid(self, gas: int = GAS_LIMIT) -> int:
"""
return self.job_contract.functions.getBulkPaid().call(
{"from": self.gas_payer, "gas": gas}
{"from": self.gas_payer, "gas": Wei(gas)}
)

def _last_escrow_addr(self, gas: int = GAS_LIMIT) -> str:
Expand All @@ -1367,7 +1370,7 @@ def _last_escrow_addr(self, gas: int = GAS_LIMIT) -> str:
"""
return self.factory_contract.functions.getLastEscrow().call(
{"from": self.gas_payer, "gas": gas}
{"from": self.gas_payer, "gas": Wei(gas)}
)

def _create_escrow(self, trusted_handlers=[], gas: int = GAS_LIMIT) -> bool:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"lint:js": "eslint test/** migrations/**",
"lint": "npm run lint:js",
"publish": "truffle publish",
"test": "truffle test",
"test": "npx truffle test",
"coverage": "./node_modules/.bin/solidity-coverage"
},
"repository": {
Expand Down
6 changes: 0 additions & 6 deletions requirements.txt

This file was deleted.

4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setuptools.setup(
name="hmt-escrow",
version="0.8.2",
version="0.8.3",
author="HUMAN Protocol",
description="A python library to launch escrow contracts to the HUMAN network.",
url="https://github.com/hCaptcha/hmt-escrow",
Expand All @@ -14,5 +14,5 @@
"Programming Language :: Python",
],
packages=setuptools.find_packages() + ["contracts", "migrations"],
install_requires=["py-solc-x", "web3", "hmt-basemodels", "boto3"],
install_requires=["py-solc-x", "trinity", "hmt-basemodels", "boto3", "sphinx"],
)

0 comments on commit 529f294

Please sign in to comment.