Skip to content

Commit

Permalink
Merge pull request #15 from tserg/fix/builtins-val-order
Browse files Browse the repository at this point in the history
add tests
  • Loading branch information
charles-cooper authored Sep 4, 2023
2 parents 021b7ab + f78bad2 commit 82df7a8
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/parser/functions/test_addmod.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,35 @@ def c() -> uint256:
c = get_contract_with_gas_estimation(code)

assert c.foo() == 2


def test_uint256_addmod_evaluation_order(get_contract_with_gas_estimation):
code = """
a: uint256
@external
def foo1() -> uint256:
self.a = 0
return uint256_addmod(self.a, 1, self.bar())
@external
def foo2() -> uint256:
self.a = 0
return uint256_addmod(self.a, self.bar(), 3)
@external
def foo3() -> uint256:
self.a = 0
return uint256_addmod(1, self.a, self.bar())
@internal
def bar() -> uint256:
self.a = 1
return 2
"""

c = get_contract_with_gas_estimation(code)

assert c.foo1() == 1
assert c.foo2() == 2
assert c.foo3() == 1
40 changes: 40 additions & 0 deletions tests/parser/functions/test_ec.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,26 @@ def foo(a: Foo) -> uint256[2]:
assert_side_effects_invoked(c1, lambda: c2.foo(c1.address, transact={}))


def test_ecadd_evaluation_order(get_contract_with_gas_estimation):
code = """
x: uint256[2]
@internal
def bar() -> uint256[2]:
self.x = ecadd([1, 2], [1, 2])
return [1, 2]
@external
def foo() -> bool:
self.x = [1, 2]
a: uint256[2] = ecadd([1, 2], [1, 2])
b: uint256[2] = ecadd(self.x, self.bar())
return a[0] == b[0] and a[1] == b[1]
"""
c = get_contract_with_gas_estimation(code)
assert c.foo() is True


def test_ecmul(get_contract_with_gas_estimation):
ecmuller = """
x3: uint256[2]
Expand Down Expand Up @@ -136,3 +156,23 @@ def foo(a: Foo) -> uint256[2]:
assert c2.foo(c1.address) == G1_times_three

assert_side_effects_invoked(c1, lambda: c2.foo(c1.address, transact={}))


def test_ecmul_evaluation_order(get_contract_with_gas_estimation):
code = """
x: uint256[2]
@internal
def bar() -> uint256:
self.x = ecmul([1, 2], 3)
return 3
@external
def foo() -> bool:
self.x = [1, 2]
a: uint256[2] = ecmul([1, 2], 3)
b: uint256[2] = ecmul(self.x, self.bar())
return a[0] == b[0] and a[1] == b[1]
"""
c = get_contract_with_gas_estimation(code)
assert c.foo() is True
32 changes: 32 additions & 0 deletions tests/parser/functions/test_mulmod.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,35 @@ def c() -> uint256:
c = get_contract_with_gas_estimation(code)

assert c.foo() == 600


def test_uint256_mulmod_evaluation_order(get_contract_with_gas_estimation):
code = """
a: uint256
@external
def foo1() -> uint256:
self.a = 1
return uint256_mulmod(self.a, 2, self.bar())
@external
def foo2() -> uint256:
self.a = 1
return uint256_mulmod(self.bar(), self.a, 2)
@external
def foo3() -> uint256:
self.a = 1
return uint256_mulmod(2, self.a, self.bar())
@internal
def bar() -> uint256:
self.a = 7
return 5
"""

c = get_contract_with_gas_estimation(code)

assert c.foo1() == 2
assert c.foo2() == 1
assert c.foo3() == 2

0 comments on commit 82df7a8

Please sign in to comment.