Add fix for init_args.

This commit is contained in:
Jacques Wagener 2018-09-17 19:37:14 +02:00
parent 7c8b646c35
commit 7b35bf401c
No known key found for this signature in database
GPG Key ID: C294D1025DA0E923
2 changed files with 21 additions and 17 deletions

View File

@ -27,7 +27,7 @@ from web3 import (
aparser = argparse.ArgumentParser(description='Vyper {0} quick CLI runner'.format(vyper.__version__))
aparser.add_argument('input_file', help='Vyper sourcecode to run')
aparser.add_argument('call_list', help='call list, without parameters: func, with parameters func(1, 2, 3). Semicolon separated')
aparser.add_argument('-i', help='init args, comma separated', default='', dest='init_args')
aparser.add_argument('-i', help='init args, comma separated', default=None, dest='init_args')
args = aparser.parse_args()
set_evm_opcode_pass() # by default just pass over the debug opcode.
@ -146,8 +146,9 @@ if __name__ == '__main__':
init_abi = next(filter(lambda func: func["name"] == '__init__', abi))
init_args = cast_types(init_args, init_abi)
# Compile contract to chain.
contract = get_contract(w3, code, *init_args, language='vyper')
contract = get_contract(w3, code, *init_args)
# Execute calls
for func_name, args in calls:
@ -163,6 +164,7 @@ if __name__ == '__main__':
break
cast_args = cast_types(args, func_abi)
res = getattr(contract.functions, func_name)(*cast_args).call({'gas': func_abi.get('gas', 0) + 50000})
source_map = produce_source_map(code)
@ -171,6 +173,7 @@ if __name__ == '__main__':
set_evm_opcode_pass()
print('- Returns:')
res = getattr(contract.functions, func_name)(*cast_args).call({'gas': func_abi['gas'] + 92000})
pprint('{}'.format(res))
# Detect any new log events, and print them.

View File

@ -53,22 +53,23 @@ def produce_source_map(code):
prev_func_name = None
for _def in global_ctx._defs:
func_info = {
'from_lineno': _def.lineno,
'variables': {}
}
# set local variables for specific function.
context = contexts[_def.name]
func_info['variables'] = {
var_name: serialise_var_rec(var_rec)
for var_name, var_rec in context.vars.items()
}
if _def.name != '__init__':
func_info = {
'from_lineno': _def.lineno,
'variables': {}
}
# set local variables for specific function.
context = contexts[_def.name]
func_info['variables'] = {
var_name: serialise_var_rec(var_rec)
for var_name, var_rec in context.vars.items()
}
source_map['locals'][_def.name] = func_info
# set to_lineno
if prev_func_name:
source_map['locals'][prev_func_name]['to_lineno'] = _def.lineno
prev_func_name = _def.name
source_map['locals'][_def.name] = func_info
# set to_lineno
if prev_func_name:
source_map['locals'][prev_func_name]['to_lineno'] = _def.lineno
prev_func_name = _def.name
source_map['locals'][_def.name]['to_lineno'] = len(code.splitlines())