-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Permitted bytes addresses in web3 #893
Conversation
a20ddf2
to
9d49eee
Compare
@pipermerriam @carver I have added some tests to check that my code is functionally complete. For the ease of reviewing I have separated the code change from the tests by splitting them into two separate commits. Also, I had some trouble with
I was getting this error with geth:
In such cases I left the tests as is. PS: I'll update docs once I get some feedback on this! |
0aad54c
to
efddf0e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approach looks good 👍
|
||
|
||
@pytest.fixture(params=['hex', 'bytes']) | ||
def math_addr(request, math_deploy_receipt): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, the approach of parametrizing the address seems totally reasonable 👍
def math_addr(request, math_deploy_receipt): | ||
addr = math_deploy_receipt['contractAddress'] | ||
if request.param == 'bytes': | ||
return to_bytes(hexstr=addr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I considered recommending eth_utils.to_canonical_address(addr)
here, but I find it hard to remember that canonical means the bytes
version (to me the semantically "canonical" version of the address is the checksum version).
So I actually like to_bytes
for clarity here.
@pytest.fixture(scope="module", params=['bytes', 'hex']) | ||
def math_contract_address(math_contract, request): | ||
if request.param == 'bytes': | ||
return math_contract.address |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
conversion missing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, Nice catch!!!
|
||
|
||
@pytest.fixture | ||
def unlocked_account_dual_type(web3, unlockable_account_dual_type, unlockable_account_pw): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I liked the other approach in this PR: replace the existing fixture with a parametrized one, as opposed to leaving the old one and adding a new one with a different name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to do this because some tests were failing with the parametrized approach. Its the same issue that I've mentioned in #893 (comment).
web3/utils/rpc_abi.py
Outdated
@@ -24,6 +24,7 @@ | |||
|
|||
FILTER_PARAMS_ABIS = { | |||
'to': 'address', | |||
'address': 'address' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick add trailing comma
web3/utils/rpc_abi.py
Outdated
@@ -47,6 +48,9 @@ | |||
'eth_sign': ['address', 'bytes'], | |||
# personal | |||
'personal_sendTransaction': TRANSACTION_PARAMS_ABIS, | |||
'personal_lockAccount': ['address'], | |||
'personal_unlockAccount': ['address', None, None], | |||
'personal_sign': [None, 'address', None] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick add trailing comma
That doesn't sound right. Something else must be going on. Can you leave in an example of a broken test with
Right, I think the integration tests don't reset state in between tests.
That should be fine, although it should be possible to parametrize non-state-changing tests with both kinds of addresses, like a |
Thanks @carver for the review!
Quite possible that something else is going wrong. I did not spend any time digging it. But simply using paramaterized Besides do you have any ideas what tests I might be missing? Or any other tests that you would like to see added. Although this code won't break anything, I want to make sure that I've covered most cases where binary addresses will be used. |
Maybe search through this API list for Maybe I missed it, but tests for addresses being passed in as arguments to contract function calls. Checking that Also, the Filters: contract address, or indexed address arguments. |
efddf0e
to
920bc41
Compare
@carver I tried to figure out what was going wrong with test_eth_sendTransaction_with_nonce. This time I tested with parity. Like I said before
As you can see Also, I got the test passing by doing the following: count = 0
def _counter():
global count
while True:
yield count
count += 1
counter = _counter()
class EthModuleTest:
def test_eth_sendTransaction_with_nonce(self, web3, unlockable_account_dual_type):
txn_params = {
...
'nonce': web3.eth.getTransactionCount(unlockable_account_dual_type) + next(counter),
} which clearly shows that the |
Yeah, that sounds right to me. I don't think we're using the |
ec15217
to
d6d4fe2
Compare
tests/core/contracts/conftest.py
Outdated
@@ -15,6 +20,11 @@ | |||
CONTRACT_ABI = json.loads('[{"constant":false,"inputs":[],"name":"return13","outputs":[{"name":"result","type":"int256"}],"type":"function"},{"constant":true,"inputs":[],"name":"counter","outputs":[{"name":"","type":"uint256"}],"type":"function"},{"constant":false,"inputs":[{"name":"amt","type":"uint256"}],"name":"increment","outputs":[{"name":"result","type":"uint256"}],"type":"function"},{"constant":false,"inputs":[{"name":"a","type":"int256"},{"name":"b","type":"int256"}],"name":"add","outputs":[{"name":"result","type":"int256"}],"type":"function"},{"constant":false,"inputs":[],"name":"increment","outputs":[{"name":"","type":"uint256"}],"type":"function"},{"constant":false,"inputs":[{"name":"a","type":"int256"}],"name":"multiply7","outputs":[{"name":"result","type":"int256"}],"type":"function"},{"anonymous":false,"inputs":[{"indexed":false,"name":"value","type":"uint256"}],"name":"Increased","type":"event"}]') # noqa: E501 | |||
|
|||
|
|||
@pytest.fixture(params=[lambda x: to_bytes(hexstr=x), identity]) | |||
def address_conversion_func(request): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, this approach seems like a clean way to test the different accepted address formats. 👍
Instead of repeating it in several conftests, it seems like a reasonable thing to put it in the root tests/conftest.py
.
@carver Ready for review! |
90960d3
to
4d46cf5
Compare
added trailing commas
added missing conversion
changed fixture scope to module
5badde8
to
43fac7f
Compare
Thanks, @carver and @pipermerriam. |
This isn't necessary since ethereum/web3.py#893
This isn't necessary since ethereum/web3.py#893
What was wrong?
Web3 did not permit bytes addresses.
see #884
How was it fixed?
Permitted bytes addresses in web3.
TODO LIST
Add tests
update docs
Cute Animal Picture