This repository was archived by the owner on Nov 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 187
[refactor prompt] Add support for search method group #739
Merged
ixje
merged 13 commits into
CityOfZion:refactor-prompt
from
jseagrave21:refactor-CommandSearch
Dec 6, 2018
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
dbe5074
Merge pull request #78 from CityOfZion/refactor-prompt
jseagrave21 681b063
Update prompt.py
jseagrave21 5b8c226
Update prompt.py
jseagrave21 ebdd8ca
Update prompt.py
jseagrave21 63c437e
Add Search.py
jseagrave21 c263e3b
Add test_search_commands.py
jseagrave21 4396d7e
Update Search.py
jseagrave21 64693ca
Update test_search_commands.py
jseagrave21 843ae57
Update LevelDBBlockchain.py
jseagrave21 156907a
Update test_search_commands.py
jseagrave21 487d294
Update test_search_commands.py
jseagrave21 446732f
Update Wallet.py
jseagrave21 bed8d09
Update test_search_commands.py
jseagrave21 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| from neo.Prompt.CommandBase import CommandBase, CommandDesc, ParameterDesc | ||
| from neo.Prompt.PromptData import PromptData | ||
| from neo.Prompt.Utils import get_arg | ||
| from neo.Core.Blockchain import Blockchain | ||
| from neo.logging import log_manager | ||
| import json | ||
|
|
||
|
|
||
| logger = log_manager.getLogger() | ||
|
|
||
|
|
||
| class CommandSearch(CommandBase): | ||
| def __init__(self): | ||
| super().__init__() | ||
|
|
||
| self.register_sub_command(CommandSearchAsset()) | ||
| self.register_sub_command(CommandSearchContract()) | ||
|
|
||
| def command_desc(self): | ||
| return CommandDesc('search', 'search the blockchain') | ||
|
|
||
| def execute(self, arguments): | ||
| item = get_arg(arguments) | ||
|
|
||
| if not item: | ||
| print("run `%s help` to see supported queries" % CommandSearch().command_desc().command) | ||
| return | ||
|
|
||
| try: | ||
| return self.execute_sub_command(item, arguments[1:]) | ||
| except KeyError: | ||
| print(f"{item} is an invalid parameter") | ||
| return | ||
|
|
||
|
|
||
| class CommandSearchAsset(CommandBase): | ||
| def __init__(self): | ||
| super().__init__() | ||
|
|
||
| def execute(self, arguments): | ||
| item = get_arg(arguments) | ||
|
|
||
| results = Blockchain.Default().SearchAssetState(item) | ||
| print("Found %s results for %s" % (len(results), item)) | ||
| for asset in results: | ||
| print(json.dumps(asset.ToJson(), indent=4)) | ||
| return results | ||
|
|
||
| def command_desc(self): | ||
| p1 = ParameterDesc('query', 'supports name, issuer, or admin searches') | ||
| return CommandDesc('asset', 'perform an asset search', [p1]) | ||
|
|
||
|
|
||
| class CommandSearchContract(CommandBase): | ||
| def __init__(self): | ||
| super().__init__() | ||
|
|
||
| def execute(self, arguments): | ||
| item = get_arg(arguments) | ||
|
|
||
| contracts = Blockchain.Default().SearchContracts(query=item) | ||
| print("Found %s results for %s" % (len(contracts), item)) | ||
| for contract in contracts: | ||
| print(json.dumps(contract.ToJson(), indent=4)) | ||
| return contracts | ||
|
|
||
| def command_desc(self): | ||
| p1 = ParameterDesc('query', 'supports name, author, description, or email searches') | ||
| return CommandDesc('contract', 'perform a contract search', [p1]) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| import os | ||
| from neo.Settings import settings | ||
| from neo.Utils.BlockchainFixtureTestCase import BlockchainFixtureTestCase | ||
| from neo.Prompt.Commands.Search import CommandSearch | ||
|
|
||
|
|
||
| class CommandShowTestCase(BlockchainFixtureTestCase): | ||
|
|
||
| @classmethod | ||
| def leveldb_testpath(self): | ||
| return os.path.join(settings.DATA_DIR_PATH, 'fixtures/test_chain') | ||
|
|
||
| def test_search(self): | ||
| # with no subcommand | ||
| res = CommandSearch().execute(None) | ||
| self.assertFalse(res) | ||
|
|
||
| # with invalid command | ||
| args = ['badcommand'] | ||
| res = CommandSearch().execute(args) | ||
| self.assertFalse(res) | ||
|
|
||
| def test_search_asset(self): | ||
| # successful search asset NEO | ||
| args = ['asset', "NEO"] | ||
| res = CommandSearch().execute(args) | ||
| self.assertTrue(res) | ||
|
|
||
| # successful search asset gas | ||
| args = ['asset', "gas"] | ||
| res = CommandSearch().execute(args) | ||
| self.assertTrue(res) | ||
|
|
||
| # successful search asset NEOGas | ||
| args = ['asset', "NEOGas"] | ||
| res = CommandSearch().execute(args) | ||
| self.assertTrue(res) | ||
|
|
||
| # successful search asset AntShare | ||
| args = ['asset', "AntShare"] | ||
| res = CommandSearch().execute(args) | ||
| self.assertTrue(res) | ||
|
|
||
| # successful search asset AntCoin | ||
| args = ['asset', "AntCoin"] | ||
| res = CommandSearch().execute(args) | ||
| self.assertTrue(res) | ||
|
|
||
| # successful search by issuer and admin (same address) | ||
| args = ['asset', "Abf2qMs1pzQb8kYk9RuxtUb9jtRKJVuBJt"] | ||
| res = CommandSearch().execute(args) | ||
| self.assertTrue(res) | ||
|
|
||
| # unsuccessful search | ||
| args = ['asset', 'blah'] | ||
| res = CommandSearch().execute(args) | ||
| self.assertFalse(res) | ||
|
|
||
| def test_search_contract(self): | ||
| # successful search by name | ||
| args = ['contract', "test NEX Template V4"] | ||
| res = CommandSearch().execute(args) | ||
| self.assertTrue(res) | ||
| self.assertEqual(len(res), 1) | ||
|
|
||
| # successful search by author | ||
| args = ['contract', "dauTT"] | ||
| res = CommandSearch().execute(args) | ||
| self.assertTrue(res) | ||
| self.assertEqual(len(res), 3) | ||
|
|
||
| # successful search by description | ||
| args = ['contract', "neo-ico-template"] | ||
| res = CommandSearch().execute(args) | ||
| self.assertTrue(res) | ||
| self.assertEqual(len(res), 1) | ||
|
|
||
| # successful search by email (as entered) | ||
| args = ['contract', ""] | ||
| res = CommandSearch().execute(args) | ||
| self.assertTrue(res) | ||
| self.assertEqual(len(res), 6) | ||
|
|
||
| # bad search input | ||
| args = ['contract', "blah"] | ||
| res = CommandSearch().execute(args) | ||
| self.assertFalse(res) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.