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

add: signature from abi to tester funcs #251

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
23 changes: 20 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,24 @@ 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(number, peers, really, **kargs)
# Docstring: yeah(uint32 number, uint256 peers, 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