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 test_gatherloadedcontractparams(self): # test too few args with self.assertRaises(Exception) as e: args = [] script = "script" GatherLoadedContractParams(args, script) self.assertTrue( "please specify contract properties like {needs_storage} {needs_dynamic_invoke} {is_payable} {params} {return_type}" in str(e.exception)) # test for void (ff) type in params with self.assertRaises(ValueError) as e: args = ["False", "False", "False", "07ff10", "01"] script = b"script" GatherLoadedContractParams(args, script) self.assertTrue("Void is not a valid input parameter type" in str(e.exception)) # test good params with needs_dynamic_invoke with mock.patch("neo.Prompt.Commands.LoadSmartContract.generate_deploy_script", return_value=True): args = ["False", "True", "False", "070710", "01"] script = "script" res = GatherLoadedContractParams(args, script) self.assertTrue(res) # test no required params with mock.patch("neo.Prompt.Commands.LoadSmartContract.generate_deploy_script", return_value=True): args = ["False", "False", "False", "", "01"] script = "script" res = GatherLoadedContractParams(args, script) self.assertTrue(res)
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