Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tserg committed Feb 14, 2024
1 parent c5d0328 commit 7e98c1e
Show file tree
Hide file tree
Showing 17 changed files with 116 additions and 125 deletions.
2 changes: 1 addition & 1 deletion tests/functional/codegen/integration/test_crowdfund.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def __init__(_beneficiary: address, _goal: uint256, _timelimit: uint256):
def participate():
assert block.timestamp < self.deadline
nfi: int128 = self.nextFunderIndex
self.funders[nfi] = Funder({sender: msg.sender, value: msg.value})
self.funders[nfi] = Funder(sender=msg.sender, value=msg.value)
self.nextFunderIndex = nfi + 1
@external
Expand Down
4 changes: 2 additions & 2 deletions tests/functional/codegen/modules/test_stateless_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def test_library_structs(get_contract, make_input_bundle):
@internal
def foo() -> SomeStruct:
return SomeStruct({x: 1})
return SomeStruct(x=1)
"""
contract_source = """
import library
Expand All @@ -170,7 +170,7 @@ def bar(s: library.SomeStruct):
@external
def baz() -> library.SomeStruct:
return library.SomeStruct({x: 2})
return library.SomeStruct(x=2)
@external
def qux() -> library.SomeStruct:
Expand Down
32 changes: 16 additions & 16 deletions tests/functional/codegen/storage_variables/test_setters.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,16 @@ def test_multi_setter_struct_test(get_contract_with_gas_estimation):
@external
def foo() -> int128:
foo0: int128 = 1
self.dog[0] = Dog({foo: foo0, bar: 2})
self.dog[1] = Dog({foo: 3, bar: 4})
self.dog[2] = Dog({foo: 5, bar: 6})
self.dog[0] = Dog(foo=foo0, bar=2)
self.dog[1] = Dog(foo=3, bar=4)
self.dog[2] = Dog(foo=5, bar=6)
return self.dog[0].foo + self.dog[0].bar * 10 + self.dog[1].foo * 100 + \
self.dog[1].bar * 1000 + self.dog[2].foo * 10000 + self.dog[2].bar * 100000
@external
def fop() -> int128:
self.z = [Z({foo: [1, 2, 3], bar: [Bar({a: 4, b: 5}), Bar({a: 2, b: 3})]}),
Z({foo: [6, 7, 8], bar: [Bar({a: 9, b: 1}), Bar({a: 7, b: 8})]})]
self.z = [Z(foo=[1, 2, 3], bar=[Bar(a=4, b=5), Bar(a=2, b=3)]),
Z(foo=[6, 7, 8], bar=[Bar(a=9, b=1), Bar(a=7, b=8)])]
return self.z[0].foo[0] + self.z[0].foo[1] * 10 + self.z[0].foo[2] * 100 + \
self.z[0].bar[0].a * 1000 + \
self.z[0].bar[0].b * 10000 + \
Expand All @@ -116,15 +116,15 @@ def fop() -> int128:
@external
def goo() -> int128:
god: Goo[3] = [Goo({foo: 1, bar: 2}), Goo({foo: 3, bar: 4}), Goo({foo: 5, bar: 6})]
god: Goo[3] = [Goo(foo=1, bar=2), Goo(foo=3, bar=4), Goo(foo=5, bar=6)]
return god[0].foo + god[0].bar * 10 + god[1].foo * 100 + \
god[1].bar * 1000 + god[2].foo * 10000 + god[2].bar * 100000
@external
def gop() -> int128:
zed: Zed[2] = [
Zed({foo: [1, 2, 3], bar: [Bar({a: 4, b: 5}), Bar({a: 2, b: 3})]}),
Zed({foo: [6, 7, 8], bar: [Bar({a: 9, b: 1}), Bar({a: 7, b: 8})]})
Zed(foo=[1, 2, 3], bar=[Bar(a=4, b=5), Bar(a=2, b=3)]),
Zed(foo=[6, 7, 8], bar=[Bar(a=9, b=1), Bar(a=7, b=8)])
]
return zed[0].foo[0] + zed[0].foo[1] * 10 + \
zed[0].foo[2] * 100 + \
Expand Down Expand Up @@ -157,7 +157,7 @@ def test_struct_assignment_order(get_contract, assert_compile_failed):
@external
@view
def test2() -> uint256:
foo: Foo = Foo({b: 2, a: 297})
foo: Foo = Foo(b=2, a=297)
return foo.a
"""
assert_compile_failed(lambda: get_contract(code), InvalidAttribute)
Expand Down Expand Up @@ -193,25 +193,25 @@ def test_composite_setter_test(get_contract_with_gas_estimation):
@external
def foo() -> int128:
self.mom = Mom({a: [C({c: 1}), C({c: 2}), C({c: 3})], b: 4})
non: C = C({c: 5})
self.mom = Mom(a=[C(c=1), C(c=2), C(c=3)], b=4)
non: C = C(c=5)
self.mom.a[0] = non
non = C({c: 6})
non = C(c=6)
self.mom.a[2] = non
return self.mom.a[0].c + self.mom.a[1].c * 10 + self.mom.a[2].c * 100 + self.mom.b * 1000
@external
def fop() -> int128:
popp: Mom = Mom({a: [C({c: 1}), C({c: 2}), C({c: 3})], b: 4})
self.qoq = C({c: 5})
popp: Mom = Mom(a=[C(c=1), C(c=2), C(c=3)], b=4)
self.qoq = C(c=5)
popp.a[0] = self.qoq
self.qoq = C({c: 6})
self.qoq = C(c=6)
popp.a[2] = self.qoq
return popp.a[0].c + popp.a[1].c * 10 + popp.a[2].c * 100 + popp.b * 1000
@external
def foq() -> int128:
popp: Mom = Mom({a: [C({c: 1}), C({c: 2}), C({c: 3})], b: 4})
popp: Mom = Mom(a=[C(c=1), C(c=2), C(c=3)], b=4)
popp.a[0] = empty(C)
popp.a[2] = empty(C)
return popp.a[0].c + popp.a[1].c * 10 + popp.a[2].c * 100 + popp.b * 1000
Expand Down
8 changes: 4 additions & 4 deletions tests/functional/codegen/types/test_bytes.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def test_test_bytes5(get_contract_with_gas_estimation):
@external
def foo(inp1: Bytes[40], inp2: Bytes[45]):
self.g = G({a: inp1, b: inp2})
self.g = G(a=inp1, b=inp2)
@external
def check1() -> Bytes[50]:
Expand All @@ -144,17 +144,17 @@ def check2() -> Bytes[50]:
@external
def bar(inp1: Bytes[40], inp2: Bytes[45]) -> Bytes[50]:
h: H = H({a: inp1, b: inp2})
h: H = H(a=inp1, b=inp2)
return h.a
@external
def bat(inp1: Bytes[40], inp2: Bytes[45]) -> Bytes[50]:
h: H = H({a: inp1, b: inp2})
h: H = H(a=inp1, b=inp2)
return h.b
@external
def quz(inp1: Bytes[40], inp2: Bytes[45]):
h: H = H({a: inp1, b: inp2})
h: H = H(a=inp1, b=inp2)
self.g.a = h.a
self.g.b = h.b
"""
Expand Down
47 changes: 23 additions & 24 deletions tests/functional/codegen/types/test_dynamic_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -1362,12 +1362,12 @@ def test_list_of_structs_lists_with_nested_lists(get_contract, tx_failed):
def foo(x: uint8) -> uint8:
b: DynArray[Bar[2], 2] = [
[
Bar({a: [[x, x + 1], [x + 2, x + 3]]}),
Bar({a: [[x + 4, x +5], [x + 6, x + 7]]})
Bar(a=[[x, x + 1], [x + 2, x + 3]]),
Bar(a=[[x + 4, x +5], [x + 6, x + 7]])
],
[
Bar({a: [[x + 8, x + 9], [x + 10, x + 11]]}),
Bar({a: [[x + 12, x + 13], [x + 14, x + 15]]})
Bar(a=[[x + 8, x + 9], [x + 10, x + 11]]),
Bar(a=[[x + 12, x + 13], [x + 14, x + 15]])
],
]
return b[0][0].a[0][0] + b[0][1].a[1][1] + b[1][0].a[0][1] + b[1][1].a[1][0]
Expand Down Expand Up @@ -1503,11 +1503,11 @@ def _foo3() -> DynArray[DynArray[DynArray[uint256, 2], 2], 2]:
@external
def bar() -> DynArray[DynArray[DynArray[uint256, 2], 2], 2]:
foo: Foo = Foo({
a1: self._foo(),
a2: self._foo2(),
a3: self._foo3(),
})
foo: Foo = Foo(
a1=self._foo(),
a2=self._foo2(),
a3=self._foo3(),
)
return foo.a3
"""
c = get_contract(code)
Expand All @@ -1524,12 +1524,12 @@ def test_struct_of_lists_2(get_contract):
@internal
def _foo(x: int128) -> Foo:
f: Foo = Foo({
b: b"hello",
da: [x, x * 2],
sa: [x + 1, x + 2, x + 3, x + 4, x + 5],
some_int: x - 1
})
f: Foo = Foo(
b=b"hello",
da=[x, x * 2],
sa=[x + 1, x + 2, x + 3, x + 4, x + 5],
some_int=x - 1
)
return f
@external
Expand All @@ -1550,12 +1550,11 @@ def test_struct_of_lists_3(get_contract):
@internal
def _foo(x: int128) -> Foo:
f: Foo = Foo({
a: [x, x * 2],
b: [0x0000000000000000000000000000000000000012],
c: [False, True, False]
})
f: Foo = Foo(
a=[x, x * 2],
b=[0x0000000000000000000000000000000000000012],
c=[False, True, False]
)
return f
@external
Expand All @@ -1577,15 +1576,15 @@ def test_nested_struct_of_lists(get_contract, assert_compile_failed, optimize):
@internal
def _foo() -> nestedFoo:
return nestedFoo({a1: [
return nestedFoo(a1=[
[[3, 7], [7, 3]],
[[7, 3], [3, 7]],
]})
])
@internal
def _foo2() -> Foo:
_nF1: nestedFoo = self._foo()
return Foo({b1: [[[_nF1, _nF1], [_nF1, _nF1]], [[_nF1, _nF1], [_nF1, _nF1]]]})
return Foo(b1=[[[_nF1, _nF1], [_nF1, _nF1]], [[_nF1, _nF1], [_nF1, _nF1]]])
@internal
def _foo3(f: Foo) -> Foo:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def foo() -> int128:
"""
struct S:
x: int128
s: S = S({x: int128}, 1)
s: S = S(x=int128, 1)
""",
"""
struct S:
Expand Down
8 changes: 4 additions & 4 deletions tests/functional/syntax/test_ann_assign.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def data() -> int128:
b: decimal
@external
def foo() -> int128:
s: S = S({a: 1.2, b: 1})
s: S = S(a=1.2, b=1)
return s.a
""",
TypeMismatch,
Expand All @@ -71,7 +71,7 @@ def foo() -> int128:
b: decimal
@external
def foo() -> int128:
s: S = S({a: 1})
s: S = S(a=1)
""",
VariableDeclarationException,
),
Expand All @@ -82,7 +82,7 @@ def foo() -> int128:
b: decimal
@external
def foo() -> int128:
s: S = S({b: 1.2, a: 1})
s: S = S(b=1.2, a=1)
""",
InvalidAttribute,
),
Expand All @@ -93,7 +93,7 @@ def foo() -> int128:
b: decimal
@external
def foo() -> int128:
s: S = S({a: 1, b: 1.2, c: 1, d: 33, e: 55})
s: S = S(a=1, b=1.2, c=1, d=33, e=55)
return s.a
""",
UnknownAttribute,
Expand Down
6 changes: 3 additions & 3 deletions tests/functional/syntax/test_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ def add_record():
y: int128
@external
def add_record():
a: X = X({x: block.timestamp})
b: Y = Y({y: 5})
a: X = X(x=block.timestamp)
b: Y = Y(y=5)
a.x = b.y
""",
"""
Expand Down Expand Up @@ -123,7 +123,7 @@ def foo():
x: uint256
@external
def add_record():
a: X = X({x: block.timestamp})
a: X = X(x=block.timestamp)
a.x = block.gaslimit
a.x = block.basefee
a.x = 5
Expand Down
12 changes: 6 additions & 6 deletions tests/functional/syntax/test_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def test(VAL: uint256):
a: uint256
b: uint256
CONST_BAR: constant(Foo) = Foo({a: 1, b: block.number})
CONST_BAR: constant(Foo) = Foo(a=1, b=block.number)
""",
StateAccessViolation,
),
Expand Down Expand Up @@ -163,7 +163,7 @@ def foo() -> uint256:
struct Foo:
a : uint256
x: constant(Foo) = Foo({a: 1})
x: constant(Foo) = Foo(a=1)
@external
def hello() :
Expand Down Expand Up @@ -276,7 +276,7 @@ def deposit(deposit_input: Bytes[2048]):
a: uint256
b: uint256
CONST_BAR: constant(Foo) = Foo({a: 1, b: 2})
CONST_BAR: constant(Foo) = Foo(a=1, b=2)
""",
"""
CONST_EMPTY: constant(bytes32) = empty(bytes32)
Expand All @@ -293,7 +293,7 @@ def foo() -> bytes32:
A: constant(uint256) = 1
B: constant(uint256) = 2
CONST_BAR: constant(Foo) = Foo({a: A, b: B})
CONST_BAR: constant(Foo) = Foo(a=A, b=B)
""",
"""
struct Foo:
Expand All @@ -306,10 +306,10 @@ def foo() -> bytes32:
A: constant(uint256) = 1
B: constant(uint256) = 2
C: constant(Foo) = Foo({a: A, b: B})
C: constant(Foo) = Foo(a=A, b=B)
D: constant(int128) = -1
CONST_BAR: constant(Bar) = Bar({c: C, d: D})
CONST_BAR: constant(Bar) = Bar(c=C, d=D)
""",
"""
interface Foo:
Expand Down
8 changes: 4 additions & 4 deletions tests/functional/syntax/test_flag.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,10 @@ def run() -> Action:
@external
def run() -> Order:
return Order({
action: Action.BUY,
amount: 10**18
})
return Order(
action=Action.BUY,
amount=10**18
)
""",
"flag Foo:\n" + "\n".join([f" member{i}" for i in range(256)]),
"""
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/syntax/test_immutables.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def report():
@deploy
def __init__():
x = Foo({a:1})
x = Foo(a=1)
@external
def hello() :
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/syntax/test_invalids.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ def a():
@external
def a():
x: int128 = StructX({y: 1})
x: int128 = StructX(y=1)
""",
UnknownAttribute,
)
Expand Down
Loading

0 comments on commit 7e98c1e

Please sign in to comment.