From 22c89a9987f1809a69dbde7cb6d9eb81429fa59b Mon Sep 17 00:00:00 2001 From: tserg <8017125+tserg@users.noreply.github.com> Date: Wed, 3 Jan 2024 14:23:41 +0800 Subject: [PATCH] add tests --- .../test_default_parameters.py | 35 +++++++++++++++++++ .../codegen/storage_variables/test_getters.py | 5 +++ tests/functional/syntax/test_constants.py | 6 ++++ 3 files changed, 46 insertions(+) diff --git a/tests/functional/codegen/calling_convention/test_default_parameters.py b/tests/functional/codegen/calling_convention/test_default_parameters.py index 462748a9c7..1929b83cce 100644 --- a/tests/functional/codegen/calling_convention/test_default_parameters.py +++ b/tests/functional/codegen/calling_convention/test_default_parameters.py @@ -111,6 +111,41 @@ def fooBar(a: Bytes[100], b: uint256[2], c: Bytes[6] = b"hello", d: int128[3] = assert c.fooBar(b"booo", [55, 66]) == [b"booo", 66, c_default, d_default] +def test_default_param_interface(get_contract): + code = """ +interface Foo: + def bar(): payable + +FOO: constant(Foo) = Foo(0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF) + +@external +def bar(a: uint256, b: Foo = Foo(0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF)) -> Foo: + return b + +@external +def baz(a: uint256, b: Foo = Foo(empty(address))) -> Foo: + return b + +@external +def faz(a: uint256, b: Foo = FOO) -> Foo: + return b + """ + c = get_contract(code) + + assert c.bar(1) == "0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF" + assert ( + c.bar(1, "0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF") + == "0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF" + ) + assert c.baz(1) is None + assert c.baz(1, "0x0000000000000000000000000000000000000000") is None + assert c.faz(1) == "0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF" + assert ( + c.faz(1, "0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF") + == "0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF" + ) + + def test_default_param_internal_function(get_contract): code = """ @internal diff --git a/tests/functional/codegen/storage_variables/test_getters.py b/tests/functional/codegen/storage_variables/test_getters.py index 5eac074ef6..a2d9c6d0bb 100644 --- a/tests/functional/codegen/storage_variables/test_getters.py +++ b/tests/functional/codegen/storage_variables/test_getters.py @@ -19,6 +19,9 @@ def foo() -> int128: def test_getter_code(get_contract_with_gas_estimation_for_constants): getter_code = """ +interface V: + def foo(): nonpayable + struct W: a: uint256 b: int128[7] @@ -36,6 +39,7 @@ def test_getter_code(get_contract_with_gas_estimation_for_constants): d: public(immutable(uint256)) e: public(immutable(uint256[2])) f: public(constant(uint256[2])) = [3, 7] +g: public(constant(V)) = V(0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF) @external def __init__(): @@ -70,6 +74,7 @@ def __init__(): assert c.d() == 1729 assert c.e(0) == 2 assert [c.f(i) for i in range(2)] == [3, 7] + assert c.g() == "0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF" def test_getter_mutability(get_contract): diff --git a/tests/functional/syntax/test_constants.py b/tests/functional/syntax/test_constants.py index ffd2f1faa0..5937884181 100644 --- a/tests/functional/syntax/test_constants.py +++ b/tests/functional/syntax/test_constants.py @@ -304,6 +304,12 @@ def deposit(deposit_input: Bytes[2048]): CONST_BAR: constant(Bar) = Bar({c: C, d: D}) """, + """ +interface Foo: + def foo(): nonpayable + +FOO: constant(Foo) = Foo(0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF) + """, ]