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: opcodes and opcodes_runtime outputs #3735

Merged
merged 2 commits into from
Jan 18, 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
15 changes: 15 additions & 0 deletions tests/unit/compiler/test_opcodes.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest

import vyper
from vyper.compiler.output import _build_opcodes
from vyper.evm import opcodes
from vyper.exceptions import CompilerPanic

Expand Down Expand Up @@ -64,3 +65,17 @@ def test_get_opcodes(evm_version):
else:
for op in ("TLOAD", "TSTORE", "MCOPY"):
assert op not in ops


def test_build_opcodes():
assert _build_opcodes(bytes.fromhex("610250")) == "PUSH2 0x0250"
assert _build_opcodes(bytes.fromhex("612500")) == "PUSH2 0x2500"
assert _build_opcodes(bytes.fromhex("610100")) == "PUSH2 0x0100"
charles-cooper marked this conversation as resolved.
Show resolved Hide resolved
assert _build_opcodes(bytes.fromhex("611000")) == "PUSH2 0x1000"
assert _build_opcodes(bytes.fromhex("62010300")) == "PUSH3 0x010300"
assert (
_build_opcodes(
bytes.fromhex("7f6100000000000000000000000000000000000000000000000000000000000000")
)
== "PUSH32 0x6100000000000000000000000000000000000000000000000000000000000000"
)
4 changes: 2 additions & 2 deletions vyper/compiler/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ def _build_opcodes(bytecode: bytes) -> str:
# (instead of code) at end of contract
# CMC 2023-07-13 maybe just strip known data segments?
push_len = min(push_len, len(bytecode_sequence))
push_values = [hex(bytecode_sequence.popleft())[2:] for i in range(push_len)]
opcode_output.append(f"0x{''.join(push_values).upper()}")
push_values = [f"{bytecode_sequence.popleft():0>2X}" for i in range(push_len)]
opcode_output.append(f"0x{''.join(push_values)}")

return " ".join(opcode_output)
Loading