Skip to content

Commit

Permalink
fix opcodes and opcodes_runtime output
Browse files Browse the repository at this point in the history
  • Loading branch information
trocher committed Jan 18, 2024
1 parent 81c6d8e commit 6540133
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
12 changes: 12 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,14 @@ 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("610100")) == "PUSH2 0x0100"
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)

0 comments on commit 6540133

Please sign in to comment.