From ba231b1544c025d78820b1581b56941b6d0f8e9c Mon Sep 17 00:00:00 2001 From: jseagrave21 <40873301+jseagrave21@users.noreply.github.com> Date: Mon, 26 Nov 2018 17:03:06 -0800 Subject: [PATCH 01/35] Update Send.py refactor `send`, `sendmany`, and `sign` --- neo/Prompt/Commands/Send.py | 59 +++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/neo/Prompt/Commands/Send.py b/neo/Prompt/Commands/Send.py index 6ca449e00..5076d222e 100755 --- a/neo/Prompt/Commands/Send.py +++ b/neo/Prompt/Commands/Send.py @@ -13,9 +13,68 @@ import json from prompt_toolkit import prompt import traceback +from neo.Prompt.PromptData import PromptData +from neo.Prompt.CommandBase import CommandBase, CommandDesc, ParameterDesc from logzero import logger +class CommandWalletSend(CommandBase): + + def __init__(self): + super().__init__() + + def execute(self, arguments): + framework = construct_send_basic(PromptData.Wallet, arguments) + if type(framework) is list: + process_transaction(PromptData.Wallet, contract_tx=framework[0], scripthash_from=framework[1], fee=framework[2], owners=framework[3], user_tx_attributes=framework[4]) + + def command_desc(self): + p1 = ParameterDesc('assetId or name', 'the asset you wish to send') + p2 = ParameterDesc('address', 'the NEO address you will send to') + p3 = ParameterDesc('amount', 'the amount of the asset you wish to send') + p4 = ParameterDesc('--from-addr={addr}', 'specify the NEO address you wish to send from', optional=True) + p5 = ParameterDesc('--fee={priority_fee}', 'attach a fee to give your tx priority (> 0.001)', optional=True) + p6 = ParameterDesc('--owners=[{addr}, ...]', 'specify tx owners', optional=True) + p7 = ParameterDesc('--tx-attr=[{"usage": ,"data":""}, ...]', 'specify unique tx attributes', optional=True) + params = [p1, p2, p3, p4, p5, p6, p7] + return CommandDesc('send', 'send an asset', params=params) + +class CommandWalletSendMany(CommandBase): + + def __init__(self): + super().__init__() + + def execute(self, arguments): + framework = construct_send_many(PromptData.Wallet, arguments) + if type(framework) is list: + process_transaction(PromptData.Wallet, contract_tx=framework[0], scripthash_from=framework[1], scripthash_change=framework[2], fee=framework[3], owners=framework[4], user_tx_attributes=framework[5]) + + def command_desc(self): + p1 = ParameterDesc('number of outgoing tx', 'the number of tx you wish to send') + p2 = ParameterDesc('--change-addr={addr}', 'specify the change address', optional=True) + p3 = ParameterDesc('--from-addr={addr}', 'specify the NEO address you wish to send from', optional=True) + p4 = ParameterDesc('--fee={priority_fee}', 'attach a fee to give your tx priority (> 0.001)', optional=True) + p5 = ParameterDesc('--owners=[{addr}, ...]', 'specify tx owners', optional=True) + p6 = ParameterDesc('--tx-attr=[{"usage": ,"data":""}, ...]', 'specify unique tx attributes', optional=True) + params = [p1, p2, p3, p4, p5, p6] + return CommandDesc('sendmany', 'send multiple contract transactions', params=params) + +class CommandWalletSign(CommandBase): + + def __init__(self): + super().__init__() + + def execute(self, arguments): + if not PromptData.Wallet: + print("Please open a wallet before trying to sign") + jsn = get_arg(arguments) + parse_and_sign(PromptData.Wallet, jsn) + + def command_desc(self): + p1 = ParameterDesc('jsn', 'transaction in JSON format') + params = [p1] + return CommandDesc('sign', 'sign multi-sig tx', params=params) + def construct_send_basic(wallet, arguments): if not wallet: print("please open a wallet") From 1529505900edd89ec06aa03b28d2005bb66cd12c Mon Sep 17 00:00:00 2001 From: jseagrave21 <40873301+jseagrave21@users.noreply.github.com> Date: Mon, 26 Nov 2018 17:04:52 -0800 Subject: [PATCH 02/35] Update Wallet.py - reactor open and close and add support for send, sendmany, and sign --- neo/Prompt/Commands/Wallet.py | 78 ++++++++++++++++++++++++++++++++++- 1 file changed, 76 insertions(+), 2 deletions(-) diff --git a/neo/Prompt/Commands/Wallet.py b/neo/Prompt/Commands/Wallet.py index bd3ee75ec..41b8a65dd 100644 --- a/neo/Prompt/Commands/Wallet.py +++ b/neo/Prompt/Commands/Wallet.py @@ -19,6 +19,7 @@ from neo.Implementations.Wallets.peewee.Models import Account from neo.Prompt.CommandBase import CommandBase, CommandDesc, ParameterDesc from neo.Prompt.PromptData import PromptData +from neo.Prompt.Commands.Send import CommandWalletSend, CommandWalletSendMany, CommandWalletSign from neo.logging import log_manager @@ -30,9 +31,14 @@ def __init__(self): super().__init__() self.register_sub_command('create', CommandWalletCreate()) + self.register_sub_command('open', CommandWalletOpen()) + self.register_sub_command('close', CommandWalletClose()) self.register_sub_command(['v', '--v', 'verbose'], CommandWalletVerbose()) self.register_sub_command('migrate', CommandWalletMigrate()) self.register_sub_command('create_addr', CommandWalletCreateAddress()) + self.register_sub_command('send', CommandWalletSend()) + self.register_sub_command('sendmany', CommandWalletSendMany()) + self.register_sub_command('sign', CommandWalletSign()) def command_desc(self): return CommandDesc('wallet', 'manage wallets') @@ -41,10 +47,18 @@ def execute(self, arguments): wallet = PromptData.Wallet item = get_arg(arguments) - # Create and Open must be handled specially. + # Create, Open, and Close must be handled specially. if item == 'create': self.execute_sub_command(item, arguments[1:]) return + + elif item == 'open': + self.execute_sub_command(item, arguments[1:]) + return + + elif item == 'close': + self.execute_sub_command(item, arguments=None) + return if not wallet: print("Please open a wallet") @@ -67,6 +81,8 @@ def __init__(self): @classmethod def execute(cls, arguments): + if PromptData.Wallet: + CommandWalletClose.execute(arguments=None) path = get_arg(arguments, 0) if path: @@ -106,11 +122,69 @@ def execute(cls, arguments): print("Please specify a path") @classmethod - def command_desc(self): + def command_desc(cls): p1 = ParameterDesc('path', 'path to store the wallet file') return CommandDesc('create', 'creates a new NEO wallet address', [p1]) +class CommandWalletOpen(CommandBase): + + def __init__(self): + super().__init__() + + @classmethod + def execute(cls, arguments): + if PromptData.Wallet: + CommandWalletClose.execute(arguments=None) + + path = get_arg(arguments, 0) + + if path: + + if not os.path.exists(path): + print("Wallet file not found") + return + + passwd = prompt("[password]> ", is_password=True) + password_key = to_aes_key(passwd) + + try: + PromptData.Wallet = UserWallet.Open(path, password_key) + + PromptData.Prompt.start_wallet_loop() + print("Opened wallet at %s" % path) + return PromptData.Wallet + except Exception as e: + print("Could not open wallet: %s" % e) + + else: + print("Please specify a path") + + @classmethod + def command_desc(cls): + p1 = ParameterDesc('path', 'path to open the wallet file') + return CommandDesc('open', 'opens a NEO wallet', [p1]) + + +class CommandWalletClose(CommandBase): + + def __init__(self): + super().__init__() + + @classmethod + def execute(cls, arguments): + if PromptData.Wallet: + path = PromptData.Wallet._path + PromptData.Prompt.stop_wallet_loop() + PromptData.Wallet.Close() + PromptData.Wallet = None + print("Closed wallet %s" % path) + + @classmethod + def command_desc(cls): + return CommandDesc('close', 'closes the open NEO wallet') + + class CommandWalletVerbose(CommandBase): def __init__(self): From dba3ffb504b45acf794636c3e55a4dcebf5bb4a2 Mon Sep 17 00:00:00 2001 From: jseagrave21 <40873301+jseagrave21@users.noreply.github.com> Date: Mon, 26 Nov 2018 17:07:37 -0800 Subject: [PATCH 03/35] Update prompt.py - add support for `CommandWalletClose` and update for refactoring --- neo/bin/prompt.py | 84 +++++++++++++++++++++++------------------------ 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/neo/bin/prompt.py b/neo/bin/prompt.py index a50b4fa2a..e4efaa17c 100755 --- a/neo/bin/prompt.py +++ b/neo/bin/prompt.py @@ -30,13 +30,13 @@ from neo.Prompt.Commands.Invoke import InvokeContract, TestInvokeContract, test_invoke from neo.Prompt.Commands.LoadSmartContract import LoadContract, GatherContractDetails, ImportContractAddr, \ ImportMultiSigContractAddr -from neo.Prompt.Commands.Send import construct_send_basic, construct_send_many, process_transaction, parse_and_sign +# from neo.Prompt.Commands.Send import construct_send_basic, construct_send_many, process_transaction, parse_and_sign from neo.Prompt.Commands.Tokens import token_approve_allowance, token_get_allowance, token_send, token_send_from, \ token_mint, token_crowdsale_register, token_history # from neo.Prompt.Commands.Wallet import CreateAddress, DeleteAddress, ImportWatchAddr, ImportToken, ClaimGas, DeleteToken, AddAlias, \ # ShowUnspentCoins, SplitUnspentCoin -from neo.Prompt.Commands.Wallet import CommandWallet +from neo.Prompt.Commands.Wallet import CommandWallet, CommandWalletClose from neo.Prompt.PromptData import PromptData from neo.Prompt.Utils import get_arg, get_from_addr, get_tx_attr_from_args, get_owners_from_params @@ -133,7 +133,7 @@ class PromptInterface: # 'import token {token_contract_hash}', # 'export wif {address}', # 'export nep2 {address}', - # 'open wallet {path}', + # 'open wallet {path}', #DONE # 'create wallet {path}', #DONE # 'wallet (verbose)', #DONE # 'wallet claim (max_coins_to_claim)', @@ -152,10 +152,10 @@ class PromptInterface: # 'wallet tkn_history {token symbol}', # 'wallet unspent (neo/gas)', # 'wallet split {addr} {asset} {unspent index} {divide into number of vins}', - # 'wallet close', - # 'send {assetId or name} {address} {amount} (--from-addr={addr}) (--fee={priority_fee}) (--owners=[{addr}, ...]) (--tx-attr=[{"usage": ,"data":""}, ...])', - # 'sendmany {number of outgoing tx} (--change-addr={addr}) (--from-addr={addr}) (--fee={priority_fee}) (--owners=[{addr}, ...]) (--tx-attr=[{"usage": ,"data":""}, ...])', - # 'sign {transaction in JSON format}', + # 'wallet close', #DONE + # 'send {assetId or name} {address} {amount} (--from-addr={addr}) (--fee={priority_fee}) (--owners=[{addr}, ...]) (--tx-attr=[{"usage": ,"data":""}, ...])', #DONE + # 'sendmany {number of outgoing tx} (--change-addr={addr}) (--from-addr={addr}) (--fee={priority_fee}) (--owners=[{addr}, ...]) (--tx-attr=[{"usage": ,"data":""}, ...])', #DONE + # 'sign {transaction in JSON format}', #DONE # 'testinvoke {contract hash} [{params} or --i] (--attach-neo={amount}, --attach-gas={amount}) (--from-addr={addr}) --no-parse-addr (parse address strings to script hash bytearray)', # 'debugstorage {on/off/reset}' # ] @@ -206,14 +206,14 @@ def get_completer(self): # 'withdraw_reqest', 'completed', 'cancel', 'cleanup', # 'all', 'debugstorage', 'compiler-nep8', ] - if self.Wallet: - for addr in self.Wallet.Addresses: + if PromptData.Wallet: + for addr in PromptData.Wallet.Addresses: if addr not in self._known_things: self._known_things.append(addr) - for alias in self.Wallet.NamedAddr: + for alias in PromptData.Wallet.NamedAddr: if alias.Title not in self._known_things: self._known_things.append(alias.Title) - for tkn in self.Wallet.GetTokens().values(): + for tkn in PromptData.Wallet.GetTokens().values(): if tkn.symbol not in self._known_things: self._known_things.append(tkn.symbol) @@ -226,7 +226,7 @@ def get_completer(self): def quit(self): print('Shutting down. This may take a bit...') self.go_on = False - self.do_close_wallet() + CommandWalletClose.execute(arguments=None) reactor.stop() def help(self): @@ -239,37 +239,37 @@ def help(self): tokens.append(("class:command", f"\nRun 'COMMAND help' for more information on a command.")) print_formatted_text(FormattedText(tokens), style=self.token_style) - def do_open(self, arguments): - if self.Wallet: - self.do_close_wallet() + # def do_open(self, arguments): + # if self.Wallet: + # self.do_close_wallet() - item = get_arg(arguments) + # item = get_arg(arguments) - if item and item == 'wallet': + # if item and item == 'wallet': - path = get_arg(arguments, 1) + # path = get_arg(arguments, 1) - if path: + # if path: - if not os.path.exists(path): - print("Wallet file not found") - return + # if not os.path.exists(path): + # print("Wallet file not found") + # return - passwd = prompt("[password]> ", is_password=True) - password_key = to_aes_key(passwd) + # passwd = prompt("[password]> ", is_password=True) + # password_key = to_aes_key(passwd) - try: - self.Wallet = UserWallet.Open(path, password_key) + # try: + # self.Wallet = UserWallet.Open(path, password_key) - self.start_wallet_loop() - print("Opened wallet at %s" % path) - except Exception as e: - print("Could not open wallet: %s" % e) + # self.start_wallet_loop() + # print("Opened wallet at %s" % path) + # except Exception as e: + # print("Could not open wallet: %s" % e) - else: - print("Please specify a path") - else: - print("Please specify something to open") + # else: + # print("Please specify a path") + # else: + # print("Please specify something to open") # def do_create(self, arguments): # item = get_arg(arguments) @@ -319,7 +319,7 @@ def do_open(self, arguments): def start_wallet_loop(self): if self.wallet_loop_deferred: self.stop_wallet_loop() - self.walletdb_loop = task.LoopingCall(self.Wallet.ProcessBlocks) + self.walletdb_loop = task.LoopingCall(PromptData.Wallet.ProcessBlocks) self.wallet_loop_deferred = self.walletdb_loop.start(1) self.wallet_loop_deferred.addErrback(self.on_looperror) @@ -329,13 +329,13 @@ def stop_wallet_loop(self): if self.walletdb_loop and self.walletdb_loop.running: self.walletdb_loop.stop() - def do_close_wallet(self): - if self.Wallet: - path = self.Wallet._path - self.stop_wallet_loop() - self.Wallet.Close() - self.Wallet = None - print("Closed wallet %s" % path) + # def do_close_wallet(self): + # if self.Wallet: + # path = self.Wallet._path + # self.stop_wallet_loop() + # self.Wallet.Close() + # self.Wallet = None + # print("Closed wallet %s" % path) # def do_import(self, arguments): # item = get_arg(arguments) From 7d94d3cb2aea281c10fa51702a5c13911dabc885 Mon Sep 17 00:00:00 2001 From: jseagrave21 <40873301+jseagrave21@users.noreply.github.com> Date: Mon, 26 Nov 2018 17:12:07 -0800 Subject: [PATCH 04/35] Update Send.py - update for `make lint` --- neo/Prompt/Commands/Send.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/neo/Prompt/Commands/Send.py b/neo/Prompt/Commands/Send.py index 5076d222e..2d83d0602 100755 --- a/neo/Prompt/Commands/Send.py +++ b/neo/Prompt/Commands/Send.py @@ -39,6 +39,7 @@ def command_desc(self): params = [p1, p2, p3, p4, p5, p6, p7] return CommandDesc('send', 'send an asset', params=params) + class CommandWalletSendMany(CommandBase): def __init__(self): @@ -59,6 +60,7 @@ def command_desc(self): params = [p1, p2, p3, p4, p5, p6] return CommandDesc('sendmany', 'send multiple contract transactions', params=params) + class CommandWalletSign(CommandBase): def __init__(self): @@ -75,6 +77,7 @@ def command_desc(self): params = [p1] return CommandDesc('sign', 'sign multi-sig tx', params=params) + def construct_send_basic(wallet, arguments): if not wallet: print("please open a wallet") From 191b28ad2b125e3ffd16840cc3ce88b1a8c5794f Mon Sep 17 00:00:00 2001 From: jseagrave21 <40873301+jseagrave21@users.noreply.github.com> Date: Mon, 26 Nov 2018 17:13:14 -0800 Subject: [PATCH 05/35] Update Wallet.py - update for `make lint` --- neo/Prompt/Commands/Wallet.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/neo/Prompt/Commands/Wallet.py b/neo/Prompt/Commands/Wallet.py index 41b8a65dd..c7ae506ef 100644 --- a/neo/Prompt/Commands/Wallet.py +++ b/neo/Prompt/Commands/Wallet.py @@ -51,11 +51,11 @@ def execute(self, arguments): if item == 'create': self.execute_sub_command(item, arguments[1:]) return - + elif item == 'open': self.execute_sub_command(item, arguments[1:]) return - + elif item == 'close': self.execute_sub_command(item, arguments=None) return @@ -131,7 +131,7 @@ class CommandWalletOpen(CommandBase): def __init__(self): super().__init__() - + @classmethod def execute(cls, arguments): if PromptData.Wallet: @@ -179,7 +179,7 @@ def execute(cls, arguments): PromptData.Wallet.Close() PromptData.Wallet = None print("Closed wallet %s" % path) - + @classmethod def command_desc(cls): return CommandDesc('close', 'closes the open NEO wallet') From 7d14b07207b124afea2f14bd5e45345dc04d45af Mon Sep 17 00:00:00 2001 From: jseagrave21 <40873301+jseagrave21@users.noreply.github.com> Date: Mon, 26 Nov 2018 22:31:36 -0800 Subject: [PATCH 06/35] Update prompt.py - update CommandWalletClose --- neo/bin/prompt.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neo/bin/prompt.py b/neo/bin/prompt.py index e4efaa17c..433528e4e 100755 --- a/neo/bin/prompt.py +++ b/neo/bin/prompt.py @@ -226,7 +226,7 @@ def get_completer(self): def quit(self): print('Shutting down. This may take a bit...') self.go_on = False - CommandWalletClose.execute(arguments=None) + CommandWalletClose.execute() reactor.stop() def help(self): From dd8030f3e95103cd95d5d865b93b04bb8d109282 Mon Sep 17 00:00:00 2001 From: jseagrave21 <40873301+jseagrave21@users.noreply.github.com> Date: Mon, 26 Nov 2018 22:33:51 -0800 Subject: [PATCH 07/35] Update CommandBase.py - update to match https://github.com/CityOfZion/neo-python/pull/725 and also allow for subcommands to execute without arguments --- neo/Prompt/CommandBase.py | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/neo/Prompt/CommandBase.py b/neo/Prompt/CommandBase.py index d9b01b092..25d6646b6 100644 --- a/neo/Prompt/CommandBase.py +++ b/neo/Prompt/CommandBase.py @@ -66,18 +66,25 @@ def command_desc(self): pass # Raise KeyError exception if the command does not exist - def execute_sub_command(self, id, arguments): - self.__sub_commands[id].execute(arguments) - - # ids: can be either a string or a list of strings. - def register_sub_command(self, ids, sub_command): - if isinstance(ids, list): - for id in ids: - self.__register_sub_command(id, sub_command) + def execute_sub_command(self, id, arguments=None): + if arguments is not None: + self.__sub_commands[id].execute(arguments) else: - self.__register_sub_command(ids, sub_command) + self.__sub_commands[id].execute() - def __register_sub_command(self, id, sub_command): + def register_sub_command(self, sub_command, additional_ids=[]): + """ + Register a command as a subcommand. + It will have it's CommandDesc.command string used as id. Additional ids can be provided. + Args: + sub_command (CommandBase): Subcommand to register. + additional_ids (List[str]): List of additional ids. Can be empty. + """ + self.__register_sub_command(sub_command, sub_command.command_desc().command) + for id in additional_ids: + self.__register_sub_command(sub_command, id) + + def __register_sub_command(self, sub_command, id): if id in self.__sub_commands: raise ValueError(f"{id} is already a subcommand of {self.command_desc().command}.") if sub_command.__parent_command and sub_command.__parent_command != self: From d9f5102ef0ad1713e5e8eacc3eccd4c47ddd1abd Mon Sep 17 00:00:00 2001 From: jseagrave21 <40873301+jseagrave21@users.noreply.github.com> Date: Mon, 26 Nov 2018 22:35:20 -0800 Subject: [PATCH 08/35] Update Wallet.py - update to match https://github.com/CityOfZion/neo-python/pull/725 and update CommandWalletClose.execute() w/o arguments --- neo/Prompt/Commands/Wallet.py | 41 +++++++++++++++-------------------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/neo/Prompt/Commands/Wallet.py b/neo/Prompt/Commands/Wallet.py index c7ae506ef..2be445ed1 100644 --- a/neo/Prompt/Commands/Wallet.py +++ b/neo/Prompt/Commands/Wallet.py @@ -30,15 +30,15 @@ class CommandWallet(CommandBase): def __init__(self): super().__init__() - self.register_sub_command('create', CommandWalletCreate()) - self.register_sub_command('open', CommandWalletOpen()) - self.register_sub_command('close', CommandWalletClose()) - self.register_sub_command(['v', '--v', 'verbose'], CommandWalletVerbose()) - self.register_sub_command('migrate', CommandWalletMigrate()) - self.register_sub_command('create_addr', CommandWalletCreateAddress()) - self.register_sub_command('send', CommandWalletSend()) - self.register_sub_command('sendmany', CommandWalletSendMany()) - self.register_sub_command('sign', CommandWalletSign()) + self.register_sub_command(CommandWalletCreate()) + self.register_sub_command(CommandWalletOpen()) + self.register_sub_command(CommandWalletClose()) + self.register_sub_command(CommandWalletVerbose(), ['v', '--v']) + self.register_sub_command(CommandWalletMigrate()) + self.register_sub_command(CommandWalletCreateAddress()) + self.register_sub_command(CommandWalletSend()) + self.register_sub_command(CommandWalletSendMany()) + self.register_sub_command(CommandWalletSign()) def command_desc(self): return CommandDesc('wallet', 'manage wallets') @@ -57,7 +57,7 @@ def execute(self, arguments): return elif item == 'close': - self.execute_sub_command(item, arguments=None) + self.execute_sub_command(item) return if not wallet: @@ -79,10 +79,9 @@ class CommandWalletCreate(CommandBase): def __init__(self): super().__init__() - @classmethod - def execute(cls, arguments): + def execute(self, arguments): if PromptData.Wallet: - CommandWalletClose.execute(arguments=None) + CommandWalletClose.execute() path = get_arg(arguments, 0) if path: @@ -121,8 +120,7 @@ def execute(cls, arguments): else: print("Please specify a path") - @classmethod - def command_desc(cls): + def command_desc(self): p1 = ParameterDesc('path', 'path to store the wallet file') return CommandDesc('create', 'creates a new NEO wallet address', [p1]) @@ -132,10 +130,9 @@ class CommandWalletOpen(CommandBase): def __init__(self): super().__init__() - @classmethod - def execute(cls, arguments): + def execute(self, arguments): if PromptData.Wallet: - CommandWalletClose.execute(arguments=None) + CommandWalletClose.execute() path = get_arg(arguments, 0) @@ -160,8 +157,7 @@ def execute(cls, arguments): else: print("Please specify a path") - @classmethod - def command_desc(cls): + def command_desc(self): p1 = ParameterDesc('path', 'path to open the wallet file') return CommandDesc('open', 'opens a NEO wallet', [p1]) @@ -172,7 +168,7 @@ def __init__(self): super().__init__() @classmethod - def execute(cls, arguments): + def execute(cls): if PromptData.Wallet: path = PromptData.Wallet._path PromptData.Prompt.stop_wallet_loop() @@ -180,8 +176,7 @@ def execute(cls, arguments): PromptData.Wallet = None print("Closed wallet %s" % path) - @classmethod - def command_desc(cls): + def command_desc(self): return CommandDesc('close', 'closes the open NEO wallet') From ad864fc18a140cbb7e3a9ea62b9260ad96b52c36 Mon Sep 17 00:00:00 2001 From: jseagrave21 <40873301+jseagrave21@users.noreply.github.com> Date: Tue, 27 Nov 2018 01:23:19 -0800 Subject: [PATCH 09/35] Update CommandBase.py for compatibility --- neo/Prompt/CommandBase.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/neo/Prompt/CommandBase.py b/neo/Prompt/CommandBase.py index 25d6646b6..cc7164970 100644 --- a/neo/Prompt/CommandBase.py +++ b/neo/Prompt/CommandBase.py @@ -65,18 +65,15 @@ def execute(self, arguments): def command_desc(self): pass - # Raise KeyError exception if the command does not exist - def execute_sub_command(self, id, arguments=None): - if arguments is not None: - self.__sub_commands[id].execute(arguments) - else: - self.__sub_commands[id].execute() + def execute_sub_command(self, id, arguments): + self.__sub_commands[id].execute(arguments) def register_sub_command(self, sub_command, additional_ids=[]): """ Register a command as a subcommand. It will have it's CommandDesc.command string used as id. Additional ids can be provided. - Args: + + Args: sub_command (CommandBase): Subcommand to register. additional_ids (List[str]): List of additional ids. Can be empty. """ From 309c59426cce0f800bbbb873795d5eb50906b626 Mon Sep 17 00:00:00 2001 From: jseagrave21 <40873301+jseagrave21@users.noreply.github.com> Date: Tue, 27 Nov 2018 01:29:09 -0800 Subject: [PATCH 10/35] Update Wallet.py for compatibility --- neo/Prompt/Commands/Wallet.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/neo/Prompt/Commands/Wallet.py b/neo/Prompt/Commands/Wallet.py index 2be445ed1..063a58347 100644 --- a/neo/Prompt/Commands/Wallet.py +++ b/neo/Prompt/Commands/Wallet.py @@ -30,15 +30,9 @@ class CommandWallet(CommandBase): def __init__(self): super().__init__() - self.register_sub_command(CommandWalletCreate()) - self.register_sub_command(CommandWalletOpen()) - self.register_sub_command(CommandWalletClose()) self.register_sub_command(CommandWalletVerbose(), ['v', '--v']) self.register_sub_command(CommandWalletMigrate()) self.register_sub_command(CommandWalletCreateAddress()) - self.register_sub_command(CommandWalletSend()) - self.register_sub_command(CommandWalletSendMany()) - self.register_sub_command(CommandWalletSign()) def command_desc(self): return CommandDesc('wallet', 'manage wallets') From 0a12c556d829ecd94d87e253186d64037cef086a Mon Sep 17 00:00:00 2001 From: jseagrave21 <40873301+jseagrave21@users.noreply.github.com> Date: Tue, 27 Nov 2018 01:29:57 -0800 Subject: [PATCH 11/35] Update Wallet.py for compatibility --- neo/Prompt/Commands/Wallet.py | 1 + 1 file changed, 1 insertion(+) diff --git a/neo/Prompt/Commands/Wallet.py b/neo/Prompt/Commands/Wallet.py index 063a58347..c59f7c27d 100644 --- a/neo/Prompt/Commands/Wallet.py +++ b/neo/Prompt/Commands/Wallet.py @@ -30,6 +30,7 @@ class CommandWallet(CommandBase): def __init__(self): super().__init__() + self.register_sub_command(CommandWalletCreate()) self.register_sub_command(CommandWalletVerbose(), ['v', '--v']) self.register_sub_command(CommandWalletMigrate()) self.register_sub_command(CommandWalletCreateAddress()) From de7987590e1d9f5674f402810998d7af9e88b448 Mon Sep 17 00:00:00 2001 From: jseagrave21 <40873301+jseagrave21@users.noreply.github.com> Date: Tue, 27 Nov 2018 01:30:52 -0800 Subject: [PATCH 12/35] Update Wallet.py for compatibility --- neo/Prompt/Commands/Wallet.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/neo/Prompt/Commands/Wallet.py b/neo/Prompt/Commands/Wallet.py index c59f7c27d..f66009fc0 100644 --- a/neo/Prompt/Commands/Wallet.py +++ b/neo/Prompt/Commands/Wallet.py @@ -75,8 +75,6 @@ def __init__(self): super().__init__() def execute(self, arguments): - if PromptData.Wallet: - CommandWalletClose.execute() path = get_arg(arguments, 0) if path: From 86396e074e7d49614ddd9350754077fed8003bcd Mon Sep 17 00:00:00 2001 From: jseagrave21 <40873301+jseagrave21@users.noreply.github.com> Date: Tue, 27 Nov 2018 01:32:49 -0800 Subject: [PATCH 13/35] Update prompt.py - update CommandWalletClose --- neo/bin/prompt.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neo/bin/prompt.py b/neo/bin/prompt.py index 433528e4e..fdfd5b77c 100755 --- a/neo/bin/prompt.py +++ b/neo/bin/prompt.py @@ -226,7 +226,7 @@ def get_completer(self): def quit(self): print('Shutting down. This may take a bit...') self.go_on = False - CommandWalletClose.execute() + CommandWalletClose().execute() reactor.stop() def help(self): From fe95dee371c96d639eeb401e90651d3e4bbf7781 Mon Sep 17 00:00:00 2001 From: jseagrave21 <40873301+jseagrave21@users.noreply.github.com> Date: Tue, 27 Nov 2018 01:35:51 -0800 Subject: [PATCH 14/35] Update Send.py - remove redundant logic --- neo/Prompt/Commands/Send.py | 52 ++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 30 deletions(-) diff --git a/neo/Prompt/Commands/Send.py b/neo/Prompt/Commands/Send.py index 2d83d0602..c6d6c00ee 100755 --- a/neo/Prompt/Commands/Send.py +++ b/neo/Prompt/Commands/Send.py @@ -67,8 +67,6 @@ def __init__(self): super().__init__() def execute(self, arguments): - if not PromptData.Wallet: - print("Please open a wallet before trying to sign") jsn = get_arg(arguments) parse_and_sign(PromptData.Wallet, jsn) @@ -79,12 +77,9 @@ def command_desc(self): def construct_send_basic(wallet, arguments): - if not wallet: - print("please open a wallet") - return False if len(arguments) < 3: print("Not enough arguments") - return False + return arguments, from_address = get_from_addr(arguments) arguments, priority_fee = get_fee(arguments) @@ -97,19 +92,19 @@ def construct_send_basic(wallet, arguments): assetId = get_asset_id(wallet, to_send) if assetId is None: print("Asset id not found") - return False + return scripthash_to = lookup_addr_str(wallet, address_to) if scripthash_to is None: logger.debug("invalid address") - return False + return scripthash_from = None if from_address is not None: scripthash_from = lookup_addr_str(wallet, from_address) if scripthash_from is None: logger.debug("invalid address") - return False + return # if this is a token, we will use a different # transfer mechanism @@ -119,17 +114,17 @@ def construct_send_basic(wallet, arguments): f8amount = get_asset_amount(amount, assetId) if f8amount is False: logger.debug("invalid amount") - return False + return if float(amount) == 0: print("amount cannot be 0") - return False + return fee = Fixed8.Zero() if priority_fee is not None: fee = priority_fee if fee is False: logger.debug("invalid fee") - return False + return output = TransactionOutput(AssetId=assetId, Value=f8amount, script_hash=scripthash_to) contract_tx = ContractTransaction(outputs=[output]) @@ -137,20 +132,17 @@ def construct_send_basic(wallet, arguments): def construct_send_many(wallet, arguments): - if not wallet: - print("please open a wallet") - return False if len(arguments) is 0: print("Not enough arguments") - return False + return outgoing = get_arg(arguments, convert_to_int=True) if outgoing is None: print("invalid outgoing number") - return False + return if outgoing < 1: print("outgoing number must be >= 1") - return False + return arguments, from_address = get_from_addr(arguments) arguments, change_address = get_change_addr(arguments) @@ -165,23 +157,23 @@ def construct_send_many(wallet, arguments): assetId = get_asset_id(wallet, to_send) if assetId is None: print("Asset id not found") - return False + return if type(assetId) is NEP5Token: print('Sendmany does not support NEP5 tokens') - return False + return address_to = prompt("Address to: ") scripthash_to = lookup_addr_str(wallet, address_to) if scripthash_to is None: logger.debug("invalid address") - return False + return amount = prompt("Amount to send: ") f8amount = get_asset_amount(amount, assetId) if f8amount is False: logger.debug("invalid amount") - return False + return if float(amount) == 0: print("amount cannot be 0") - return False + return tx_output = TransactionOutput(AssetId=assetId, Value=f8amount, script_hash=scripthash_to) output.append(tx_output) contract_tx = ContractTransaction(outputs=output) @@ -192,7 +184,7 @@ def construct_send_many(wallet, arguments): scripthash_from = lookup_addr_str(wallet, from_address) if scripthash_from is None: logger.debug("invalid address") - return False + return scripthash_change = None @@ -200,14 +192,14 @@ def construct_send_many(wallet, arguments): scripthash_change = lookup_addr_str(wallet, change_address) if scripthash_change is None: logger.debug("invalid address") - return False + return fee = Fixed8.Zero() if priority_fee is not None: fee = priority_fee if fee is False: logger.debug("invalid fee") - return False + return print("sending with fee: %s " % fee.ToString()) return [contract_tx, scripthash_from, scripthash_change, fee, owners, user_tx_attributes] @@ -222,13 +214,13 @@ def process_transaction(wallet, contract_tx, scripthash_from=None, scripthash_ch if tx is None: logger.debug("insufficient funds") - return False + return # password prompt passwd = prompt("[Password]> ", is_password=True) if not wallet.ValidatePassword(passwd): print("incorrect password") - return False + return standard_contract = wallet.GetStandardAddress() @@ -278,14 +270,14 @@ def process_transaction(wallet, contract_tx, scripthash_from=None, scripthash_ch else: print("Transaction initiated, but the signature is incomplete") print(json.dumps(context.ToJson(), separators=(',', ':'))) - return False + return except Exception as e: print("could not send: %s " % e) traceback.print_stack() traceback.print_exc() - return False + return def parse_and_sign(wallet, jsn): From d288e4d31678474662d84bb051d4786703c909dd Mon Sep 17 00:00:00 2001 From: jseagrave21 <40873301+jseagrave21@users.noreply.github.com> Date: Tue, 27 Nov 2018 01:37:35 -0800 Subject: [PATCH 15/35] Update test_send_command.py - add tests to show normal functionality --- .../Commands/tests/test_send_command.py | 97 +++++++++---------- 1 file changed, 46 insertions(+), 51 deletions(-) diff --git a/neo/Prompt/Commands/tests/test_send_command.py b/neo/Prompt/Commands/tests/test_send_command.py index 3721f036a..59b3e1274 100644 --- a/neo/Prompt/Commands/tests/test_send_command.py +++ b/neo/Prompt/Commands/tests/test_send_command.py @@ -6,12 +6,11 @@ from neo.Prompt.Commands.Send import construct_send_basic, construct_send_many, process_transaction from neo.Prompt.Commands.Wallet import ImportToken from neo.Prompt.Utils import get_tx_attr_from_args -from neo.Prompt.Commands import Send +from neo.Prompt.Commands import Send, Wallet import shutil -from mock import MagicMock +from mock import MagicMock, patch import json - -from mock import patch +from io import StringIO class UserWalletTestCase(WalletFixtureTestCase): @@ -40,26 +39,26 @@ def GetWallet1(cls, recreate=False): return cls._wallet1 def test_send_neo(self): - with patch('neo.Prompt.Commands.Send.prompt', side_effect=[UserWalletTestCase.wallet_1_pass()]): - wallet = self.GetWallet1(recreate=True) - args = ['neo', self.watch_addr_str, '50'] - - framework = construct_send_basic(wallet, args) - res = process_transaction(wallet, contract_tx=framework[0], scripthash_from=framework[1], fee=framework[2], owners=framework[3], user_tx_attributes=framework[4]) - - self.assertTrue(res) + wallet = self.GetWallet1(recreate=True) + with patch('neo.Prompt.PromptData.PromptData.Wallet', return_value=wallet): + with patch('neo.Prompt.Commands.Send.prompt', side_effect=[UserWalletTestCase.wallet_1_pass()]): + with patch('sys.stdout', new=StringIO()) as mock_print: + args = ['send', 'neo', self.watch_addr_str, '50'] + command_wallet = Wallet.CommandWallet() + command_wallet.execute(args) - def test_send_gas_mimic_prompt(self): - with patch('neo.Prompt.Commands.Send.prompt', side_effect=[UserWalletTestCase.wallet_1_pass()]): - wallet = self.GetWallet1(recreate=True) - args = ['gas', self.watch_addr_str, '5'] - res = False + self.assertIn("Relayed Tx", mock_print.getvalue()) - framework = construct_send_basic(wallet, args) - if type(framework) is list: - res = process_transaction(wallet, contract_tx=framework[0], scripthash_from=framework[1], fee=framework[2], owners=framework[3], user_tx_attributes=framework[4]) + def test_send_gas(self): + wallet = self.GetWallet1(recreate=True) + with patch('neo.Prompt.PromptData.PromptData.Wallet', return_value=wallet): + with patch('neo.Prompt.Commands.Send.prompt', side_effect=[UserWalletTestCase.wallet_1_pass()]): + with patch('sys.stdout', new=StringIO()) as mock_print: + args = ['send', 'gas', self.watch_addr_str, '5'] + command_wallet = Wallet.CommandWallet() + command_wallet.execute(args) - self.assertTrue(res) + self.assertIn("Relayed Tx", mock_print.getvalue()) def test_send_with_fee_and_from_addr(self): with patch('neo.Prompt.Commands.Send.prompt', side_effect=[UserWalletTestCase.wallet_1_pass()]): @@ -77,13 +76,12 @@ def test_send_with_fee_and_from_addr(self): self.assertEqual(json_res['net_fee'], "0.005") # verify correct fee def test_send_no_wallet(self): + with patch('sys.stdout', new=StringIO()) as mock_print: + args = ["send", "neo", self.wallet_1_addr, '5'] + command_wallet = Wallet.CommandWallet() + command_wallet.execute(args) - wallet = None - args = ['neo', self.watch_addr_str, '50'] - - framework = construct_send_basic(wallet, args) - - self.assertFalse(framework) + self.assertIn("Please open a wallet", mock_print.getvalue()) def test_send_bad_args(self): @@ -328,25 +326,15 @@ def test_could_not_send(self, mocked_tracback_module): self.assertFalse(res) def test_sendmany_good_simple(self): - with patch('neo.Prompt.Commands.Send.prompt', side_effect=["neo", self.watch_addr_str, "1", "gas", self.watch_addr_str, "1", UserWalletTestCase.wallet_1_pass()]): - - wallet = self.GetWallet1(recreate=True) - args = ["2"] - - framework = construct_send_many(wallet, args) - res = process_transaction(wallet, contract_tx=framework[0], scripthash_from=framework[1], scripthash_change=framework[2], fee=framework[3], owners=framework[4], user_tx_attributes=framework[5]) - - self.assertTrue(res) # verify successful tx - - json_res = res.ToJson() - self.assertEqual(self.watch_addr_str, json_res['vout'][0]['address']) # verify correct address_to + wallet = self.GetWallet1(recreate=True) + with patch('neo.Prompt.PromptData.PromptData.Wallet', return_value=wallet): + with patch('neo.Prompt.Commands.Send.prompt', side_effect=["neo", self.watch_addr_str, "1", "gas", self.watch_addr_str, "1", UserWalletTestCase.wallet_1_pass()]): + with patch('sys.stdout', new=StringIO()) as mock_print: + args = ['sendmany', '2'] + command_wallet = Wallet.CommandWallet() + command_wallet.execute(args) - # check for 2 transfers - transfers = 0 - for info in json_res['vout']: - if info['address'] == self.watch_addr_str: - transfers += 1 - self.assertEqual(2, transfers) + self.assertIn("Relayed Tx", mock_print.getvalue()) def test_sendmany_good_complex(self): with patch('neo.Prompt.Commands.Send.prompt', side_effect=["neo", "AXjaFSP23Jkbe6Pk9pPGT6NBDs1HVdqaXK", "1", "gas", "AXjaFSP23Jkbe6Pk9pPGT6NBDs1HVdqaXK", "1", UserWalletTestCase.wallet_1_pass()]): @@ -365,18 +353,25 @@ def test_sendmany_good_complex(self): json_res = res.ToJson() self.assertEqual("AXjaFSP23Jkbe6Pk9pPGT6NBDs1HVdqaXK", json_res['vout'][0]['address']) # verify correct address_to + + # check for 2 transfers + transfers = 0 + for info in json_res['vout']: + if info['address'] == self.watch_addr_str: + transfers += 1 + self.assertEqual(2, transfers) + self.assertEqual(self.watch_addr_str, json_res['vout'][2]['address']) # verify correct change address self.assertEqual(float(address_from_gas_bal) - 1 - 0.005, float(json_res['vout'][3]['value'])) self.assertEqual('0.005', json_res['net_fee']) def test_sendmany_no_wallet(self): + with patch('sys.stdout', new=StringIO()) as mock_print: + args = ['sendmany', '2'] + command_wallet = Wallet.CommandWallet() + command_wallet.execute(args) - wallet = None - args = ['2'] - - framework = construct_send_many(wallet, args) - - self.assertFalse(framework) + self.assertIn("Please open a wallet", mock_print.getvalue()) def test_sendmany_bad_args(self): From d654416c684863a2bd5cd2201725a2addbc16601 Mon Sep 17 00:00:00 2001 From: jseagrave21 <40873301+jseagrave21@users.noreply.github.com> Date: Tue, 27 Nov 2018 01:42:49 -0800 Subject: [PATCH 16/35] Update Wallet.py --- neo/Prompt/Commands/Wallet.py | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/neo/Prompt/Commands/Wallet.py b/neo/Prompt/Commands/Wallet.py index f66009fc0..88a8747a5 100644 --- a/neo/Prompt/Commands/Wallet.py +++ b/neo/Prompt/Commands/Wallet.py @@ -31,9 +31,14 @@ def __init__(self): super().__init__() self.register_sub_command(CommandWalletCreate()) + self.register_sub_command(CommandWalletOpen()) + self.register_sub_command(CommandWalletClose()) self.register_sub_command(CommandWalletVerbose(), ['v', '--v']) self.register_sub_command(CommandWalletMigrate()) self.register_sub_command(CommandWalletCreateAddress()) + self.register_sub_command(CommandWalletSend()) + self.register_sub_command(CommandWalletSendMany()) + self.register_sub_command(CommandWalletSign()) def command_desc(self): return CommandDesc('wallet', 'manage wallets') @@ -42,19 +47,11 @@ def execute(self, arguments): wallet = PromptData.Wallet item = get_arg(arguments) - # Create, Open, and Close must be handled specially. - if item == 'create': + # Create and Open must be handled specially. + if item in {'create', 'open'}: self.execute_sub_command(item, arguments[1:]) return - elif item == 'open': - self.execute_sub_command(item, arguments[1:]) - return - - elif item == 'close': - self.execute_sub_command(item) - return - if not wallet: print("Please open a wallet") return @@ -64,7 +61,10 @@ def execute(self, arguments): return try: - self.execute_sub_command(item, arguments[1:]) + if len(arguments) > 1: + self.execute_sub_command(item, arguments[1:]) + else: + self.execute_sub_command(item) except KeyError: print(f"Wallet: {item} is an invalid parameter") @@ -75,6 +75,8 @@ def __init__(self): super().__init__() def execute(self, arguments): + if PromptData.Wallet: + CommandWalletClose().execute() path = get_arg(arguments, 0) if path: @@ -125,7 +127,7 @@ def __init__(self): def execute(self, arguments): if PromptData.Wallet: - CommandWalletClose.execute() + CommandWalletClose().execute() path = get_arg(arguments, 0) @@ -160,8 +162,7 @@ class CommandWalletClose(CommandBase): def __init__(self): super().__init__() - @classmethod - def execute(cls): + def execute(self): if PromptData.Wallet: path = PromptData.Wallet._path PromptData.Prompt.stop_wallet_loop() @@ -178,7 +179,7 @@ class CommandWalletVerbose(CommandBase): def __init__(self): super().__init__() - def execute(self, arguments): + def execute(self): print("Wallet %s " % json.dumps(PromptData.Wallet.ToJson(verbose=True), indent=4)) def command_desc(self): From 01076dc20c50b17ce72fc0335f2ea6b8017ce527 Mon Sep 17 00:00:00 2001 From: jseagrave21 <40873301+jseagrave21@users.noreply.github.com> Date: Tue, 27 Nov 2018 01:45:09 -0800 Subject: [PATCH 17/35] Update CommandBase.py - add functionality for subcommands without arguments --- neo/Prompt/CommandBase.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/neo/Prompt/CommandBase.py b/neo/Prompt/CommandBase.py index cc7164970..95776813a 100644 --- a/neo/Prompt/CommandBase.py +++ b/neo/Prompt/CommandBase.py @@ -65,8 +65,11 @@ def execute(self, arguments): def command_desc(self): pass - def execute_sub_command(self, id, arguments): - self.__sub_commands[id].execute(arguments) + def execute_sub_command(self, id, arguments=None): + if arguments is not None: + self.__sub_commands[id].execute(arguments) + else: + self.__sub_commands[id].execute() def register_sub_command(self, sub_command, additional_ids=[]): """ From 38e77fbb7bd202474f7753c98787b092c61377bb Mon Sep 17 00:00:00 2001 From: jseagrave21 <40873301+jseagrave21@users.noreply.github.com> Date: Tue, 27 Nov 2018 01:59:21 -0800 Subject: [PATCH 18/35] Update CommandBase.py - re-add comment --- neo/Prompt/CommandBase.py | 1 + 1 file changed, 1 insertion(+) diff --git a/neo/Prompt/CommandBase.py b/neo/Prompt/CommandBase.py index 95776813a..b956654ba 100644 --- a/neo/Prompt/CommandBase.py +++ b/neo/Prompt/CommandBase.py @@ -65,6 +65,7 @@ def execute(self, arguments): def command_desc(self): pass + # Raise KeyError exception if the command does not exist def execute_sub_command(self, id, arguments=None): if arguments is not None: self.__sub_commands[id].execute(arguments) From 5d766ccb2fbc93cb54cc35803fa56977d645cef0 Mon Sep 17 00:00:00 2001 From: jseagrave21 <40873301+jseagrave21@users.noreply.github.com> Date: Tue, 27 Nov 2018 09:41:17 -0800 Subject: [PATCH 19/35] Update prompt.py - update CommandWalletClose --- neo/bin/prompt.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neo/bin/prompt.py b/neo/bin/prompt.py index b437771e0..95bef7f3f 100755 --- a/neo/bin/prompt.py +++ b/neo/bin/prompt.py @@ -226,7 +226,7 @@ def get_completer(self): def quit(self): print('Shutting down. This may take a bit...') self.go_on = False - CommandWalletClose().execute() + CommandWalletClose.execute() reactor.stop() def help(self): From 19442179c4de5983fd5e43f53b274d15b7741687 Mon Sep 17 00:00:00 2001 From: jseagrave21 <40873301+jseagrave21@users.noreply.github.com> Date: Tue, 27 Nov 2018 09:43:11 -0800 Subject: [PATCH 20/35] Update Wallet.py - make CommandWalletClose.execute a classmethod to avoid having to instantiate it - update per @LysanderGG's comments --- neo/Prompt/Commands/Wallet.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/neo/Prompt/Commands/Wallet.py b/neo/Prompt/Commands/Wallet.py index 88a8747a5..8ca9e235d 100644 --- a/neo/Prompt/Commands/Wallet.py +++ b/neo/Prompt/Commands/Wallet.py @@ -61,10 +61,7 @@ def execute(self, arguments): return try: - if len(arguments) > 1: - self.execute_sub_command(item, arguments[1:]) - else: - self.execute_sub_command(item) + self.execute_sub_command(item, arguments[1:]) except KeyError: print(f"Wallet: {item} is an invalid parameter") @@ -76,7 +73,7 @@ def __init__(self): def execute(self, arguments): if PromptData.Wallet: - CommandWalletClose().execute() + CommandWalletClose.execute() path = get_arg(arguments, 0) if path: @@ -127,7 +124,7 @@ def __init__(self): def execute(self, arguments): if PromptData.Wallet: - CommandWalletClose().execute() + CommandWalletClose.execute() path = get_arg(arguments, 0) @@ -162,7 +159,8 @@ class CommandWalletClose(CommandBase): def __init__(self): super().__init__() - def execute(self): + @classmethod + def execute(cls, arguments=None): if PromptData.Wallet: path = PromptData.Wallet._path PromptData.Prompt.stop_wallet_loop() @@ -179,7 +177,7 @@ class CommandWalletVerbose(CommandBase): def __init__(self): super().__init__() - def execute(self): + def execute(self, arguments): print("Wallet %s " % json.dumps(PromptData.Wallet.ToJson(verbose=True), indent=4)) def command_desc(self): From 1a390d2c53e54b490d7a4634e22de5fb5445f516 Mon Sep 17 00:00:00 2001 From: jseagrave21 <40873301+jseagrave21@users.noreply.github.com> Date: Tue, 27 Nov 2018 09:44:16 -0800 Subject: [PATCH 21/35] Update CommandBase.py - update per @LysanderGG's comments --- neo/Prompt/CommandBase.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/neo/Prompt/CommandBase.py b/neo/Prompt/CommandBase.py index b956654ba..b4dbce1c3 100644 --- a/neo/Prompt/CommandBase.py +++ b/neo/Prompt/CommandBase.py @@ -66,11 +66,8 @@ def command_desc(self): pass # Raise KeyError exception if the command does not exist - def execute_sub_command(self, id, arguments=None): - if arguments is not None: - self.__sub_commands[id].execute(arguments) - else: - self.__sub_commands[id].execute() + def execute_sub_command(self, id, arguments): + self.__sub_commands[id].execute(arguments) def register_sub_command(self, sub_command, additional_ids=[]): """ From 6755c6ad8573a2883d9c2b0ff55547f96e3e5e96 Mon Sep 17 00:00:00 2001 From: jseagrave21 <40873301+jseagrave21@users.noreply.github.com> Date: Tue, 27 Nov 2018 11:24:17 -0800 Subject: [PATCH 22/35] Update Send.py - return values for testing --- neo/Prompt/Commands/Send.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/neo/Prompt/Commands/Send.py b/neo/Prompt/Commands/Send.py index c6d6c00ee..1695bb2bb 100755 --- a/neo/Prompt/Commands/Send.py +++ b/neo/Prompt/Commands/Send.py @@ -26,7 +26,9 @@ def __init__(self): def execute(self, arguments): framework = construct_send_basic(PromptData.Wallet, arguments) if type(framework) is list: - process_transaction(PromptData.Wallet, contract_tx=framework[0], scripthash_from=framework[1], fee=framework[2], owners=framework[3], user_tx_attributes=framework[4]) + return process_transaction(PromptData.Wallet, contract_tx=framework[0], scripthash_from=framework[1], + fee=framework[2], owners=framework[3], user_tx_attributes=framework[4]) + return framework def command_desc(self): p1 = ParameterDesc('assetId or name', 'the asset you wish to send') @@ -48,7 +50,9 @@ def __init__(self): def execute(self, arguments): framework = construct_send_many(PromptData.Wallet, arguments) if type(framework) is list: - process_transaction(PromptData.Wallet, contract_tx=framework[0], scripthash_from=framework[1], scripthash_change=framework[2], fee=framework[3], owners=framework[4], user_tx_attributes=framework[5]) + return process_transaction(PromptData.Wallet, contract_tx=framework[0], scripthash_from=framework[1], scripthash_change=framework[2], + fee=framework[3], owners=framework[4], user_tx_attributes=framework[5]) + return framework def command_desc(self): p1 = ParameterDesc('number of outgoing tx', 'the number of tx you wish to send') @@ -68,7 +72,7 @@ def __init__(self): def execute(self, arguments): jsn = get_arg(arguments) - parse_and_sign(PromptData.Wallet, jsn) + return parse_and_sign(PromptData.Wallet, jsn) def command_desc(self): p1 = ParameterDesc('jsn', 'transaction in JSON format') @@ -109,7 +113,8 @@ def construct_send_basic(wallet, arguments): # if this is a token, we will use a different # transfer mechanism if type(assetId) is NEP5Token: - return do_token_transfer(assetId, wallet, from_address, address_to, amount_from_string(assetId, amount), tx_attributes=user_tx_attributes) + return do_token_transfer(assetId, wallet, from_address, address_to, amount_from_string(assetId, amount), + tx_attributes=user_tx_attributes) f8amount = get_asset_amount(amount, assetId) if f8amount is False: From 809faab0eaaceb9ef4a122b1db574a4d32a3d89a Mon Sep 17 00:00:00 2001 From: jseagrave21 <40873301+jseagrave21@users.noreply.github.com> Date: Tue, 27 Nov 2018 11:25:16 -0800 Subject: [PATCH 23/35] Update test_send_command.py - refactor tests --- .../Commands/tests/test_send_command.py | 364 +++++++++--------- 1 file changed, 174 insertions(+), 190 deletions(-) diff --git a/neo/Prompt/Commands/tests/test_send_command.py b/neo/Prompt/Commands/tests/test_send_command.py index 59b3e1274..cdab89b38 100644 --- a/neo/Prompt/Commands/tests/test_send_command.py +++ b/neo/Prompt/Commands/tests/test_send_command.py @@ -7,6 +7,7 @@ from neo.Prompt.Commands.Wallet import ImportToken from neo.Prompt.Utils import get_tx_attr_from_args from neo.Prompt.Commands import Send, Wallet +from neo.Prompt.PromptData import PromptData import shutil from mock import MagicMock, patch import json @@ -38,35 +39,34 @@ def GetWallet1(cls, recreate=False): to_aes_key(UserWalletTestCase.wallet_1_pass())) return cls._wallet1 + @classmethod + def tearDown(cls): + PromptData.Wallet = None + def test_send_neo(self): - wallet = self.GetWallet1(recreate=True) - with patch('neo.Prompt.PromptData.PromptData.Wallet', return_value=wallet): - with patch('neo.Prompt.Commands.Send.prompt', side_effect=[UserWalletTestCase.wallet_1_pass()]): - with patch('sys.stdout', new=StringIO()) as mock_print: - args = ['send', 'neo', self.watch_addr_str, '50'] - command_wallet = Wallet.CommandWallet() - command_wallet.execute(args) + with patch('neo.Prompt.Commands.Send.prompt', side_effect=[UserWalletTestCase.wallet_1_pass()]): + PromptData.Wallet = self.GetWallet1(recreate=True) + args = ['send', 'neo', self.watch_addr_str, '50'] + + res = Wallet.CommandWallet().execute(args) - self.assertIn("Relayed Tx", mock_print.getvalue()) + self.assertTrue(res) def test_send_gas(self): - wallet = self.GetWallet1(recreate=True) - with patch('neo.Prompt.PromptData.PromptData.Wallet', return_value=wallet): - with patch('neo.Prompt.Commands.Send.prompt', side_effect=[UserWalletTestCase.wallet_1_pass()]): - with patch('sys.stdout', new=StringIO()) as mock_print: - args = ['send', 'gas', self.watch_addr_str, '5'] - command_wallet = Wallet.CommandWallet() - command_wallet.execute(args) + with patch('neo.Prompt.Commands.Send.prompt', side_effect=[UserWalletTestCase.wallet_1_pass()]): + PromptData.Wallet = self.GetWallet1(recreate=True) + args = ['send', 'gas', self.watch_addr_str, '5'] - self.assertIn("Relayed Tx", mock_print.getvalue()) + res = Wallet.CommandWallet().execute(args) + + self.assertTrue(res) def test_send_with_fee_and_from_addr(self): with patch('neo.Prompt.Commands.Send.prompt', side_effect=[UserWalletTestCase.wallet_1_pass()]): - wallet = self.GetWallet1(recreate=True) - args = ['neo', self.watch_addr_str, '1', '--from-addr=AJQ6FoaSXDFzA6wLnyZ1nFN7SGSN2oNTc3', '--fee=0.005'] + PromptData.Wallet = self.GetWallet1(recreate=True) + args = ['send', 'neo', self.watch_addr_str, '1', '--from-addr=AJQ6FoaSXDFzA6wLnyZ1nFN7SGSN2oNTc3', '--fee=0.005'] - framework = construct_send_basic(wallet, args) - res = process_transaction(wallet, contract_tx=framework[0], scripthash_from=framework[1], fee=framework[2], owners=framework[3], user_tx_attributes=framework[4]) + res = Wallet.CommandWallet().execute(args) self.assertTrue(res) # verify successful tx @@ -78,190 +78,184 @@ def test_send_with_fee_and_from_addr(self): def test_send_no_wallet(self): with patch('sys.stdout', new=StringIO()) as mock_print: args = ["send", "neo", self.wallet_1_addr, '5'] - command_wallet = Wallet.CommandWallet() - command_wallet.execute(args) + + Wallet.CommandWallet().execute(args) self.assertIn("Please open a wallet", mock_print.getvalue()) def test_send_bad_args(self): - wallet = self.GetWallet1(recreate=True) - args = ['neo', self.watch_addr_str] # too few args + PromptData.Wallet = self.GetWallet1(recreate=True) + args = ['send', 'neo', self.watch_addr_str] # too few args - framework = construct_send_basic(wallet, args) + res = Wallet.CommandWallet().execute(args) - self.assertFalse(framework) + self.assertFalse(res) def test_send_bad_assetid(self): - wallet = self.GetWallet1(recreate=True) - args = ['blah', self.watch_addr_str, '12'] + PromptData.Wallet = self.GetWallet1(recreate=True) + args = ['send', 'blah', self.watch_addr_str, '12'] - framework = construct_send_basic(wallet, args) + res = Wallet.CommandWallet().execute(args) - self.assertFalse(framework) + self.assertFalse(res) def test_send_bad_address_to(self): - wallet = self.GetWallet1(recreate=True) + PromptData.Wallet = self.GetWallet1(recreate=True) address_to = 'AGYaEi3W6ndHPUmW7T12FFfsbQ6DWymkE' # address_to is too short causing ToScriptHash to fail - args = ['neo', address_to, '12'] + args = ['send', 'neo', address_to, '12'] - framework = construct_send_basic(wallet, args) + res = Wallet.CommandWallet().execute(args) - self.assertFalse(framework) + self.assertFalse(res) def test_send_bad_address_from(self): - wallet = self.GetWallet1(recreate=True) + PromptData.Wallet = self.GetWallet1(recreate=True) address_from = '--from-addr=AJQ6FoaSXDFzA6wLnyZ1nFN7SGSN2oNTc' # address_from is too short causing ToScriptHash to fail - args = ['neo', self.watch_addr_str, '12', address_from] + args = ['send', 'neo', self.watch_addr_str, '12', address_from] - framework = construct_send_basic(wallet, args) + res = Wallet.CommandWallet().execute(args) - self.assertFalse(framework) + self.assertFalse(res) def test_send_negative_amount(self): - wallet = self.GetWallet1(recreate=True) - args = ['neo', self.watch_addr_str, '-12'] + PromptData.Wallet = self.GetWallet1(recreate=True) + args = ['send', 'neo', self.watch_addr_str, '-12'] - framework = construct_send_basic(wallet, args) + res = Wallet.CommandWallet().execute(args) - self.assertFalse(framework) + self.assertFalse(res) def test_send_zero_amount(self): - wallet = self.GetWallet1(recreate=True) - args = ['neo', self.watch_addr_str, '0'] + PromptData.Wallet = self.GetWallet1(recreate=True) + args = ['send', 'neo', self.watch_addr_str, '0'] - framework = construct_send_basic(wallet, args) + res = Wallet.CommandWallet().execute(args) - self.assertFalse(framework) + self.assertFalse(res) def test_send_weird_amount(self): - wallet = self.GetWallet1(recreate=True) - args = ['neo', self.watch_addr_str, '12.abc3'] + PromptData.Wallet = self.GetWallet1(recreate=True) + args = ['send', 'neo', self.watch_addr_str, '12.abc3'] - framework = construct_send_basic(wallet, args) + res = Wallet.CommandWallet().execute(args) - self.assertFalse(framework) + self.assertFalse(res) def test_send_bad_precision_amount(self): - wallet = self.GetWallet1(recreate=True) - args = ['neo', self.watch_addr_str, '12.01'] + PromptData.Wallet = self.GetWallet1(recreate=True) + args = ['send', 'neo', self.watch_addr_str, '12.01'] - framework = construct_send_basic(wallet, args) + res = Wallet.CommandWallet().execute(args) - self.assertFalse(framework) + self.assertFalse(res) def test_send_negative_fee(self): - wallet = self.GetWallet1(recreate=True) - args = ['neo', self.watch_addr_str, '12', '--fee=-0.005'] + PromptData.Wallet = self.GetWallet1(recreate=True) + args = ['send', 'neo', self.watch_addr_str, '12', '--fee=-0.005'] - framework = construct_send_basic(wallet, args) + res = Wallet.CommandWallet().execute(args) - self.assertFalse(framework) + self.assertFalse(res) def test_send_weird_fee(self): - wallet = self.GetWallet1(recreate=True) - args = ['neo', self.watch_addr_str, '12', '--fee=0.0abc'] + PromptData.Wallet = self.GetWallet1(recreate=True) + args = ['send', 'neo', self.watch_addr_str, '12', '--fee=0.0abc'] - framework = construct_send_basic(wallet, args) + res = Wallet.CommandWallet().execute(args) - self.assertFalse(framework) + self.assertFalse(res) def test_send_token_bad(self): - wallet = self.GetWallet1(recreate=True) + PromptData.Wallet = self.GetWallet1(recreate=True) token_hash = 'f8d448b227991cf07cb96a6f9c0322437f1599b9' - ImportToken(wallet, token_hash) + ImportToken(PromptData.Wallet, token_hash) - args = ['NEP5', self.watch_addr_str, '32'] + args = ['send', 'NEP5', self.watch_addr_str, '32'] - framework = construct_send_basic(wallet, args) + res = Wallet.CommandWallet().execute(args) - self.assertFalse(framework) + self.assertFalse(res) def test_send_token_ok(self): with patch('neo.Prompt.Commands.Tokens.prompt', side_effect=[UserWalletTestCase.wallet_1_pass()]): - wallet = self.GetWallet1(recreate=True) + PromptData.Wallet = self.GetWallet1(recreate=True) token_hash = '31730cc9a1844891a3bafd1aa929a4142860d8d3' - ImportToken(wallet, token_hash) + ImportToken(PromptData.Wallet, token_hash) - args = ['NXT4', self.watch_addr_str, '30', '--from-addr=%s' % self.wallet_1_addr] + args = ['send', 'NXT4', self.watch_addr_str, '30', '--from-addr=%s' % self.wallet_1_addr] - framework = construct_send_basic(wallet, args) + res = Wallet.CommandWallet().execute(args) - self.assertTrue(framework) + self.assertTrue(res) def test_insufficient_funds(self): - wallet = self.GetWallet1(recreate=True) - args = ['gas', self.watch_addr_str, '72620'] + PromptData.Wallet = self.GetWallet1(recreate=True) + args = ['send', 'gas', self.watch_addr_str, '72620'] - framework = construct_send_basic(wallet, args) - res = process_transaction(wallet, contract_tx=framework[0], scripthash_from=framework[1], fee=framework[2], owners=framework[3], user_tx_attributes=framework[4]) + res = Wallet.CommandWallet().execute(args) self.assertFalse(res) def test_bad_password(self): with patch('neo.Prompt.Commands.Send.prompt', side_effect=['blah']): - wallet = self.GetWallet1(recreate=True) - args = ['neo', self.watch_addr_str, '50'] + PromptData.Wallet = self.GetWallet1(recreate=True) + args = ['send', 'neo', self.watch_addr_str, '50'] - framework = construct_send_basic(wallet, args) - res = process_transaction(wallet, contract_tx=framework[0], scripthash_from=framework[1], fee=framework[2], owners=framework[3], user_tx_attributes=framework[4]) + res = Wallet.CommandWallet().execute(args) self.assertFalse(res) @patch.object(Send, 'gather_signatures') def test_owners(self, mock): with patch('neo.Prompt.Commands.Send.prompt', side_effect=[UserWalletTestCase.wallet_1_pass()]): - wallet = self.GetWallet1(recreate=True) + PromptData.Wallet = self.GetWallet1(recreate=True) - args = ['gas', self.wallet_1_addr, '2', "--owners=['AXjaFSP23Jkbe6Pk9pPGT6NBDs1HVdqaXK','APRgMZHZubii29UXF9uFa6sohrsYupNAvx']"] + args = ['send', 'gas', self.wallet_1_addr, '2', "--owners=['AXjaFSP23Jkbe6Pk9pPGT6NBDs1HVdqaXK','APRgMZHZubii29UXF9uFa6sohrsYupNAvx']"] - framework = construct_send_basic(wallet, args) - process_transaction(wallet, contract_tx=framework[0], scripthash_from=framework[1], fee=framework[2], owners=framework[3], user_tx_attributes=framework[4]) + Wallet.CommandWallet().execute(args) self.assertTrue(mock.called) def test_attributes(self): with patch('neo.Prompt.Commands.Send.prompt', side_effect=[UserWalletTestCase.wallet_1_pass()]): - wallet = self.GetWallet1(recreate=True) - args = ['gas', self.watch_addr_str, '2', '--tx-attr={"usage":241,"data":"This is a remark"}'] + PromptData.Wallet = self.GetWallet1(recreate=True) + args = ['send', 'gas', self.watch_addr_str, '2', '--tx-attr={"usage":241,"data":"This is a remark"}'] - framework = construct_send_basic(wallet, args) - res = process_transaction(wallet, contract_tx=framework[0], scripthash_from=framework[1], fee=framework[2], owners=framework[3], user_tx_attributes=framework[4]) + res = Wallet.CommandWallet().execute(args) self.assertTrue(res) self.assertEqual(2, len(res.Attributes)) # By default the script_hash of the transaction sender is added to the TransactionAttribute list, therefore the Attributes length is `count` + 1 def test_multiple_attributes(self): with patch('neo.Prompt.Commands.Send.prompt', side_effect=[UserWalletTestCase.wallet_1_pass()]): - wallet = self.GetWallet1(recreate=True) - args = ['gas', self.watch_addr_str, '2', '--tx-attr=[{"usage":241,"data":"This is a remark"},{"usage":242,"data":"This is a remark 2"}]'] + PromptData.Wallet = self.GetWallet1(recreate=True) + args = ['send', 'gas', self.watch_addr_str, '2', '--tx-attr=[{"usage":241,"data":"This is a remark"},{"usage":242,"data":"This is a remark 2"}]'] - framework = construct_send_basic(wallet, args) - res = process_transaction(wallet, contract_tx=framework[0], scripthash_from=framework[1], fee=framework[2], owners=framework[3], user_tx_attributes=framework[4]) + res = Wallet.CommandWallet().execute(args) self.assertTrue(res) self.assertEqual(3, len(res.Attributes)) def test_bad_attributes(self): with patch('neo.Prompt.Commands.Send.prompt', side_effect=[UserWalletTestCase.wallet_1_pass()]): - wallet = self.GetWallet1(recreate=True) - args = ['gas', self.watch_addr_str, '2', '--tx-attr=[{"usa:241"data":his is a remark"}]'] + PromptData.Wallet = self.GetWallet1(recreate=True) + args = ['send', 'gas', self.watch_addr_str, '2', '--tx-attr=[{"usa:241"data":his is a remark"}]'] - framework = construct_send_basic(wallet, args) - res = process_transaction(wallet, contract_tx=framework[0], scripthash_from=framework[1], fee=framework[2], owners=framework[3], user_tx_attributes=framework[4]) + res = Wallet.CommandWallet().execute(args) self.assertTrue(res) self.assertEqual(1, len(res.Attributes)) @@ -290,77 +284,67 @@ def test_utilst_bad_type(self): def test_fails_to_sign_tx(self): with patch('neo.Prompt.Commands.Send.prompt', side_effect=[UserWalletTestCase.wallet_1_pass()]): with patch('neo.Wallets.Wallet.Wallet.Sign', return_value=False): - wallet = self.GetWallet1(recreate=True) - args = ['gas', self.watch_addr_str, '2'] + PromptData.Wallet = self.GetWallet1(recreate=True) + args = ['send', 'gas', self.watch_addr_str, '2'] - framework = construct_send_basic(wallet, args) - res = process_transaction(wallet, contract_tx=framework[0], scripthash_from=framework[1], fee=framework[2], owners=framework[3], user_tx_attributes=framework[4]) + res = Wallet.CommandWallet().execute(args) self.assertFalse(res) def test_fails_to_relay_tx(self): with patch('neo.Prompt.Commands.Send.prompt', side_effect=[UserWalletTestCase.wallet_1_pass()]): with patch('neo.Prompt.Commands.Send.NodeLeader.Relay', return_value=False): - wallet = self.GetWallet1(recreate=True) - args = ['gas', self.watch_addr_str, '2'] + PromptData.Wallet = self.GetWallet1(recreate=True) + args = ['send', 'gas', self.watch_addr_str, '2'] - framework = construct_send_basic(wallet, args) - res = process_transaction(wallet, contract_tx=framework[0], scripthash_from=framework[1], fee=framework[2], owners=framework[3], user_tx_attributes=framework[4]) + res = Wallet.CommandWallet().execute(args) self.assertFalse(res) - @patch('neo.Prompt.Commands.Send.traceback') - def test_could_not_send(self, mocked_tracback_module): + def test_could_not_send(self): # mocking traceback module to avoid stacktrace printing during test run + with patch('neo.Prompt.Commands.Send.traceback'): + PromptData.Wallet = self.GetWallet1(recreate=True) + args = ['send', 'gas', self.watch_addr_str, '2'] - wallet = self.GetWallet1(recreate=True) - args = ['gas', self.watch_addr_str, '2'] - - contract_tx, scripthash_from, fee, owners, user_tx_attributes = construct_send_basic(wallet, args) - scripthash_change = scripthash_from - # mocking wallet to trigger the exception - wallet = MagicMock() - wallet.MakeTransaction.side_effect = Exception - res = process_transaction(wallet, contract_tx, scripthash_from, scripthash_change, fee, owners, user_tx_attributes) # forces the 'try:' to fail + with patch('neo.Wallets.Wallet.Wallet.MakeTransaction', side_effect=[Exception]): + res = Wallet.CommandWallet().execute(args) - self.assertFalse(res) + self.assertFalse(res) def test_sendmany_good_simple(self): - wallet = self.GetWallet1(recreate=True) - with patch('neo.Prompt.PromptData.PromptData.Wallet', return_value=wallet): - with patch('neo.Prompt.Commands.Send.prompt', side_effect=["neo", self.watch_addr_str, "1", "gas", self.watch_addr_str, "1", UserWalletTestCase.wallet_1_pass()]): - with patch('sys.stdout', new=StringIO()) as mock_print: - args = ['sendmany', '2'] - command_wallet = Wallet.CommandWallet() - command_wallet.execute(args) + with patch('neo.Prompt.Commands.Send.prompt', side_effect=["neo", self.watch_addr_str, "1", "gas", self.watch_addr_str, "1", UserWalletTestCase.wallet_1_pass()]): + PromptData.Wallet = self.GetWallet1(recreate=True) + args = ['sendmany', '2'] + + res = Wallet.CommandWallet().execute(args) - self.assertIn("Relayed Tx", mock_print.getvalue()) + self.assertTrue(res) # verify successful tx + json_res = res.ToJson() + + # check for 2 transfers + transfers = 0 + for info in json_res['vout']: + if info['address'] == self.watch_addr_str: + transfers += 1 + self.assertEqual(2, transfers) def test_sendmany_good_complex(self): with patch('neo.Prompt.Commands.Send.prompt', side_effect=["neo", "AXjaFSP23Jkbe6Pk9pPGT6NBDs1HVdqaXK", "1", "gas", "AXjaFSP23Jkbe6Pk9pPGT6NBDs1HVdqaXK", "1", UserWalletTestCase.wallet_1_pass()]): - wallet = self.GetWallet1(recreate=True) - args = ["2", '--from-addr=%s' % self.wallet_1_addr, '--change-addr=%s' % self.watch_addr_str, '--fee=0.005'] + PromptData.Wallet = self.GetWallet1(recreate=True) + args = ['sendmany', '2', '--from-addr=%s' % self.wallet_1_addr, '--change-addr=%s' % self.watch_addr_str, '--fee=0.005'] address_from_account_state = Blockchain.Default().GetAccountState(self.wallet_1_addr).ToJson() address_from_gas = next(filter(lambda b: b['asset'] == '0x602c79718b16e442de58778e148d0b1084e3b2dffd5de6b7b16cee7969282de7', address_from_account_state['balances'])) address_from_gas_bal = address_from_gas['value'] - framework = construct_send_many(wallet, args) - res = process_transaction(wallet, contract_tx=framework[0], scripthash_from=framework[1], scripthash_change=framework[2], fee=framework[3], owners=framework[4], user_tx_attributes=framework[5]) + res = Wallet.CommandWallet().execute(args) self.assertTrue(res) # verify successful tx json_res = res.ToJson() self.assertEqual("AXjaFSP23Jkbe6Pk9pPGT6NBDs1HVdqaXK", json_res['vout'][0]['address']) # verify correct address_to - - # check for 2 transfers - transfers = 0 - for info in json_res['vout']: - if info['address'] == self.watch_addr_str: - transfers += 1 - self.assertEqual(2, transfers) - self.assertEqual(self.watch_addr_str, json_res['vout'][2]['address']) # verify correct change address self.assertEqual(float(address_from_gas_bal) - 1 - 0.005, float(json_res['vout'][3]['value'])) self.assertEqual('0.005', json_res['net_fee']) @@ -368,131 +352,131 @@ def test_sendmany_good_complex(self): def test_sendmany_no_wallet(self): with patch('sys.stdout', new=StringIO()) as mock_print: args = ['sendmany', '2'] - command_wallet = Wallet.CommandWallet() - command_wallet.execute(args) + + Wallet.CommandWallet().execute(args) self.assertIn("Please open a wallet", mock_print.getvalue()) def test_sendmany_bad_args(self): - wallet = self.GetWallet1(recreate=True) - args = [] # too few args + PromptData.Wallet = self.GetWallet1(recreate=True) + args = ['sendmany'] # too few args - framework = construct_send_many(wallet, args) + res = Wallet.CommandWallet().execute(args) - self.assertFalse(framework) + self.assertFalse(res) def test_sendmany_bad_outgoing(self): - wallet = self.GetWallet1(recreate=True) - args = ['0'] # too few outgoing + PromptData.Wallet = self.GetWallet1(recreate=True) + args = ['sendmany', '0'] # too few outgoing - framework = construct_send_many(wallet, args) + res = Wallet.CommandWallet().execute(args) - self.assertFalse(framework) + self.assertFalse(res) def test_sendmany_weird_outgoing(self): - wallet = self.GetWallet1(recreate=True) - args = ['0.5'] # weird number outgoing + PromptData.Wallet = self.GetWallet1(recreate=True) + args = ['sendmany', '0.5'] # weird number outgoing - framework = construct_send_many(wallet, args) + res = Wallet.CommandWallet().execute(args) - self.assertFalse(framework) + self.assertFalse(res) def test_sendmany_bad_assetid(self): with patch('neo.Prompt.Commands.Send.prompt', side_effect=["neo", self.watch_addr_str, "1", "blah", self.watch_addr_str, "1"]): - wallet = self.GetWallet1(recreate=True) - args = ['2'] + PromptData.Wallet = self.GetWallet1(recreate=True) + args = ['sendmany', '2'] - framework = construct_send_many(wallet, args) + res = Wallet.CommandWallet().execute(args) - self.assertFalse(framework) + self.assertFalse(res) def test_sendmany_token(self): with patch('neo.Prompt.Commands.Send.prompt', side_effect=["neo", self.watch_addr_str, "1", "NXT4", self.watch_addr_str, "32"]): - wallet = self.GetWallet1(recreate=True) + PromptData.Wallet = self.GetWallet1(recreate=True) token_hash = '31730cc9a1844891a3bafd1aa929a4142860d8d3' - ImportToken(wallet, token_hash) + ImportToken(PromptData.Wallet, token_hash) args = ["2", '--from-addr=%s' % self.wallet_1_addr] - framework = construct_send_many(wallet, args) + res = Wallet.CommandWallet().execute(args) - self.assertFalse(framework) + self.assertFalse(res) def test_sendmany_bad_address_to(self): with patch('neo.Prompt.Commands.Send.prompt', side_effect=["neo", self.watch_addr_str, "1", "gas", "AGYaEi3W6ndHPUmW7T12FFfsbQ6DWymkE", "1"]): # address is too short - wallet = self.GetWallet1(recreate=True) - args = ['2'] + PromptData.Wallet = self.GetWallet1(recreate=True) + args = ['sendmany' '2'] - framework = construct_send_many(wallet, args) + res = Wallet.CommandWallet().execute(args) - self.assertFalse(framework) + self.assertFalse(res) def test_sendmany_negative_amount(self): with patch('neo.Prompt.Commands.Send.prompt', side_effect=["neo", self.watch_addr_str, "1", "gas", self.watch_addr_str, "-1"]): - wallet = self.GetWallet1(recreate=True) - args = ['2'] + PromptData.Wallet = self.GetWallet1(recreate=True) + args = ['sendmany', '2'] - framework = construct_send_many(wallet, args) + res = Wallet.CommandWallet().execute(args) - self.assertFalse(framework) + self.assertFalse(res) def test_sendmany_zero_amount(self): with patch('neo.Prompt.Commands.Send.prompt', side_effect=["neo", self.watch_addr_str, "1", "gas", self.watch_addr_str, "0"]): - wallet = self.GetWallet1(recreate=True) - args = ['2'] + PromptData.Wallet = self.GetWallet1(recreate=True) + args = ['sendmany', '2'] - framework = construct_send_many(wallet, args) + res = Wallet.CommandWallet().execute(args) - self.assertFalse(framework) + self.assertFalse(res) def test_sendmany_weird_amount(self): with patch('neo.Prompt.Commands.Send.prompt', side_effect=["neo", self.watch_addr_str, "1", "gas", self.watch_addr_str, "5.abc3"]): - wallet = self.GetWallet1(recreate=True) - args = ['2'] + PromptData.Wallet = self.GetWallet1(recreate=True) + args = ['sendmany', '2'] - framework = construct_send_many(wallet, args) + res = Wallet.CommandWallet().execute(args) - self.assertFalse(framework) + self.assertFalse(res) def test_sendmany_bad_precision_amount(self): with patch('neo.Prompt.Commands.Send.prompt', side_effect=["gas", self.watch_addr_str, "1", "neo", self.watch_addr_str, "5.01"]): - wallet = self.GetWallet1(recreate=True) - args = ['2'] + PromptData.Wallet = self.GetWallet1(recreate=True) + args = ['sendmany', '2'] - framework = construct_send_many(wallet, args) + res = Wallet.CommandWallet().execute(args) - self.assertFalse(framework) + self.assertFalse(res) def test_sendmany_bad_address_from(self): with patch('neo.Prompt.Commands.Send.prompt', side_effect=["neo", self.watch_addr_str, "1", "gas", self.watch_addr_str, "1"]): - wallet = self.GetWallet1(recreate=True) + PromptData.Wallet = self.GetWallet1(recreate=True) address_from = '--from-addr=AJQ6FoaSXDFzA6wLnyZ1nFN7SGSN2oNTc' # address_from is too short causing ToScriptHash to fail - args = ['2', address_from] + args = ['sendmany', '2', address_from] - framework = construct_send_many(wallet, args) + res = Wallet.CommandWallet().execute(args) - self.assertFalse(framework) + self.assertFalse(res) def test_sendmany_bad_change_address(self): with patch('neo.Prompt.Commands.Send.prompt', side_effect=["neo", self.watch_addr_str, "1", "gas", self.watch_addr_str, "1"]): - wallet = self.GetWallet1(recreate=True) + PromptData.Wallet = self.GetWallet1(recreate=True) change_address = '--change-addr=AGYaEi3W6ndHPUmW7T12FFfsbQ6DWymkE' # change address is too short causing ToScriptHash to fail - args = ['2', change_address] + args = ['sendmany', '2', change_address] - framework = construct_send_many(wallet, args) + res = Wallet.CommandWallet().execute(args) - self.assertFalse(framework) + self.assertFalse(res) def test_sendmany_negative_fee(self): with patch('neo.Prompt.Commands.Send.prompt', side_effect=["neo", self.watch_addr_str, "1", "gas", self.watch_addr_str, "1"]): - wallet = self.GetWallet1(recreate=True) - args = ['2', '--fee=-0.005'] + PromptData.Wallet = self.GetWallet1(recreate=True) + args = ['sendmany', '2', '--fee=-0.005'] - framework = construct_send_many(wallet, args) + res = Wallet.CommandWallet().execute(args) - self.assertFalse(framework) + self.assertFalse(res) From 9f2d7f1e3505b67b5ef605a31af32d1a9c958fb1 Mon Sep 17 00:00:00 2001 From: jseagrave21 <40873301+jseagrave21@users.noreply.github.com> Date: Tue, 27 Nov 2018 11:26:29 -0800 Subject: [PATCH 24/35] Update Wallet.py - update returns --- neo/Prompt/Commands/Wallet.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/neo/Prompt/Commands/Wallet.py b/neo/Prompt/Commands/Wallet.py index 8ca9e235d..81f190e42 100644 --- a/neo/Prompt/Commands/Wallet.py +++ b/neo/Prompt/Commands/Wallet.py @@ -61,9 +61,10 @@ def execute(self, arguments): return try: - self.execute_sub_command(item, arguments[1:]) + return self.execute_sub_command(item, arguments[1:]) except KeyError: print(f"Wallet: {item} is an invalid parameter") + return class CommandWalletCreate(CommandBase): @@ -96,6 +97,7 @@ def execute(self, arguments): key = PromptData.Wallet.GetKey(contract.PublicKeyHash) print("Wallet %s" % json.dumps(PromptData.Wallet.ToJson(), indent=4)) print("Pubkey %s" % key.PublicKey.encode_point(True)) + return PromptData.Wallet except Exception as e: print("Exception creating wallet: %s" % e) PromptData.Wallet = None @@ -108,9 +110,11 @@ def execute(self, arguments): if PromptData.Wallet: PromptData.Prompt.start_wallet_loop() + return else: print("Please specify a path") + return def command_desc(self): p1 = ParameterDesc('path', 'path to store the wallet file') @@ -145,9 +149,11 @@ def execute(self, arguments): return PromptData.Wallet except Exception as e: print("Could not open wallet: %s" % e) + return else: print("Please specify a path") + return def command_desc(self): p1 = ParameterDesc('path', 'path to open the wallet file') @@ -167,6 +173,8 @@ def execute(cls, arguments=None): PromptData.Wallet.Close() PromptData.Wallet = None print("Closed wallet %s" % path) + return True + return False def command_desc(self): return CommandDesc('close', 'closes the open NEO wallet') @@ -179,6 +187,7 @@ def __init__(self): def execute(self, arguments): print("Wallet %s " % json.dumps(PromptData.Wallet.ToJson(verbose=True), indent=4)) + return True def command_desc(self): return CommandDesc('verbose', 'show additional wallet details') @@ -193,6 +202,8 @@ def execute(self, arguments): if PromptData.Wallet is not None: PromptData.Wallet.Migrate() print("Migrated wallet") + return True + return False def command_desc(self): p1 = ParameterDesc('option1', 'description of params 1') @@ -209,7 +220,7 @@ def __init__(self): def execute(self, arguments): addresses_to_create = get_arg(arguments, 0) - CreateAddress(PromptData.Wallet, addresses_to_create) + return CreateAddress(PromptData.Wallet, addresses_to_create) def command_desc(self): return CommandDesc('create_addr', 'create a wallet address') From 18d5ec02ec672bda4b4963dd889cd127bfc20354 Mon Sep 17 00:00:00 2001 From: jseagrave21 <40873301+jseagrave21@users.noreply.github.com> Date: Tue, 27 Nov 2018 11:27:01 -0800 Subject: [PATCH 25/35] Update CommandBase.py - update to support returned data --- neo/Prompt/CommandBase.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neo/Prompt/CommandBase.py b/neo/Prompt/CommandBase.py index b4dbce1c3..8cf8c1d09 100644 --- a/neo/Prompt/CommandBase.py +++ b/neo/Prompt/CommandBase.py @@ -67,7 +67,7 @@ def command_desc(self): # Raise KeyError exception if the command does not exist def execute_sub_command(self, id, arguments): - self.__sub_commands[id].execute(arguments) + return self.__sub_commands[id].execute(arguments) def register_sub_command(self, sub_command, additional_ids=[]): """ From 72bf6cb05d99363dc53a34c498b66647e0d031ba Mon Sep 17 00:00:00 2001 From: jseagrave21 <40873301+jseagrave21@users.noreply.github.com> Date: Tue, 27 Nov 2018 11:30:45 -0800 Subject: [PATCH 26/35] Update test_send_command.py - remove redundant imports --- neo/Prompt/Commands/tests/test_send_command.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/neo/Prompt/Commands/tests/test_send_command.py b/neo/Prompt/Commands/tests/test_send_command.py index cdab89b38..0cae6b572 100644 --- a/neo/Prompt/Commands/tests/test_send_command.py +++ b/neo/Prompt/Commands/tests/test_send_command.py @@ -3,13 +3,12 @@ from neo.Implementations.Wallets.peewee.UserWallet import UserWallet from neo.Core.Blockchain import Blockchain from neocore.UInt160 import UInt160 -from neo.Prompt.Commands.Send import construct_send_basic, construct_send_many, process_transaction from neo.Prompt.Commands.Wallet import ImportToken from neo.Prompt.Utils import get_tx_attr_from_args from neo.Prompt.Commands import Send, Wallet from neo.Prompt.PromptData import PromptData import shutil -from mock import MagicMock, patch +from mock import patch import json from io import StringIO From b2958e6b7c0c47e5e333485028c541b0ca4d850e Mon Sep 17 00:00:00 2001 From: jseagrave21 <40873301+jseagrave21@users.noreply.github.com> Date: Tue, 27 Nov 2018 11:45:51 -0800 Subject: [PATCH 27/35] Update Wallet.py - return values from `create` and `open` --- neo/Prompt/Commands/Wallet.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/neo/Prompt/Commands/Wallet.py b/neo/Prompt/Commands/Wallet.py index 81f190e42..12c2e691b 100644 --- a/neo/Prompt/Commands/Wallet.py +++ b/neo/Prompt/Commands/Wallet.py @@ -49,8 +49,8 @@ def execute(self, arguments): # Create and Open must be handled specially. if item in {'create', 'open'}: - self.execute_sub_command(item, arguments[1:]) - return + return self.execute_sub_command(item, arguments[1:]) + if not wallet: print("Please open a wallet") From 6e1e95c47cf493c231ada25233aa1dced109f80f Mon Sep 17 00:00:00 2001 From: jseagrave21 <40873301+jseagrave21@users.noreply.github.com> Date: Tue, 27 Nov 2018 12:35:57 -0800 Subject: [PATCH 28/35] Update Wallet.py - update for `make lint` --- neo/Prompt/Commands/Wallet.py | 1 - 1 file changed, 1 deletion(-) diff --git a/neo/Prompt/Commands/Wallet.py b/neo/Prompt/Commands/Wallet.py index 12c2e691b..ea4df5863 100644 --- a/neo/Prompt/Commands/Wallet.py +++ b/neo/Prompt/Commands/Wallet.py @@ -50,7 +50,6 @@ def execute(self, arguments): # Create and Open must be handled specially. if item in {'create', 'open'}: return self.execute_sub_command(item, arguments[1:]) - if not wallet: print("Please open a wallet") From faaa972a4f70b588beefae3f8062fa530e654e7a Mon Sep 17 00:00:00 2001 From: jseagrave21 <40873301+jseagrave21@users.noreply.github.com> Date: Tue, 27 Nov 2018 12:37:00 -0800 Subject: [PATCH 29/35] Update test_wallet_commands.py - add tests for `wallet open` and `wallet close` --- .../Commands/tests/test_wallet_commands.py | 54 ++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/neo/Prompt/Commands/tests/test_wallet_commands.py b/neo/Prompt/Commands/tests/test_wallet_commands.py index c9ed30d19..b8627dac9 100644 --- a/neo/Prompt/Commands/tests/test_wallet_commands.py +++ b/neo/Prompt/Commands/tests/test_wallet_commands.py @@ -4,8 +4,9 @@ from neo.Core.Blockchain import Blockchain from neocore.UInt160 import UInt160 from neocore.Fixed8 import Fixed8 -from neo.Prompt.Commands.Wallet import CreateAddress, DeleteAddress, ImportToken, ImportWatchAddr, ShowUnspentCoins, SplitUnspentCoin +from neo.Prompt.Commands.Wallet import CommandWallet, CreateAddress, DeleteAddress, ImportToken, ImportWatchAddr, ShowUnspentCoins, SplitUnspentCoin import shutil +from mock import patch class UserWalletTestCase(WalletFixtureTestCase): @@ -33,6 +34,57 @@ def GetWallet1(cls, recreate=False): to_aes_key(UserWalletTestCase.wallet_1_pass())) return cls._wallet1 + # Beginning with refactored tests + + def test_wallet_open_and_close(self): + with patch('neo.Prompt.PromptData.PromptData.Prompt'): + # test wallet close with no wallet + args = ['close'] + + res = CommandWallet().execute(args) + + self.assertFalse(res) + + with patch('neo.Prompt.Commands.Wallet.prompt', side_effect=["testpassword"]): + # test wallet open successful + args = ['open', 'fixtures/testwallet.db3'] + + res = CommandWallet().execute(args) + + self.assertEqual(str(type(res)), "") + + # test wallet close with open wallet + args = ['close'] + + res = CommandWallet().execute(args) + + self.assertTrue(res) + + # test wallet open with no path + args = ['open'] + + res = CommandWallet().execute(args) + + self.assertFalse(res) + + # test wallet open with bad path + args = ['open', 'badpath'] + + res = CommandWallet().execute(args) + + self.assertFalse(res) + + # test wallet open unsuccessful + with patch('neo.Prompt.Commands.Wallet.prompt', side_effect=["testpassword"]): + with patch('neo.Implementations.Wallets.peewee.UserWallet.UserWallet.Open', side_effect=[Exception('test exception')]): + args = ['open', 'fixtures/testwallet.db3'] + + res = CommandWallet().execute(args) + + self.assertFalse(res) + + ########################################################## + ########################################################## def test_1_import_addr(self): wallet = self.GetWallet1(recreate=True) From 963baeeac09d62eaf60c4ca079abed8bae6e2d92 Mon Sep 17 00:00:00 2001 From: jseagrave21 <40873301+jseagrave21@users.noreply.github.com> Date: Tue, 27 Nov 2018 12:56:57 -0800 Subject: [PATCH 30/35] Update test_send_command.py - update bad tests --- neo/Prompt/Commands/tests/test_send_command.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/neo/Prompt/Commands/tests/test_send_command.py b/neo/Prompt/Commands/tests/test_send_command.py index 0cae6b572..0e1c349f4 100644 --- a/neo/Prompt/Commands/tests/test_send_command.py +++ b/neo/Prompt/Commands/tests/test_send_command.py @@ -399,7 +399,7 @@ def test_sendmany_token(self): token_hash = '31730cc9a1844891a3bafd1aa929a4142860d8d3' ImportToken(PromptData.Wallet, token_hash) - args = ["2", '--from-addr=%s' % self.wallet_1_addr] + args = ['sendmany', "2", '--from-addr=%s' % self.wallet_1_addr] res = Wallet.CommandWallet().execute(args) @@ -409,7 +409,7 @@ def test_sendmany_bad_address_to(self): with patch('neo.Prompt.Commands.Send.prompt', side_effect=["neo", self.watch_addr_str, "1", "gas", "AGYaEi3W6ndHPUmW7T12FFfsbQ6DWymkE", "1"]): # address is too short PromptData.Wallet = self.GetWallet1(recreate=True) - args = ['sendmany' '2'] + args = ['sendmany', '2'] res = Wallet.CommandWallet().execute(args) From f53f0a89af471bc43d56c2ff4d9517531522c99b Mon Sep 17 00:00:00 2001 From: jseagrave21 <40873301+jseagrave21@users.noreply.github.com> Date: Tue, 27 Nov 2018 13:11:56 -0800 Subject: [PATCH 31/35] Update test_wallet_commands.py - improve tests --- .../Commands/tests/test_wallet_commands.py | 42 ++++++++++++------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/neo/Prompt/Commands/tests/test_wallet_commands.py b/neo/Prompt/Commands/tests/test_wallet_commands.py index b8627dac9..10068ec79 100644 --- a/neo/Prompt/Commands/tests/test_wallet_commands.py +++ b/neo/Prompt/Commands/tests/test_wallet_commands.py @@ -36,15 +36,8 @@ def GetWallet1(cls, recreate=False): # Beginning with refactored tests - def test_wallet_open_and_close(self): + def test_wallet_open(self): with patch('neo.Prompt.PromptData.PromptData.Prompt'): - # test wallet close with no wallet - args = ['close'] - - res = CommandWallet().execute(args) - - self.assertFalse(res) - with patch('neo.Prompt.Commands.Wallet.prompt', side_effect=["testpassword"]): # test wallet open successful args = ['open', 'fixtures/testwallet.db3'] @@ -53,14 +46,7 @@ def test_wallet_open_and_close(self): self.assertEqual(str(type(res)), "") - # test wallet close with open wallet - args = ['close'] - - res = CommandWallet().execute(args) - - self.assertTrue(res) - - # test wallet open with no path + # test wallet open with no path; this will also close the open wallet args = ['open'] res = CommandWallet().execute(args) @@ -83,6 +69,30 @@ def test_wallet_open_and_close(self): self.assertFalse(res) + def test_wallet_close(self): + with patch('neo.Prompt.PromptData.PromptData.Prompt'): + # test wallet close with no wallet + args = ['close'] + + res = CommandWallet().execute(args) + + self.assertFalse(res) + + # test wallet close with open wallet + with patch('neo.Prompt.Commands.Wallet.prompt', side_effect=["testpassword"]): + args = ['open', 'fixtures/testwallet.db3'] + + res = CommandWallet().execute(args) + + self.assertEqual(str(type(res)), "") + + # now close the open wallet manually + args = ['close'] + + res = CommandWallet().execute(args) + + self.assertTrue(res) + ########################################################## ########################################################## def test_1_import_addr(self): From 041ad140a311a808d6458e100f61563d5b75fb92 Mon Sep 17 00:00:00 2001 From: jseagrave21 <40873301+jseagrave21@users.noreply.github.com> Date: Tue, 27 Nov 2018 13:24:04 -0800 Subject: [PATCH 32/35] Update Wallet.py - remove unnecessary logic --- neo/Prompt/Commands/Wallet.py | 1 - 1 file changed, 1 deletion(-) diff --git a/neo/Prompt/Commands/Wallet.py b/neo/Prompt/Commands/Wallet.py index ea4df5863..509113081 100644 --- a/neo/Prompt/Commands/Wallet.py +++ b/neo/Prompt/Commands/Wallet.py @@ -173,7 +173,6 @@ def execute(cls, arguments=None): PromptData.Wallet = None print("Closed wallet %s" % path) return True - return False def command_desc(self): return CommandDesc('close', 'closes the open NEO wallet') From 9c3b679f2165efbc01a2ee9e02c48f65712c0197 Mon Sep 17 00:00:00 2001 From: jseagrave21 <40873301+jseagrave21@users.noreply.github.com> Date: Tue, 27 Nov 2018 18:28:18 -0800 Subject: [PATCH 33/35] Update prompt.py - update close_wallet implementation --- neo/bin/prompt.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/neo/bin/prompt.py b/neo/bin/prompt.py index 95bef7f3f..53fc3a2e6 100755 --- a/neo/bin/prompt.py +++ b/neo/bin/prompt.py @@ -36,7 +36,7 @@ token_mint, token_crowdsale_register, token_history # from neo.Prompt.Commands.Wallet import CreateAddress, DeleteAddress, ImportWatchAddr, ImportToken, ClaimGas, DeleteToken, AddAlias, \ # ShowUnspentCoins, SplitUnspentCoin -from neo.Prompt.Commands.Wallet import CommandWallet, CommandWalletClose +from neo.Prompt.Commands.Wallet import CommandWallet from neo.Prompt.PromptData import PromptData from neo.Prompt.Utils import get_arg, get_from_addr, get_tx_attr_from_args, get_owners_from_params @@ -226,7 +226,7 @@ def get_completer(self): def quit(self): print('Shutting down. This may take a bit...') self.go_on = False - CommandWalletClose.execute() + PromptData.close_wallet() reactor.stop() def help(self): From e7c99140b7c97376ea14d8dd926f9b381c2a8e53 Mon Sep 17 00:00:00 2001 From: jseagrave21 <40873301+jseagrave21@users.noreply.github.com> Date: Tue, 27 Nov 2018 18:29:13 -0800 Subject: [PATCH 34/35] Update Wallet.py - update close_wallet implementation --- neo/Prompt/Commands/Wallet.py | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/neo/Prompt/Commands/Wallet.py b/neo/Prompt/Commands/Wallet.py index 509113081..ef517384d 100644 --- a/neo/Prompt/Commands/Wallet.py +++ b/neo/Prompt/Commands/Wallet.py @@ -73,7 +73,7 @@ def __init__(self): def execute(self, arguments): if PromptData.Wallet: - CommandWalletClose.execute() + PromptData.close_wallet() path = get_arg(arguments, 0) if path: @@ -127,7 +127,7 @@ def __init__(self): def execute(self, arguments): if PromptData.Wallet: - CommandWalletClose.execute() + PromptData.close_wallet() path = get_arg(arguments, 0) @@ -164,15 +164,8 @@ class CommandWalletClose(CommandBase): def __init__(self): super().__init__() - @classmethod - def execute(cls, arguments=None): - if PromptData.Wallet: - path = PromptData.Wallet._path - PromptData.Prompt.stop_wallet_loop() - PromptData.Wallet.Close() - PromptData.Wallet = None - print("Closed wallet %s" % path) - return True + def execute(self, arguments=None): + return PromptData.close_wallet() def command_desc(self): return CommandDesc('close', 'closes the open NEO wallet') From d87059509be957fc6816b559001b08560cf0db06 Mon Sep 17 00:00:00 2001 From: jseagrave21 <40873301+jseagrave21@users.noreply.github.com> Date: Tue, 27 Nov 2018 18:30:40 -0800 Subject: [PATCH 35/35] Update PromptData.py - update close_wallet implementation --- neo/Prompt/PromptData.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/neo/Prompt/PromptData.py b/neo/Prompt/PromptData.py index 0493676e2..2bb5a6cdc 100644 --- a/neo/Prompt/PromptData.py +++ b/neo/Prompt/PromptData.py @@ -1,3 +1,15 @@ class PromptData: Prompt = None Wallet = None + + @staticmethod + def close_wallet(): + if not PromptData.Wallet: + return False + + path = PromptData.Wallet._path + PromptData.Prompt.stop_wallet_loop() + PromptData.Wallet.Close() + PromptData.Wallet = None + print("Closed wallet %s" % path) + return True