def TestBuild(script, invoke_args, wallet, plist='05', ret='05', dynamic=False, invoke_attrs=None, owners=None): properties = ContractPropertyState.HasStorage if dynamic: properties += ContractPropertyState.HasDynamicInvoke if not isinstance(ret, bytearray): ret = bytearray(binascii.unhexlify(str(ret).encode('utf-8'))) script = generate_deploy_script(script, contract_properties=int(properties), parameter_list=plist, return_type=BigInteger.FromBytes(ret)) return test_deploy_and_invoke(script, invoke_args, wallet, invoke_attrs=invoke_attrs, owners=owners)
def DoRun(contract_script, arguments, wallet, path, verbose=True, from_addr=None, min_fee=DEFAULT_MIN_FEE): test = get_arg(arguments, 1) if test is not None and test == 'test': if wallet is not None: f_args = arguments[2:] i_args = arguments[6:] script = GatherLoadedContractParams(f_args, contract_script) tx, result, total_ops, engine = test_deploy_and_invoke( script, i_args, wallet, from_addr, min_fee) i_args.reverse() return_type_results = [] try: rtype = ContractParameterType.FromString(f_args[1]) for r in result: cp = ContractParameter.AsParameterType(rtype, r) return_type_results.append(cp.ToJson()) except Exception as e: logger.error( 'Could not convert result to ContractParameter: %s ' % e) if tx is not None and result is not None: if verbose: print( "\n-----------------------------------------------------------" ) print("Calling %s with arguments %s " % (path, i_args)) print("Test deploy invoke successful") print("Used total of %s operations " % total_ops) print("Result %s " % return_type_results) print("Invoke TX gas cost: %s " % (tx.Gas.value / Fixed8.D)) print( "-------------------------------------------------------------\n" ) return tx, result, total_ops, engine else: if verbose: print("Test invoke failed") print("tx is, results are %s %s " % (tx, result)) else: print("please open a wallet to test built contract") return None, None, None, None
def TestBuild(script, invoke_args, wallet, plist='05', ret='05', dynamic=False): properties = ContractPropertyState.HasStorage if dynamic: properties += ContractPropertyState.HasDynamicInvoke script = generate_deploy_script(script, contract_properties=int(properties), parameter_list=plist, return_type=ret) return test_deploy_and_invoke(script, invoke_args, wallet)
def TestBuild(script, invoke_args, wallet, plist='05', ret='05', dynamic=False): properties = ContractPropertyState.HasStorage if dynamic: properties += ContractPropertyState.HasDynamicInvoke if not isinstance(ret, bytearray): ret = bytearray(binascii.unhexlify(str(ret).encode('utf-8'))) script = generate_deploy_script(script, contract_properties=int(properties), parameter_list=plist, return_type=ret) return test_deploy_and_invoke(script, invoke_args, wallet)
def DoRun(contract_script, arguments, wallet, path, verbose=True, from_addr=None, min_fee=DEFAULT_MIN_FEE, invocation_test_mode=True, debug_map=None): test = get_arg(arguments, 1) if test is not None and test == 'test': if wallet is not None: f_args = arguments[2:] i_args = arguments[6:] script = GatherLoadedContractParams(f_args, contract_script) tx, result, total_ops, engine = test_deploy_and_invoke(script, i_args, wallet, from_addr, min_fee, invocation_test_mode, debug_map=debug_map) i_args.reverse() return_type_results = [] try: rtype = ContractParameterType.FromString(f_args[1]) for r in result: cp = ContractParameter.AsParameterType(rtype, r) return_type_results.append(cp.ToJson()) except Exception as e: logger.error('Could not convert result to ContractParameter: %s ' % e) if tx is not None and result is not None: if verbose: print("\n-----------------------------------------------------------") print("Calling %s with arguments %s " % (path, i_args)) print("Test deploy invoke successful") print("Used total of %s operations " % total_ops) print("Result %s " % return_type_results) print("Invoke TX gas cost: %s " % (tx.Gas.value / Fixed8.D)) print("-------------------------------------------------------------\n") return tx, result, total_ops, engine else: if verbose: print("Test invoke failed") print("tx is, results are %s %s " % (tx, result)) else: print("please open a wallet to test built contract") return None, None, None, None
def DoRun(contract_script, arguments, wallet, path): try: test = get_arg(arguments, 1) if test is not None and test == 'test': if wallet is not None: f_args = arguments[2:] i_args = arguments[5:] script = GatherLoadedContractParams(f_args, contract_script) tx, result, total_ops = test_deploy_and_invoke( script, i_args, wallet) i_args.reverse() if tx is not None and result is not None: print( "\n-----------------------------------------------------------" ) print("Calling %s with arguments %s " % (path, i_args)) print("Test deploy invoke successful") print("Used total of %s operations " % total_ops) print("Result %s " % result) print("Invoke TX gas cost: %s " % (tx.Gas.value / Fixed8.D)) print( "-------------------------------------------------------------\n" ) return else: print("test ivoke failed") print("tx is, results are %s %s " % (tx, result)) return else: print("please open a wallet to test built contract") except Exception as e: print("could not bulid %s " % e) traceback.print_stack() traceback.print_exc()
def DoRun(contract_script, arguments, wallet, path, verbose=True): test = get_arg(arguments, 1) if test is not None and test == 'test': if wallet is not None: f_args = arguments[2:] i_args = arguments[6:] script = GatherLoadedContractParams(f_args, contract_script) tx, result, total_ops, engine = test_deploy_and_invoke( script, i_args, wallet) i_args.reverse() #print (type(result)) if tx is not None and result is not None: if False: print( "\n-----------------------------------------------------------" ) print("Calling %s with arguments %s " % (path, i_args)) print("Test deploy invoke successful") print("Used total of %s operations " % total_ops) print("Result %s " % result) print(type(result)) print("Invoke TX gas cost: %s " % (tx.Gas.value / Fixed8.D)) print( "-------------------------------------------------------------\n" ) return tx, result, total_ops, engine else: if verbose: print("Test invoke failed") print("tx is, results are %s %s " % (tx, result)) else: print("please open a wallet to test built contract") return None, None, None, None
def DoRun(contract_script, arguments, wallet, path, verbose=True, from_addr=None, min_fee=DEFAULT_MIN_FEE, invocation_test_mode=True, debug_map=None, invoke_attrs=None, owners=None): if not wallet: print("Please open a wallet to test build contract") return None, None, None, None f_args = arguments[1:] i_args = arguments[6:] try: script = GatherLoadedContractParams(f_args, contract_script) except Exception: raise TypeError tx, result, total_ops, engine = test_deploy_and_invoke( script, i_args, wallet, from_addr, min_fee, invocation_test_mode, debug_map=debug_map, invoke_attrs=invoke_attrs, owners=owners) i_args.reverse() return_type_results = [] try: rtype = ContractParameterType.FromString(f_args[4]) for r in result: cp = ContractParameter.AsParameterType(rtype, r) return_type_results.append(cp.ToJson()) except Exception: raise TypeError if tx and result: if verbose: print( "\n-----------------------------------------------------------" ) print("Calling %s with arguments %s " % (path, [item for item in reversed(engine.invocation_args)])) print("Test deploy invoke successful") print("Used total of %s operations " % total_ops) print("Result %s " % return_type_results) print("Invoke TX gas cost: %s " % (tx.Gas.value / Fixed8.D)) print( "-------------------------------------------------------------\n" ) return tx, result, total_ops, engine else: if verbose: print("Test invoke failed") print(f"tx is {tx}, results are {result}") return tx, result, None, None