Skip to content
This repository has been archived by the owner on May 23, 2023. It is now read-only.

Commit

Permalink
add: signature from abi to tester funcs
Browse files Browse the repository at this point in the history
  • Loading branch information
heikoheiko committed Apr 26, 2015
1 parent 7519e7c commit 8336d58
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
4 changes: 3 additions & 1 deletion ethereum/abi.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def __init__(self, full_signature):
full_signature = json_decode(full_signature)
for sig_item in full_signature:
encode_types = [f['type'] for f in sig_item['inputs']]
signature = [(f['type'], f['name']) for f in sig_item['inputs']]
name = sig_item['name']
if '(' in name:
name = name[:name.find('(')]
Expand All @@ -41,7 +42,8 @@ def __init__(self, full_signature):
"prefix": prefix,
"encode_types": encode_types,
"decode_types": decode_types,
"is_unknown_type": is_unknown_type
"is_unknown_type": is_unknown_type,
"signature": signature
}
elif sig_item['type'] == 'event':
prefix = big_endian_to_int(utils.sha3(sig))
Expand Down
22 changes: 19 additions & 3 deletions ethereum/tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
from ethereum.slogging import LogRecorder, configure_logging, set_level
from ethereum.utils import to_string
from ethereum._solidity import get_solidity
from ethereum import slogging
import rlp
from rlp.utils import decode_hex, encode_hex, ascii_chr
from rlp.utils import ascii_chr

serpent = None

Expand Down Expand Up @@ -141,8 +142,23 @@ def kall(*args, **kwargs):
return outdata
return kall

for f in self._translator.function_data:
vars(self)[f] = kall_factory(f)
for fname in self._translator.function_data:
func = kall_factory(fname)
# create wrapper with signature
# in IPython: mycontract.yeah?
# Definition: mycontract.yeah(uint32_number, uint256_counter, bool_really)
signature = self._translator.function_data[fname]['signature']
fsig = ', '.join(name for typ, name in signature)
if fsig:
fsig += ', '
wfunc = 'def %s(%s**kargs): return func(%s**kargs)' % (fname, fsig, fsig)
wfunc_code = compile(wfunc, 'na', 'exec')
fakeglobals = {}
eval(wfunc_code, {'func': func}, fakeglobals) # evil, use in tester only!
func = fakeglobals[fname]
func.__doc__ = '%s(%s)' % (fname, ', '.join(('%s %s' % x) for x in signature))

setattr(self, fname, func)

return _abi_contract(me, code, sender, endowment, language)

Expand Down

0 comments on commit 8336d58

Please sign in to comment.