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

Fix support for callable coders #76

Merged
merged 2 commits into from
Jun 5, 2018
Merged

Conversation

davesque
Copy link
Contributor

@davesque davesque commented Jun 5, 2018

What was wrong?

When adding support for tuple types and the is_encodable function, support for simple callable coders was broken.

How was it fixed?

Modified code in is_encodable as well as encoding and decoding modules to handle simple callables. Added tests for functionality that wasn't working as expected.

Cute Animal Picture

Cute animal picture

assert encoded_tuple == b'\x00' * 31 + b'\x01' + NULL_ENCODING
assert decode_single('(int,null)', encoded_tuple) == (1, None)

registry.unregister('null')
Copy link
Collaborator

@carver carver Jun 5, 2018

Choose a reason for hiding this comment

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

This unregister being necessary in the test is a hint to me that the API could be improved. The ideal I would look for is the pattern of initializing an object in a fixture, and then not worrying about state from one test polluting another test. That's awkward with this global registry singleton. Something like a make_registry() method that initializes a new registry with all the defaults would enables us to do:

@pytest.fixture
def registry():
    return make_registry()

Then we don't have to worry about unregistering.

Since there are other more pressing issues, maybe just capture the idea into an issue and we can come back to it later. (if you like it)

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 thought about making a fixture but just decided it was an okay hack for the time being. Also, I felt like it would be useful to test the functionality by calling encode_single and decode_single to make it more like an integration test instead of querying the registry directly and using the result of that. I'll make an issue for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Issue created: #77

Copy link
Member

Choose a reason for hiding this comment

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

This should be wrapped in a try/finally, otherwise it's going to leave the registry polluted when this test fails.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

PR created for this: #79

@davesque davesque merged commit cb50c08 into ethereum:master Jun 5, 2018
@davesque davesque deleted the callable-fixes branch June 5, 2018 20:51
@@ -144,4 +144,4 @@ def from_type_str(cls, type_str, registry): # pragma: no cover
Used by ``ABIRegistry`` to get an appropriate encoder or decoder
instance for the given type string and type registry.
"""
raise NotImplementedError('Must implement `from_type_str`')
raise cls()
Copy link
Member

Choose a reason for hiding this comment

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

This line is confusing to me.

Copy link
Contributor Author

@davesque davesque Jun 5, 2018

Choose a reason for hiding this comment

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

Thank you for catching that. I intended for that to be return cls() and I believe my thinking was that it would make some of the examples in the registry documentation more simple but then I just went with slightly more complex examples. I'll make a PR to revert it right away.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

PR created for this: #78

assert encoded_tuple == b'\x00' * 31 + b'\x01' + NULL_ENCODING
assert decode_single('(int,null)', encoded_tuple) == (1, None)

registry.unregister('null')
Copy link
Member

Choose a reason for hiding this comment

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

This should be wrapped in a try/finally, otherwise it's going to leave the registry polluted when this test fails.

davesque added a commit to davesque/eth-abi that referenced this pull request Jun 5, 2018
davesque added a commit that referenced this pull request Jun 6, 2018
pacrob added a commit to pacrob/eth-abi that referenced this pull request Apr 14, 2023
* remove gitter, testing setup, and pandoc sections, add quotes to dev install
pacrob added a commit to pacrob/eth-abi that referenced this pull request Dec 9, 2023
* remove gitter, testing setup, and pandoc sections, add quotes to dev install
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