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(vm): Bytecode comparison #939

Merged
merged 3 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Test fixtures for use by clients are available for each release on the [Github r
- ✨ Improve `fill` terminal output to emphasize that filling tests is not actually testing a client ([#807](https://github.com/ethereum/execution-spec-tests/pull/887)).
- ✨ Add the `BlockchainTestEngine` test spec type that only generates a fixture in the `EngineFixture` (`blockchain_test_engine`) format ([#888](https://github.com/ethereum/execution-spec-tests/pull/888)).
- πŸ”€ `ethereum_test_forks` forks now contain gas-calculating functions, which return the appropriate function to calculate the gas used by a transaction or memory function for the given fork ([#779](https://github.com/ethereum/execution-spec-tests/pull/779)).
- 🐞 Fix `Bytecode` class `__eq__` method ([#939](https://github.com/ethereum/execution-spec-tests/pull/939)).

### πŸ”§ EVM Tools

Expand Down
10 changes: 9 additions & 1 deletion src/ethereum_test_vm/bytecode.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,17 @@ def __eq__(self, other):
- NotImplementedError: if the comparison is not between an Bytecode
or a bytes object.
"""
if isinstance(other, Bytecode):
return (
bytes(self) == bytes(other)
danceratopz marked this conversation as resolved.
Show resolved Hide resolved
and self.popped_stack_items == other.popped_stack_items
and self.pushed_stack_items == other.pushed_stack_items
and self.max_stack_height == other.max_stack_height
and self.min_stack_height == other.min_stack_height
)
if isinstance(other, SupportsBytes):
return bytes(self) == bytes(other)
raise NotImplementedError(f"Unsupported type for comparison f{type(other)}")
raise NotImplementedError(f"Unsupported type for comparison: {type(other)}")

def __hash__(self):
"""
Expand Down