* Add testcase for empty types bug

* Fix Issue 869

Bug introduced in
0fc4bba9ad (diff-6cf4568b5e8712514d226faa04e417fbR450)

- Move empty string up to the beginning of the if-else chain.
- Correct test for bool type case

fixes #869
This commit is contained in:
Daniel James 2018-04-13 16:32:17 -04:00 committed by Mark Mossberg
parent aa792588fe
commit bfffa78b5f
2 changed files with 10 additions and 5 deletions

View File

@ -436,7 +436,10 @@ class ABI(object):
new_offset = offset + 32
if ty.startswith('uint'):
if ty == u'':
new_offset = offset
result = None
elif ty.startswith('uint'):
size = ABI._parse_size(ty[4:]) // 8
result = ABI.get_uint(data, size, offset)
@ -447,13 +450,10 @@ class ABI(object):
value = -(value & mask) + (value & ~mask)
result = value
elif ty in (u'bool'):
elif ty == u'bool':
result = ABI.get_uint(data, 1, offset)
elif ty == u'address':
result = ABI.get_uint(data, 20, offset)
elif ty == u'':
new_offset = offset
result = None
elif ty in (u'bytes', u'string'):
dyn_offset = ABI.get_uint(data, 32, offset)
size = ABI.get_uint(data, 32, dyn_offset)

View File

@ -202,6 +202,11 @@ class EthAbiTests(unittest.TestCase):
parsed = ABI.parse('uint{}'.format(i), data)
self.assertEqual(parsed, 2**i - 1)
def test_empty_types(self):
name, args = ABI.parse('func()', '\0'*32)
self.assertEqual(name, 'func')
self.assertEqual(args, tuple())
class EthTests(unittest.TestCase):
def test_emit_did_execute_end_instructions(self):