Skip to content

Commit

Permalink
Work around wrong annotation in web3
Browse files Browse the repository at this point in the history
  • Loading branch information
palango committed Mar 13, 2020
1 parent ae0c16c commit c4fecda
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 14 deletions.
7 changes: 3 additions & 4 deletions raiden_contracts/deploy/contract_deployer.py
@@ -1,7 +1,7 @@
from copy import deepcopy
from logging import getLogger
from pathlib import Path
from typing import Dict, List, Optional
from typing import Dict, List, Optional, Type

import semver
from eth_typing import ChecksumAddress, HexAddress
Expand Down Expand Up @@ -79,7 +79,6 @@ def deploy(self, contract_name: str, args: Optional[List] = None) -> TxReceipt:
abi=contract_interface["abi"], bytecode=contract_interface["bin"]
)

assert isinstance(contract, Contract)
# Get transaction hash from deployed contract
txhash = self.send_deployment_transaction(contract=contract, args=args)

Expand All @@ -90,7 +89,7 @@ def deploy(self, contract_name: str, args: Optional[List] = None) -> TxReceipt:
)
receipt, tx = check_successful_tx(web3=self.web3, txid=txhash, timeout=self.wait)
if not receipt["contractAddress"]: # happens with Parity
receipt["contractAddress"] = tx["creates"]
receipt["contractAddress"] = tx["creates"] # type: ignore
LOG.info(
"{0} address: {1}. Gas used: {2}".format(
contract_name, receipt["contractAddress"], receipt["gasUsed"]
Expand All @@ -105,7 +104,7 @@ def transact(self, contract_method: ContractFunction) -> TxReceipt:
receipt, _ = check_successful_tx(web3=self.web3, txid=txhash, timeout=self.wait)
return receipt

def send_deployment_transaction(self, contract: Contract, args: List) -> HexBytes:
def send_deployment_transaction(self, contract: Type[Contract], args: List) -> HexBytes:
txhash = None
while txhash is None:
try:
Expand Down
4 changes: 3 additions & 1 deletion raiden_contracts/deploy/contract_verifier.py
Expand Up @@ -197,7 +197,9 @@ def _verify_deployed_contract(
)

# Check that the deployed bytecode matches the precompiled data
blockchain_bytecode = self.web3.eth.getCode(contract_instance.address)
blockchain_bytecode = self.web3.eth.getCode( # type: ignore
contract_instance.address
).hex()
compiled_bytecode = self.contract_manager.get_runtime_hexcode(contract_name)
if blockchain_bytecode == compiled_bytecode:
print(
Expand Down
5 changes: 2 additions & 3 deletions raiden_contracts/tests/test_service_registry.py
Expand Up @@ -2,7 +2,6 @@

import pytest
from eth_tester.exceptions import TransactionFailed
from eth_typing import HexStr
from web3 import Web3
from web3.contract import Contract, get_event_data
from web3.exceptions import MismatchedABI
Expand All @@ -14,7 +13,7 @@
EVENT_REGISTERED_SERVICE,
)
from raiden_contracts.contract_manager import ContractManager, contracts_precompiled_path
from raiden_contracts.tests.utils import call_and_transact
from raiden_contracts.tests.utils import HexBytes, call_and_transact
from raiden_contracts.tests.utils.constants import (
DEFAULT_BUMP_DENOMINATOR,
DEFAULT_BUMP_NUMERATOR,
Expand Down Expand Up @@ -562,7 +561,7 @@ def test_deprecation_immediate_payout(
# The user has all the balance it has minted
assert minted == custom_token.functions.balanceOf(A).call()
# The Deposit contract has destroyed itself
assert web3.eth.getCode(deposit.address) == HexStr("0x")
assert web3.eth.getCode(deposit.address) == HexBytes("0x") # type: ignore


def test_unauthorized_deprecation_switch(
Expand Down
5 changes: 3 additions & 2 deletions raiden_contracts/tests/test_token.py
Expand Up @@ -80,7 +80,7 @@ def test_custom_token(
""" See custom_token.address contains the expected code """
blockchain_bytecode = web3.eth.getCode(custom_token.address)
compiled_bytecode = contracts_manager.get_runtime_hexcode(CONTRACT_CUSTOM_TOKEN)
assert blockchain_bytecode == compiled_bytecode
assert blockchain_bytecode.hex() == compiled_bytecode # type: ignore


def test_human_standard_token(
Expand All @@ -89,4 +89,5 @@ def test_human_standard_token(
""" See human_standard_token.address contains the expected code """
blockchain_bytecode = web3.eth.getCode(human_standard_token.address)
compiled_bytecode = contracts_manager.get_runtime_hexcode(CONTRACT_HUMAN_STANDARD_TOKEN)
assert blockchain_bytecode == compiled_bytecode
breakpoint()
assert blockchain_bytecode.hex() == compiled_bytecode # type: ignore
5 changes: 3 additions & 2 deletions raiden_contracts/utils/mint_tokens.py
Expand Up @@ -3,8 +3,9 @@
from typing import Optional

import click
from eth_typing import URI, ChecksumAddress, HexStr
from eth_typing import URI, ChecksumAddress
from eth_utils import encode_hex
from hexbytes import HexBytes
from web3 import HTTPProvider, Web3
from web3.middleware import construct_sign_and_send_raw_middleware

Expand All @@ -30,7 +31,7 @@ def main(rpc_url: URI, private_key: Path, token_address: ChecksumAddress, amount
owner = private_key_to_address(private_key_string)
web3.middleware_onion.add(construct_sign_and_send_raw_middleware(private_key_string))
token_code = web3.eth.getCode(token_address, "latest")
assert token_code != HexStr("")
assert token_code != HexBytes("") # type: ignore
token_contract = ContractManager(contracts_precompiled_path()).get_contract(
CONTRACT_CUSTOM_TOKEN
)
Expand Down
5 changes: 3 additions & 2 deletions raiden_contracts/utils/token_ops.py
Expand Up @@ -4,8 +4,9 @@

import click
import requests
from eth_typing import URI, ChecksumAddress, HexStr
from eth_typing import URI, ChecksumAddress
from eth_utils import to_checksum_address
from hexbytes import HexBytes
from web3 import HTTPProvider, Web3
from web3.middleware import construct_sign_and_send_raw_middleware, geth_poa_middleware
from web3.types import TxReceipt, Wei
Expand All @@ -31,7 +32,7 @@ def __init__(
self.web3.middleware_onion.inject(geth_poa_middleware, layer=0)

def is_valid_contract(self, token_address: ChecksumAddress) -> bool:
return self.web3.eth.getCode(token_address, "latest") != HexStr("")
return self.web3.eth.getCode(token_address, "latest") != HexBytes("") # type: ignore

def mint_tokens(self, token_address: ChecksumAddress, amount: int) -> TxReceipt:
token_address = to_checksum_address(token_address)
Expand Down

0 comments on commit c4fecda

Please sign in to comment.