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

Permitted bytes addresses in web3 #893

Merged
merged 14 commits into from
Jul 3, 2018

Conversation

voith
Copy link
Contributor

@voith voith commented Jun 9, 2018

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

@voith
Copy link
Contributor Author

voith commented Jun 11, 2018

@pipermerriam @carver I have added some tests to check that my code is functionally complete.
The integration tests, test some parts of contracts and filters. However, I might need more tests there.
Let me know if I'm missing any tests or if you'd like me to add more tests.
Currently, I have modified the existing tests to accept both binary and hex addresses. I'm not sure if this is the right approach. I wanted to verify that the code works, so to get it done fast I modified the existing tests. If you guys want this tested in a completely separate module then I'm fine with that.

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 nonce. w3.eth.getTransactionCount doesn't seem to increment the count, once a transaction has been sent. I tried using waitForTransactionReceipt but that didn't change anything.

'nonce': web3.eth.getTransactionCount(unlocked_account),

I was getting this error with geth:

ValueError: {'code': -32000, 'message': 'known transaction: 157d2598aa226207eb4711e04511266f0ad50817d6654c0a0835ae2b3dd3fa7e'}

In such cases I left the tests as is.

PS: I'll update docs once I get some feedback on this!

@voith voith force-pushed the permit-binary-addresses branch 2 times, most recently from 0aad54c to efddf0e Compare June 11, 2018 07:40
Copy link
Collaborator

@carver carver left a 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):
Copy link
Collaborator

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)
Copy link
Collaborator

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
Copy link
Collaborator

Choose a reason for hiding this comment

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

conversion missing?

Copy link
Contributor Author

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):
Copy link
Collaborator

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.

Copy link
Contributor Author

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).

@@ -24,6 +24,7 @@

FILTER_PARAMS_ABIS = {
'to': 'address',
'address': 'address'
Copy link
Collaborator

Choose a reason for hiding this comment

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

nitpick add trailing comma

@@ -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]
Copy link
Collaborator

Choose a reason for hiding this comment

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

nitpick add trailing comma

@carver
Copy link
Collaborator

carver commented Jun 11, 2018

w3.eth.getTransactionCount doesn't seem to increment the count, once a transaction has been sent

That doesn't sound right. Something else must be going on. Can you leave in an example of a broken test with getTransactionCount?

I was getting this error with geth

Right, I think the integration tests don't reset state in between tests.

In such cases I left the tests as is.

That should be fine, although it should be possible to parametrize non-state-changing tests with both kinds of addresses, like a getBalance(address) test.

@voith
Copy link
Contributor Author

voith commented Jun 11, 2018

Thanks @carver for the review!

That doesn't sound right. Something else must be going on. Can you leave in an example of a broken test with getTransactionCount?

Quite possible that something else is going wrong. I did not spend any time digging it. But simply using paramaterized unlocked_account caused the test failures for me. I'll try to come up with a test case to replicate the issue tomorrow.

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.

@carver
Copy link
Collaborator

carver commented Jun 11, 2018

Besides do you have any ideas what tests I might be missing? Or any other tests that you would like to see added.

Maybe search through this API list for account? The first one I found that I'm not sure is covered is getStorageAt.

Maybe I missed it, but tests for addresses being passed in as arguments to contract function calls.

Checking that w3.eth.account.signTransaction accepts transactions with from & to addresses in bytes.

Also, the ens module.

Filters: contract address, or indexed address arguments.

@voith voith force-pushed the permit-binary-addresses branch from efddf0e to 920bc41 Compare June 18, 2018 07:11
@voith
Copy link
Contributor Author

voith commented Jun 18, 2018

@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 web3.eth.getTransactionCount(unlockable_account_dual_type) returns the same value every time.
On inspection, web3.eth.waitForTransactionReceipt(txn_hash) returned the following

AttributeDict({'blockHash': None, 'blockNumber': None, 'contractAddress': None, 'cumulativeGasUsed': 21000, 'gasUsed': 21000, 'logs': [], 'logsBloom': HexBytes('0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'), 'root': '0x979928a2ecf81da90713b24af9b83cbc4ad59e7e7096ce86ff62ad1780c1d677', 'status': None, 'transactionHash': HexBytes('0x66a9cc4cf67fadda3d0691756d8c355b9ad77beb71ca1311467b6d8ad580dd01'), 'transactionIndex': 0})

As you can see blockNumber is None in this case. My guess is that the private chain instantiated doesn't mine(Not very sure though). @dylanjw Can you validate this statement?(since you wrote the parity tests).

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 state is not being updated! I'll leave such tests as is and focus on the missing tests to get this PR completed.

@voith
Copy link
Contributor Author

voith commented Jun 18, 2018

Checklist of tests that are needed to call this feature complete. I will update this list as I find more and point to the line number in the diff where the test was added. Hopefully, this will help the reviewer!

@carver
Copy link
Collaborator

carver commented Jun 18, 2018

My guess is that the private chain instantiated doesn't mine

Yeah, that sounds right to me. I don't think we're using the geth --dev equivalent for parity on the integration tests. (Actually, I don't think we're using geth --dev on the geth tests either)

@voith voith force-pushed the permit-binary-addresses branch from ec15217 to d6d4fe2 Compare June 22, 2018 08:54
@@ -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):
Copy link
Collaborator

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.

@voith voith changed the title [WIP]Permitted bytes addresses in web3 Permitted bytes addresses in web3 Jun 24, 2018
@voith
Copy link
Contributor Author

voith commented Jun 24, 2018

@carver Ready for review!

@carver carver force-pushed the permit-binary-addresses branch from 5badde8 to 43fac7f Compare June 29, 2018 18:25
@pipermerriam pipermerriam merged commit 9800597 into ethereum:master Jul 3, 2018
@voith voith deleted the permit-binary-addresses branch July 4, 2018 02:00
@voith
Copy link
Contributor Author

voith commented Jul 4, 2018

Thanks, @carver and @pipermerriam.

palango added a commit to raiden-network/raiden that referenced this pull request Jan 20, 2020
hackaugusto pushed a commit to raiden-network/raiden that referenced this pull request May 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants