Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Eth to method #1568

Closed
wants to merge 39 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
d9e1f78
Easy methods changed
kclowes Jan 16, 2020
69ed097
Eth call
kclowes Jan 16, 2020
10a7f27
Functions that encapsulate multiple methods
kclowes Jan 17, 2020
8ed6c42
Added error handling, still a few tests failing
kclowes Jan 17, 2020
99e8a32
Change attrdict_formatter order
kclowes Jan 20, 2020
6772306
Fix getLogs test
kclowes Jan 20, 2020
6349127
Fix eth tester tests
kclowes Jan 22, 2020
58e7bde
Fix eth_call return value
kclowes Jan 22, 2020
eab80a6
Use existing FILTER_PARAM_NORMALIZERS instead of a custom munger
kclowes Jan 22, 2020
f2a4117
Fix param normalization and name middleware tests
kclowes Jan 24, 2020
da8c2e6
Fix getBlock integration tests
kclowes Jan 27, 2020
3ee9243
Update comment to be accurate
kclowes Jan 29, 2020
cc4dae5
WIP - rough version of null_result_formatters working
kclowes Jan 29, 2020
16b7605
Fix local_filter_middleware and time_based_gas_price_strategy tests
kclowes Jan 30, 2020
45fe059
Fix other middleware tests
kclowes Jan 30, 2020
fca70de
Fix integration tests again
kclowes Jan 30, 2020
f47407a
Move abi_hex_to_address to middleware
kclowes Jan 30, 2020
b5174e4
Put back flaky xfails in parity shh integration tests
kclowes Jan 30, 2020
e4ed3da
Fix middleware and contract buildTransaction tests
kclowes Jan 30, 2020
f2f0126
WIP - domain validation
kclowes Jan 31, 2020
1c05254
Fix some more tests
kclowes Jan 31, 2020
0e62a64
isort, comment cleanup
kclowes Jan 31, 2020
e652a01
Fix lint errors aside from types
kclowes Feb 3, 2020
a53628d
Beginning of types
kclowes Feb 5, 2020
b482ee3
More types
kclowes Feb 7, 2020
6888d2c
Update getTransactionReceipt's return type
kclowes Feb 10, 2020
f522aa7
More types
kclowes Feb 11, 2020
334bb7e
Lint
kclowes Feb 13, 2020
794c516
Fix protocolVersion bug
kclowes Mar 12, 2020
2fcb957
Change apply_null_result_formatters method name
kclowes Mar 12, 2020
accbc22
Use RPC.<method name> in null result formatters
kclowes Mar 13, 2020
477d97c
WIP - protocolVersion
kclowes Mar 13, 2020
fb9e140
Fix rebase
kclowes Aug 26, 2020
78e2911
Fix protocolVersion bug
kclowes Aug 26, 2020
3ee4786
Some lint fixes
kclowes Aug 26, 2020
55c8b22
More lint
kclowes Aug 26, 2020
c0994bf
Improve on address validation
kclowes Aug 27, 2020
fa068d6
Clarify formatter comment
kclowes Aug 27, 2020
08e5e5f
lint
kclowes Aug 27, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions ens/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,15 @@ def assert_signer_in_modifier_kwargs(modifier_kwargs: Any) -> ChecksumAddress:

def is_none_or_zero_address(addr: Union[Address, ChecksumAddress, HexAddress]) -> bool:
return not addr or addr == EMPTY_ADDR_HEX


# Check everything short of validating that a name
# resolves to an address
def is_valid_domain(domain: str) -> bool:
split_domain = domain.split('.')
if len(split_domain) == 1:
return False
for name in split_domain:
if not is_valid_name(name):
return False
return True
8 changes: 4 additions & 4 deletions ethpm/_utils/deployments.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
Tuple,
)

from eth_typing import (
HexStr,
)
from eth_utils import (
is_same_address,
to_bytes,
Expand All @@ -14,9 +17,6 @@
from eth_utils.toolz import (
get_in,
)
from hexbytes import (
HexBytes,
)

from ethpm.exceptions import (
BytecodeLinkingError,
Expand Down Expand Up @@ -47,7 +47,7 @@ def get_linked_deployments(deployments: Dict[str, Any]) -> Dict[str, Any]:


def validate_linked_references(
link_deps: Tuple[Tuple[int, bytes], ...], bytecode: HexBytes
link_deps: Tuple[Tuple[int, bytes], ...], bytecode: HexStr
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@njgheorghita I am not sure why I had to make this change to appease the linter, but do you see any problems with it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I can't tell either off the top of my head, but this change doesn't seem problematic to me. 👍

) -> None:
"""
Validates that normalized linked_references (offset, expected_bytes)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"eth-account>=0.5.2,<0.6.0",
"eth-hash[pycryptodome]>=0.2.0,<1.0.0",
"eth-typing>=2.0.0,<3.0.0",
"eth-utils>=1.9.3,<2.0.0",
"eth-utils==1.9.3",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will cause problems elsewhere if it remains. For example Trinity, installs Web3.py and I know that trinity requires a later version of eth-utils

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a bummer. eth-utils 1.9.4 breaks web3's linting so will probably have to update that before this can be shipped

"hexbytes>=0.1.0,<1.0.0",
"ipfshttpclient>=0.4.13,<1",
"jsonschema>=3.2.0,<4.0.0",
Expand Down
2 changes: 1 addition & 1 deletion tests/core/eth-module/test_eth_properties.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
def test_eth_protocolVersion(web3):
assert web3.eth.protocolVersion == '63'
assert web3.eth.protocolVersion == '65'


def test_eth_chainId(web3):
Expand Down
18 changes: 12 additions & 6 deletions tests/core/gas-strategies/test_time_based_gas_price_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def _get_block_by_something(method, params):
if (
block_identifier == 'latest' or
block_identifier == '0x0000000000000000000000000000000000000000000000000000000000000005' or
block_identifier == '0x5' or
block_identifier == 5
):
return {
Expand All @@ -35,11 +36,12 @@ def _get_block_by_something(method, params):
{'gasPrice': 5},
{'gasPrice': 50},
],
'miner': '0xA',
'miner': '0x' + 'AA' * 20,
'timestamp': 120,
}
elif (
block_identifier == '0x0000000000000000000000000000000000000000000000000000000000000004' or
block_identifier == '0x4' or
block_identifier == 4
):
return {
Expand All @@ -51,11 +53,12 @@ def _get_block_by_something(method, params):
{'gasPrice': 80},
{'gasPrice': 60},
],
'miner': '0xB',
'miner': '0x' + 'BB' * 20,
'timestamp': 90,
}
elif (
block_identifier == '0x0000000000000000000000000000000000000000000000000000000000000003' or
block_identifier == '0x3' or
block_identifier == 3
):
return {
Expand All @@ -65,11 +68,12 @@ def _get_block_by_something(method, params):
'transactions': [
{'gasPrice': 100},
],
'miner': '0xC',
'miner': '0x' + 'CC' * 20,
'timestamp': 60,
}
elif (
block_identifier == '0x0000000000000000000000000000000000000000000000000000000000000002' or
block_identifier == '0x2' or
block_identifier == 2
):
return {
Expand All @@ -78,11 +82,12 @@ def _get_block_by_something(method, params):
'parentHash': '0x0000000000000000000000000000000000000000000000000000000000000001',
'transactions': [
],
'miner': '0xB',
'miner': '0x' + 'BB' * 20,
'timestamp': 30,
}
elif (
block_identifier == '0x0000000000000000000000000000000000000000000000000000000000000001' or
block_identifier == '0x1' or
block_identifier == 1
):
return {
Expand All @@ -94,11 +99,12 @@ def _get_block_by_something(method, params):
{'gasPrice': 35},
{'gasPrice': 65},
],
'miner': '0xA',
'miner': '0x' + 'AA' * 20,
'timestamp': 15,
}
elif (
block_identifier == '0x0000000000000000000000000000000000000000000000000000000000000000' or
block_identifier == '0x0' or
block_identifier == 0
):
return {
Expand All @@ -119,7 +125,7 @@ def _get_block_by_something(method, params):
{'gasPrice': 54},
{'gasPrice': 10000000000000000000000},
],
'miner': '0xA',
'miner': '0x' + 'AA' * 20,
'timestamp': 0,
}
else:
Expand Down
21 changes: 16 additions & 5 deletions tests/core/middleware/test_filter_middleware.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import pytest

from hexbytes import (
HexBytes,
)

from web3 import Web3
from web3.datastructures import (
AttributeDict,
)
from web3.middleware import (
construct_result_generator_middleware,
local_filter_middleware,
Expand Down Expand Up @@ -35,11 +42,15 @@ def iterator():
return block_number


BLOCK_HASH = '0xfe88c94d860f01a17f961bf4bdfb6e0c6cd10d3fda5cc861e805ca1240c58553'
FILTER_LOG = [AttributeDict({'address': '0xDc3A9Db694BCdd55EBaE4A89B22aC6D12b3F0c24', 'blockHash': HexBytes('0xb72256286ca528e09022ffd408856a73ef90e7216ac560187c6e43b4c4efd2f0'), 'blockNumber': 2217196, 'data': '0x0000000000000000000000000000000000000000000000000000000000000001', 'logIndex': 0, 'topics': [HexBytes('0xe65b00b698ba37c614af350761c735c5f4a82b4ab365a1f1022d49d9dfc8e930'), HexBytes('0x000000000000000000000000754c50465885f1ed1fa1a55b95ee8ecf3f1f4324'), HexBytes('0x296c7fb6ccafa3e689950b947c2895b07357c95b066d5cdccd58c301f41359a3')], 'transactionHash': HexBytes('0xfe1289fd3915794b99702202f65eea2e424b2f083a12749d29b4dd51f6dce40d'), 'transactionIndex': 1})] # noqa: E501


@pytest.fixture(scope='function')
def result_generator_middleware(iter_block_number):
return construct_result_generator_middleware({
'eth_getLogs': lambda *_: ["middleware"],
'eth_getBlockByNumber': lambda *_: type('block', (object,), {'hash': 'middleware'}),
'eth_getLogs': lambda *_: FILTER_LOG,
'eth_getBlockByNumber': lambda *_: {'hash': BLOCK_HASH},
'net_version': lambda *_: 1,
'eth_blockNumber': lambda *_: next(iter_block_number),
})
Expand Down Expand Up @@ -141,13 +152,13 @@ def test_local_filter_middleware(w3, iter_block_number):

log_filter = w3.eth.filter(filter_params={'fromBlock': 'latest'})

assert w3.eth.getFilterChanges(block_filter.filter_id) == ["middleware"]
assert w3.eth.getFilterChanges(block_filter.filter_id) == [HexBytes(BLOCK_HASH)]

iter_block_number.send(2)
results = w3.eth.getFilterChanges(log_filter.filter_id)
assert results == ["middleware"]
assert results == FILTER_LOG

assert w3.eth.getFilterLogs(log_filter.filter_id) == ["middleware"]
assert w3.eth.getFilterLogs(log_filter.filter_id) == FILTER_LOG

filter_ids = (
block_filter.filter_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import uuid

from eth_utils import (
is_hex,
is_integer,
to_tuple,
)
Expand All @@ -13,6 +14,9 @@
from web3._utils.caching import (
generate_cache_key,
)
from web3._utils.formatters import (
hex_to_integer,
)
from web3.middleware import ( # noqa: F401
construct_error_generator_middleware,
construct_latest_block_based_cache_middleware,
Expand Down Expand Up @@ -77,7 +81,9 @@ def _get_block_by_number(method, params, block_info=_block_info):
return blocks[head_block_number + 1]
elif block_id == 'earliest':
return blocks[0]
elif is_integer(block_id):
elif is_integer(block_id) or is_hex(block_id):
if is_hex(block_id):
block_id = hex_to_integer(block_id)
if block_id <= head_block_number:
return blocks[block_id]
else:
Expand Down
26 changes: 24 additions & 2 deletions tests/core/middleware/test_request_param_normalizer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import pytest

from hexbytes import (
HexBytes,
)

from web3 import Web3
from web3.datastructures import (
AttributeDict,
)
from web3.middleware import ( # noqa: F401
construct_result_generator_middleware,
request_parameter_normalizer,
Expand All @@ -17,8 +24,23 @@ def w3_base():

@pytest.fixture
def result_generator_middleware():
result = [
AttributeDict({
'address': '0x2F141Ce366a2462f02cEA3D12CF93E4DCa49e4Fd',
'blockHash': HexBytes('0x919e1d4b2e0cae57084bcb9ccf4b46553fee48fe1422f7c58765095cd43d9f2c'), # noqa: E501
'blockNumber': 9346779,
'data': '0x0000000000000000000000000000000000000000000002e820b216795fe09280',
'logIndex': 67,
'removed': False,
'topics': [HexBytes('0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef'), # noqa: E501
HexBytes('0x000000000000000000000000d58b159801499d9b7d56629e4606ae51a1b4fb28'),
HexBytes('0x0000000000000000000000001f84683e962b7dec4a6a3bd382b8adfc554da8a7')],
'transactionHash': HexBytes('0x081a7bfd0943d8b3ba7e15e3d905e60340f0f5559171b4b18d42ee166a27d4a1'), # noqa: E501
'transactionIndex': 62,
})
]
return construct_result_generator_middleware({
'eth_getLogs': lambda _, params: params,
'eth_getLogs': lambda _, params: result
})


Expand All @@ -32,4 +54,4 @@ def w3(w3_base, result_generator_middleware):
def test_eth_getLogs_param_normalization(w3):
result = w3.eth.getLogs({
'from': 'latest', 'address': '0x1111111111111111111111111111111111111111'})
assert isinstance(result[0]['address'], list)
assert isinstance(result[0]['address'], str)
12 changes: 12 additions & 0 deletions tests/ens/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
import pytest

from ens.utils import (
init_web3,
is_valid_domain,
)


def test_init_adds_middlewares():
w3 = init_web3()
middlewares = map(str, w3.manager.middleware_onion)
assert 'stalecheck_middleware' in next(middlewares)


@pytest.mark.parametrize('domain,expected', [
('thedao.eth', True),
('thedao', False),
('blog.ethereum.org', True)
])
def test_is_valid_domain(domain, expected):
actual = is_valid_domain(domain)
assert actual == expected
4 changes: 4 additions & 0 deletions web3/_utils/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
is_text,
remove_0x_prefix,
)
from eth_utils.toolz import (
curry,
)

from web3.types import (
RPCEndpoint,
Expand Down Expand Up @@ -51,6 +54,7 @@ def is_hex_encoded_block_number(value: Any) -> bool:
return 0 <= value_as_int < 2**256


@curry
def select_method_for_block_identifier(
value: Any, if_hash: RPCEndpoint, if_number: RPCEndpoint, if_predefined: RPCEndpoint
) -> RPCEndpoint:
Expand Down
Loading