Skip to content

Commit

Permalink
Refactored, finished testing suite
Browse files Browse the repository at this point in the history
  • Loading branch information
jakerockland committed Nov 29, 2018
1 parent cc993bc commit ba7822a
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 92 deletions.
92 changes: 75 additions & 17 deletions tests/parser/functions/test_reset.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def foo():
c.foo()


def test_reset_lists(get_contract_with_gas_estimation):
def test_reset_basic_type_lists(get_contract_with_gas_estimation):
contracts = [
"""
foobar: int128[3]
Expand Down Expand Up @@ -209,32 +209,90 @@ def foo():
assert bar[0] == ZERO_ADDRESS
assert bar[1] == ZERO_ADDRESS
assert bar[2] == ZERO_ADDRESS
"""
]

for contract in contracts:
c = get_contract_with_gas_estimation(contract)
c.foo()

foobar: address

def test_reset_bytes(get_contract_with_gas_estimation):
code = """
foobar: bytes[5]
@public
def foo():
self.foobar = msg.sender
bar: address = msg.sender
def foo() -> (bytes[5], bytes[5]):
self.foobar = 'Hello'
bar: bytes[5] = 'World'
reset(self.foobar)
reset(bar)
assert self.foobar == ZERO_ADDRESS
assert bar == ZERO_ADDRESS
return (self.foobar, bar)
"""
]

for contract in contracts:
c = get_contract_with_gas_estimation(contract)
c.foo()
c = get_contract_with_gas_estimation(code)
a, b = c.foo()
assert a == b''
assert b == b''


def test_reset_struct(get_contract_with_gas_estimation):
code = """
foobar: {
a: int128,
b: uint256,
c: bool,
d: decimal,
e: bytes32,
f: address
}
@public
def foo():
self.foobar = {
a: 1,
b: 2,
c: True,
d: 3.0,
e: 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF,
f: msg.sender
}
bar: {
a: int128,
b: uint256,
c: bool,
d: decimal,
e: bytes32,
f: address
} = {
a: 1,
b: 2,
c: True,
d: 3.0,
e: 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF,
f: msg.sender
}
reset(self.foobar)
reset(bar)
# def test_reset_struct(get_contract_with_gas_estimation):
# code = """
# #TODO
# """
assert self.foobar.a == 0
assert self.foobar.b == 0
assert self.foobar.c == False
assert self.foobar.d == 0.0
assert self.foobar.e == 0x0000000000000000000000000000000000000000000000000000000000000000
assert self.foobar.f == ZERO_ADDRESS
assert bar.a == 0
assert bar.b == 0
assert bar.c == False
assert bar.d == 0.0
assert bar.e == 0x0000000000000000000000000000000000000000000000000000000000000000
assert bar.f == ZERO_ADDRESS
"""

# c = get_contract_with_gas_estimation(code)
# c.foo()
c = get_contract_with_gas_estimation(code)
c.foo()

3 changes: 2 additions & 1 deletion tests/parser/syntax/test_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ def foo():
nom: {c: int128}[3]
@public
def foo():
self.mom = {b: 5}
empty: {c: int128}[3]
self.mom = {a: empty, b: 5}
""",
"""
mom: {a: {c: int128}[3], b: int128}
Expand Down
12 changes: 5 additions & 7 deletions vyper/functions/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
InvalidLiteralException,
StructureException,
TypeMismatchException,
ParserException,
)
from .signature import (
signature,
Expand Down Expand Up @@ -50,9 +51,6 @@
from vyper.types.convert import (
convert,
)
from vyper.types.reset import (
reset,
)


def enforce_units(typ, obj, expected):
Expand Down Expand Up @@ -104,10 +102,6 @@ def _convert(expr, context):
return convert(expr, context)


def _reset(expr, context):
return reset(expr, context)


@signature('bytes', start='int128', len='int128')
def _slice(expr, args, kwargs, context):
sub, start, length = args[0], kwargs['start'], kwargs['len']
Expand Down Expand Up @@ -689,6 +683,10 @@ def _can_compare_with_uint256(operand):
return LLLnode.from_list(['with', '_l', left, ['with', '_r', right, o]], typ=otyp, pos=getpos(expr))


def _reset():
raise ParserException("This function should never be called! `reset()` is currently handled differently than other functions as it self modifies its input argument statement. Please see `_reset()` in `stmt.py`")


dispatch_table = {
'floor': floor,
'ceil': ceil,
Expand Down
4 changes: 2 additions & 2 deletions vyper/parser/stmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def parse_if(self):
self.context.end_blockscope(block_scope_id)
return o

def reset_var(self):
def _reset(self):
# Create zero node
none = ast.NameConstant(None)
none.lineno = self.stmt.lineno
Expand All @@ -252,7 +252,7 @@ def call(self):
if isinstance(self.stmt.func, ast.Name):
if self.stmt.func.id in stmt_dispatch_table:
if self.stmt.func.id == 'reset':
return self.reset_var()
return self._reset()
else:
return stmt_dispatch_table[self.stmt.func.id](self.stmt, self.context)
elif self.stmt.func.id in dispatch_table:
Expand Down
65 changes: 0 additions & 65 deletions vyper/types/reset.py

This file was deleted.

0 comments on commit ba7822a

Please sign in to comment.