Skip to content

Commit

Permalink
compare bytecode directly
Browse files Browse the repository at this point in the history
  • Loading branch information
charles-cooper committed Aug 31, 2023
1 parent 43813c8 commit cab2ef8
Showing 1 changed file with 18 additions and 25 deletions.
43 changes: 18 additions & 25 deletions tests/parser/functions/test_raw_call.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest
from hexbytes import HexBytes

from vyper import compile_code
from vyper.builtins.functions import eip1167_bytecode
from vyper.exceptions import ArgumentException, InvalidType, StateAccessViolation

Expand Down Expand Up @@ -261,36 +262,28 @@ def __default__():


# check max_outsize=0 does same thing as not setting max_outsize
# compile to bytecode and compare bytecode directly.
def test_max_outsize_0(get_contract):
mock1_code = """
code1 = """
@external
def foo():
return
"""
mock2_code = """
@external
def foo():
raise
def test_raw_call(_target: address) -> bool:
# compile raw_call both ways, with revert_on_failure
a: bool = raw_call(_target, method_id("foo()"), revert_on_failure=False)
# and without revert_on_failure
raw_call(_target, method_id("foo()"))
return a
"""
code = """
# write same code, but with max_outsize=0
code2 = """
@external
def test_raw_call(_target: address) -> (bool, bool):
# compiles
a: bool = raw_call(_target, method_id("foo()"), revert_on_failure=False)
# should have same behavior
b: bool = raw_call(_target, method_id("foo()"), max_outsize=0, revert_on_failure=False)
return a, b
def test_raw_call(_target: address) -> bool:
a: bool = raw_call(_target, method_id("foo()"), max_outsize=0, revert_on_failure=False)
raw_call(_target, method_id("foo()"), max_outsize=0)
return a
"""

c = get_contract(code)

mock1 = get_contract(mock1_code)
a, b = c.test_raw_call(mock1.address)
assert a == b and a is True

mock2 = get_contract(mock2_code)
a, b = c.test_raw_call(mock2.address)
assert a == b and a is False
output1 = compile_code(code1, ["bytecode", "bytecode_runtime"])
output2 = compile_code(code2, ["bytecode", "bytecode_runtime"])
assert output1 == output2


def test_static_call_fails_nonpayable(get_contract, assert_tx_failed):
Expand Down

0 comments on commit cab2ef8

Please sign in to comment.