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

test: tests for functionality fixed in #2471 #2568

Merged
merged 19 commits into from
Jan 1, 2022
Merged
Changes from 2 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,266 @@ def get_array(arg1: address) -> (Bytes[30], int128, Bytes[3]):
assert_tx_failed(lambda: c2.get_array(c.address))


@pytest.mark.parametrize("length", [8, 256])
def test_external_contract_calls_with_uint8(get_contract, length, memory_mocker):
contract_1 = f"""
@external
def foo() -> uint{length}:
return 255
"""

c = get_contract(contract_1)

contract_2 = """
interface Foo:
def foo() -> uint8: view

@external
def bar(arg1: address) -> uint8:
return Foo(arg1).foo()
"""

c2 = get_contract(contract_2)
assert c2.bar(c.address) == 255


def test_uint8_too_long(get_contract, assert_tx_failed, memory_mocker):
contract_1 = """
@external
def foo() -> uint256:
return 2**255
"""

c = get_contract(contract_1)

contract_2 = """
interface Foo:
def foo() -> uint8: view

@external
def bar(arg1: address) -> uint8:
return Foo(arg1).foo()
"""

c2 = get_contract(contract_2)
assert_tx_failed(lambda: c2.bar(c.address))


@pytest.mark.parametrize("a,b", [(8, 8), (8, 256), (256, 8), (256, 256)])
@pytest.mark.parametrize("actual", [8, 256])
def test_tuple_with_uint8(get_contract, assert_tx_failed, a, b, actual, memory_mocker):
contract_1 = f"""
@external
def foo() -> (uint{actual}, Bytes[3], uint{actual}):
return 255, b'dog', 255
"""

c = get_contract(contract_1)

contract_2 = f"""
interface Foo:
def foo() -> (uint{a}, Bytes[3], uint{b}): view

@external
def bar(arg1: address) -> (uint{a}, Bytes[3], uint{b}):
a: uint{a} = 0
b: Bytes[3] = b""
c: uint{b} = 0
a, b, c = Foo(arg1).foo()
return a, b, c
"""

c2 = get_contract(contract_2)
assert c.foo() == [255, b"dog", 255]
assert c2.bar(c.address) == [255, b"dog", 255]


@pytest.mark.parametrize("a,b", [(8, 256), (256, 8), (256, 256)])
def test_tuple_with_uint8_too_long(get_contract, assert_tx_failed, a, b, memory_mocker):
contract_1 = f"""
@external
def foo() -> (uint{a}, Bytes[3], uint{b}):
return {(2**a)-1}, b'dog', {(2**b)-1}
"""

c = get_contract(contract_1)

contract_2 = f"""
interface Foo:
def foo() -> (uint8, Bytes[3], uint8): view

@external
def bar(arg1: address) -> (uint8, Bytes[3], uint8):
a: uint8 = 0
b: Bytes[3] = b""
c: uint8 = 0
a, b, c = Foo(arg1).foo()
return a, b, c
"""

c2 = get_contract(contract_2)
assert c.foo() == [int(f'{(2**a)-1}'), b"dog", int(f'{(2**b)-1}')]
assert_tx_failed(lambda: c2.bar(c.address))


@pytest.mark.parametrize("a,b", [(8, 256), (256, 8)])
def test_tuple_with_uint8_too_long_two(get_contract, assert_tx_failed, a, b, memory_mocker):
contract_1 = f"""
@external
def foo() -> (uint{b}, Bytes[3], uint{a}):
return {(2**b)-1}, b'dog', {(2**a)-1}
"""

c = get_contract(contract_1)

contract_2 = f"""
interface Foo:
def foo() -> (uint{a}, Bytes[3], uint{b}): view

@external
def bar(arg1: address) -> (uint{a}, Bytes[3], uint{b}):
a: uint{a} = 0
b: Bytes[3] = b""
c: uint{b} = 0
a, b, c = Foo(arg1).foo()
return a, b, c
"""

c2 = get_contract(contract_2)
assert c.foo() == [int(f'{(2**b)-1}'), b"dog", int(f'{(2**a)-1}')]
assert_tx_failed(lambda: c2.bar(c.address))


@pytest.mark.parametrize("length", [128, 256])
def test_external_contract_calls_with_int128(get_contract, length, memory_mocker):
contract_1 = f"""
@external
def foo() -> int{length}:
return 1
"""

c = get_contract(contract_1)

contract_2 = """
interface Foo:
def foo() -> int128: view

@external
def bar(arg1: address) -> int128:
return Foo(arg1).foo()
"""

c2 = get_contract(contract_2)
assert c2.bar(c.address) == 1


def test_int128_too_long(get_contract, assert_tx_failed, memory_mocker):
contract_1 = """
@external
def foo() -> int256:
return (2**255)-1
"""

c = get_contract(contract_1)

contract_2 = """
interface Foo:
def foo() -> int128: view

@external
def bar(arg1: address) -> int128:
return Foo(arg1).foo()
"""

c2 = get_contract(contract_2)
assert_tx_failed(lambda: c2.bar(c.address))


@pytest.mark.parametrize("a,b", [(128, 128), (128, 256), (256, 128), (256, 256)])
@pytest.mark.parametrize("actual", [128, 256])
def test_tuple_with_int128(get_contract, assert_tx_failed, a, b, actual, memory_mocker):
contract_1 = f"""
@external
def foo() -> (int{actual}, Bytes[3], int{actual}):
return 255, b'dog', 255
"""

c = get_contract(contract_1)

contract_2 = f"""
interface Foo:
def foo() -> (int{a}, Bytes[3], int{b}): view

@external
def bar(arg1: address) -> (int{a}, Bytes[3], int{b}):
a: int{a} = 0
b: Bytes[3] = b""
c: int{b} = 0
a, b, c = Foo(arg1).foo()
return a, b, c
"""

c2 = get_contract(contract_2)
assert c.foo() == [255, b"dog", 255]
assert c2.bar(c.address) == [255, b"dog", 255]


@pytest.mark.parametrize("a,b", [(128, 256), (256, 128), (256, 256)])
def test_tuple_with_int128_too_long(get_contract, assert_tx_failed, a, b, memory_mocker):
contract_1 = f"""
@external
def foo() -> (int{a}, Bytes[3], int{b}):
return {(2**(a-1))-1}, b'dog', {(2**(b-1))-1}
"""

c = get_contract(contract_1)

contract_2 = f"""
interface Foo:
def foo() -> (int128, Bytes[3], int128): view

@external
def bar(arg1: address) -> (int128, Bytes[3], int128):
a: int128 = 0
b: Bytes[3] = b""
c: int128 = 0
a, b, c = Foo(arg1).foo()
return a, b, c
"""

c2 = get_contract(contract_2)
assert c.foo() == [int(f'{(2**(a-1))-1}'), b"dog", int(f'{(2**(b-1))-1}')]
assert_tx_failed(lambda: c2.bar(c.address))


@pytest.mark.parametrize("a,b", [(128, 256), (256, 128)])
def test_tuple_with_int128_too_long_two(get_contract, assert_tx_failed, a, b, memory_mocker):
contract_1 = f"""
@external
def foo() -> (int{b}, Bytes[3], int{a}):
return {(2**(b-1))-1}, b'dog', {(2**(a-1))-1}
"""

c = get_contract(contract_1)

contract_2 = f"""
interface Foo:
def foo() -> (int{a}, Bytes[3], int{b}): view

@external
def bar(arg1: address) -> (int{a}, Bytes[3], int{b}):
a: int{a} = 0
b: Bytes[3] = b""
c: int{b} = 0
a, b, c = Foo(arg1).foo()
return a, b, c
"""

c2 = get_contract(contract_2)
assert c.foo() == [int(f'{(2**(b-1))-1}'), b"dog", int(f'{(2**(a-1))-1}')]
assert_tx_failed(lambda: c2.bar(c.address))


def test_external_contract_call_state_change(get_contract, memory_mocker):
contract_1 = """
lucky: public(int128)
Expand Down