Skip to content
This repository was archived by the owner on Nov 15, 2021. It is now read-only.

Commit b7fa099

Browse files
committed
Handle review: add feedback when there is no asset matching the arguments + use neocore.Utils.isValidPublicAddress
Signed-off-by: Guillaume George <lysandergc@gmail.com>
1 parent adf9df0 commit b7fa099

File tree

2 files changed

+31
-24
lines changed

2 files changed

+31
-24
lines changed

neo/Prompt/Commands/Wallet.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -275,25 +275,25 @@ def execute(self, arguments):
275275
from_addr = None
276276
watch_only = False
277277
do_count = False
278+
wallet = PromptData.Wallet
278279

279-
try:
280-
if arguments:
281-
arguments, from_addr_str = get_from_addr(arguments)
282-
if from_addr_str:
283-
from_addr = PromptData.Wallet.ToScriptHash(from_addr_str)
284-
285-
for item in arguments:
286-
if item == '--watch':
287-
watch_only = True
288-
elif item == '--count':
289-
do_count = True
290-
else:
291-
asset_id = get_asset_id(PromptData.Wallet, item)
292-
except Exception as e:
293-
print("Invalid arguments specified")
294-
return None
280+
arguments, from_addr_str = PromptUtils.get_from_addr(arguments)
281+
if from_addr_str:
282+
if not isValidPublicAddress(from_addr_str):
283+
print("Invalid address specified")
284+
return None
295285

296-
return ShowUnspentCoins(PromptData.Wallet, asset_id, from_addr, watch_only, do_count)
286+
from_addr = wallet.ToScriptHash(from_addr_str)
287+
288+
for item in arguments:
289+
if item == '--watch':
290+
watch_only = True
291+
elif item == '--count':
292+
do_count = True
293+
else:
294+
asset_id = PromptUtils.get_asset_id(wallet, item)
295+
296+
return ShowUnspentCoins(wallet, asset_id, from_addr, watch_only, do_count)
297297

298298
def command_desc(self):
299299
p1 = ParameterDesc('asset', 'type of asset to query (NEO/GAS)', optional=True)
@@ -739,6 +739,9 @@ def ShowUnspentCoins(wallet, asset_id=None, from_addr=None, watch_only=False, do
739739
print('\n-----------------------------------------------')
740740
print(json.dumps(unspent.ToJson(), indent=4))
741741

742+
if not unspents:
743+
print("No unspent assets matching the arguments.")
744+
742745
return unspents
743746

744747

neo/Prompt/Commands/tests/test_wallet_commands.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ def test_wallet_unspent(self):
373373
args = ['unspent', '--from-addr=123']
374374
res = CommandWallet().execute(args)
375375
self.assertIsNone(res)
376-
self.assertIn("Invalid arguments specified", mock_print.getvalue())
376+
self.assertIn("Invalid address specified", mock_print.getvalue())
377377

378378
# test wallet unspent successful
379379
args = ['unspent']
@@ -406,9 +406,11 @@ def test_wallet_unspent(self):
406406
self.assertEqual(res[0].Output.AssetId, self.GAS)
407407

408408
# test wallet unspent with unrelated address
409-
args = ['unspent', '--from-addr=AGYaEi3W6ndHPUmW7T12FFfsbQ6DWymkEm']
410-
res = CommandWallet().execute(args)
411-
self.assertEqual(res, [])
409+
with patch('sys.stdout', new=StringIO()) as mock_print:
410+
args = ['unspent', '--from-addr=AGYaEi3W6ndHPUmW7T12FFfsbQ6DWymkEm']
411+
res = CommandWallet().execute(args)
412+
self.assertEqual(res, [])
413+
self.assertIn("No unspent assets matching the arguments", mock_print.getvalue())
412414

413415
# test wallet unspent with address
414416
args = ['unspent', '--from-addr=AJQ6FoaSXDFzA6wLnyZ1nFN7SGSN2oNTc3']
@@ -419,9 +421,11 @@ def test_wallet_unspent(self):
419421
self.assertEqual(res[1].Output.AssetId, self.GAS)
420422

421423
# test wallet unspent with --watch
422-
args = ['unspent', '--watch']
423-
res = CommandWallet().execute(args)
424-
self.assertEqual(res, [])
424+
with patch('sys.stdout', new=StringIO()) as mock_print:
425+
args = ['unspent', '--watch']
426+
res = CommandWallet().execute(args)
427+
self.assertEqual(res, [])
428+
self.assertIn("No unspent assets matching the arguments", mock_print.getvalue())
425429

426430
# test wallet unspent with --count
427431
with patch('sys.stdout', new=StringIO()) as mock_print:

0 commit comments

Comments
 (0)