This repository has been archived by the owner on Dec 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 76
Replace subprocess #236
Merged
martriay
merged 92 commits into
OpenZeppelin:main
from
andrew-fleming:replace-subprocess
Nov 17, 2022
Merged
Replace subprocess #236
Changes from 85 commits
Commits
Show all changes
92 commits
Select commit
Hold shift + click to select a range
3b9bd03
add async deps
andrew-fleming 31faeb4
update funcs to async
andrew-fleming 4313220
adjust run_cmd, add helper funcs
andrew-fleming 4ee68d4
adjust methods to async
andrew-fleming 3c916bb
adjust nre to async
andrew-fleming 6d742af
fix formatting
andrew-fleming c47a75a
replace arg object, fix nre and output
andrew-fleming 1fe7e8d
fix formatting
andrew-fleming 0f5770f
add rstrip to capture
andrew-fleming 2c38d82
async get-nonce
andrew-fleming 485469f
remove comments
andrew-fleming f7c76c7
fix formatting
andrew-fleming 2c205e8
add event loop
andrew-fleming cf3896e
update tests without subprocess
andrew-fleming 26cf600
update cli tests with asyncclick
andrew-fleming 515a1fa
adjust tests to async
andrew-fleming 054cce6
add set_args func
andrew-fleming 0b0da87
simplify context with set_args
andrew-fleming 602b14b
remove subprocess, add set_args
andrew-fleming 195a24b
add tests for common funcs
andrew-fleming 9fe9d17
async debug, remove subprocess
andrew-fleming 50484e8
fix test
andrew-fleming 9064a8c
fix conflicts
andrew-fleming f6c7933
fix conflicts
andrew-fleming e0f066c
fix account test conflicts
andrew-fleming 4170096
update account tests to async
andrew-fleming cb138a7
update debug test to async
andrew-fleming 552b42c
update get_accounts to async
andrew-fleming 910490e
start test refactor
andrew-fleming 4e36c40
fix conflicts
andrew-fleming 8c4e3f2
add async to nre snippets
andrew-fleming 87621b2
add language to code block
andrew-fleming d04f45d
fix conflicts
andrew-fleming ce76753
fix url tests
andrew-fleming ec61c35
fix tests
andrew-fleming 122a481
fix formatting
andrew-fleming f0a2a62
fix get_gateway handling
andrew-fleming c8f92e1
remove redundant mock
andrew-fleming bf49f3f
fix formatting
andrew-fleming 0f5a7c8
remove unused func
andrew-fleming 1333b42
fix conflicts
andrew-fleming 4085231
Merge branch 'main' into replace-subprocess
andrew-fleming 8075a2d
clean up test
andrew-fleming 7058547
fix network handling
andrew-fleming f673b26
fix tx_status calls
andrew-fleming 154ff15
fix conflicts
andrew-fleming 57395fa
add call_cli func
andrew-fleming 13a5a36
abstract command args
andrew-fleming d7c0577
fix tests with call_cli
andrew-fleming c6e4eae
fix tests with call_cli
andrew-fleming a8209b7
fix formatting
andrew-fleming 5ccf195
fix conflicts
andrew-fleming ae62502
remove unnecessary hex
andrew-fleming 67f8f0b
remove async from simulate methods
andrew-fleming f57df83
remove unnecessary int conversion
andrew-fleming 8a5bac0
add comment regarding AsyncObject in Account
andrew-fleming b7f2dd8
handle async logging
andrew-fleming ab02531
fix formatting
andrew-fleming 33f4ad0
refactor _process_arguments
andrew-fleming d674b53
fix formatting
andrew-fleming effe69b
fix conflicts
andrew-fleming 7fa5ac7
fix _process_arguments
andrew-fleming 6df837f
fix test
andrew-fleming 73de60a
fix tx output and error handling
andrew-fleming 86e7851
fix formatting
andrew-fleming ede0077
add starknet_cli module
andrew-fleming 97bc116
improve command_args handling
andrew-fleming 0bbb764
fix sender param
andrew-fleming b808dfb
fix docstring formatting
andrew-fleming cc58510
add starknet_cli tests
andrew-fleming 303d634
fix status test
andrew-fleming 517a564
move tests to starknet_cli
andrew-fleming 42cca30
update patch location
andrew-fleming 483cd3a
test args in execute_call
andrew-fleming f33ccc2
add comments
andrew-fleming fbcef31
remove comments
andrew-fleming 4952346
Apply suggestions from code review
andrew-fleming aba30ec
remove comment
andrew-fleming 88eb64b
rename set_args to set_context
andrew-fleming 6b126b7
reorder _process_arguments params
andrew-fleming cdc7cbc
support nested lists in _add_args
andrew-fleming 17b6e91
suppress pytest warning
andrew-fleming 313cd6c
fix test
andrew-fleming 966ae14
call prepare_params in starknet_cli
andrew-fleming d44f78f
fix tests
andrew-fleming 3ded033
Update src/nile/core/declare.py
andrew-fleming 02381be
remove prepare_params from deploy and declare
andrew-fleming df1e71f
fix formatting
andrew-fleming fab1279
fix tests
andrew-fleming ee0a44a
Update tests/test_starknet_cli.py
andrew-fleming f27558e
Update src/nile/core/declare.py
martriay d37ce19
convert max_fee to str in starknet_cli
andrew-fleming 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 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 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 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 |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
"""Nile CLI entry point.""" | ||
import logging | ||
|
||
import click | ||
import asyncclick as click | ||
|
||
from nile.common import is_alias | ||
from nile.core.account import Account | ||
|
@@ -25,6 +25,7 @@ | |
from nile.utils.status import status as status_command | ||
|
||
logging.basicConfig(level=logging.DEBUG, format="%(message)s") | ||
logging.getLogger("asyncio").setLevel(logging.WARNING) | ||
|
||
NETWORKS = ("localhost", "integration", "goerli", "goerli2", "mainnet") | ||
|
||
|
@@ -85,9 +86,9 @@ def init(): | |
@cli.command() | ||
@click.argument("path", nargs=1) | ||
@network_option | ||
def run(path, network): | ||
async def run(path, network): | ||
"""Run Nile scripts with NileRuntimeEnvironment.""" | ||
run_command(path, network) | ||
await run_command(path, network) | ||
|
||
|
||
@cli.command() | ||
|
@@ -98,13 +99,13 @@ def run(path, network): | |
@network_option | ||
@mainnet_token_option | ||
@watch_option | ||
def deploy(artifact, arguments, network, alias, watch_mode, abi, token): | ||
async def deploy(artifact, arguments, network, alias, abi, token, watch_mode): | ||
"""Deploy StarkNet smart contract.""" | ||
deploy_command( | ||
contract_name=artifact, | ||
arguments=arguments, | ||
network=network, | ||
alias=alias, | ||
await deploy_command( | ||
artifact, | ||
arguments, | ||
network, | ||
alias, | ||
abi=abi, | ||
mainnet_token=token, | ||
watch_mode=watch_mode, | ||
|
@@ -120,7 +121,7 @@ def deploy(artifact, arguments, network, alias, watch_mode, abi, token): | |
@network_option | ||
@mainnet_token_option | ||
@watch_option | ||
def declare( | ||
async def declare( | ||
signer, | ||
contract_name, | ||
network, | ||
|
@@ -131,8 +132,8 @@ def declare( | |
token, | ||
): | ||
"""Declare StarkNet smart contract.""" | ||
account = Account(signer, network) | ||
account.declare( | ||
account = await Account(signer, network) | ||
await account.declare( | ||
contract_name, | ||
alias=alias, | ||
max_fee=max_fee, | ||
|
@@ -146,9 +147,9 @@ def declare( | |
@click.argument("signer", nargs=1) | ||
@network_option | ||
@watch_option | ||
def setup(signer, network, watch_mode): | ||
async def setup(signer, network, watch_mode): | ||
"""Set up an Account contract.""" | ||
Account(signer, network, watch_mode=watch_mode) | ||
await Account(signer, network, watch_mode=watch_mode) | ||
|
||
|
||
@cli.command() | ||
|
@@ -161,7 +162,7 @@ def setup(signer, network, watch_mode): | |
@click.option("--estimate_fee", "query", flag_value="estimate_fee") | ||
@network_option | ||
@watch_option | ||
def send( | ||
async def send( | ||
signer, | ||
address_or_alias, | ||
method, | ||
|
@@ -172,15 +173,15 @@ def send( | |
watch_mode, | ||
): | ||
"""Invoke a contract's method through an Account.""" | ||
account = Account(signer, network) | ||
account = await Account(signer, network) | ||
print( | ||
"Calling {} on {} with params: {}".format( | ||
method, address_or_alias, [x for x in params] | ||
) | ||
) | ||
# address_or_alias is not normalized first here because | ||
# Account.send is part of Nile's public API and can accept hex addresses | ||
account.send( | ||
await account.send( | ||
address_or_alias, | ||
method, | ||
params, | ||
|
@@ -195,18 +196,15 @@ def send( | |
@click.argument("method", nargs=1) | ||
@click.argument("params", nargs=-1) | ||
@network_option | ||
def call(address_or_alias, method, params, network): | ||
async def call(address_or_alias, method, params, network): | ||
"""Call functions of StarkNet smart contracts.""" | ||
if not is_alias(address_or_alias): | ||
address_or_alias = normalize_number(address_or_alias) | ||
out = call_or_invoke_command( | ||
contract=address_or_alias, | ||
type="call", | ||
method=method, | ||
params=params, | ||
network=network, | ||
out = await call_or_invoke_command( | ||
address_or_alias, "call", method, params, network | ||
) | ||
print(out) | ||
logging.info(out) | ||
return out | ||
|
||
|
||
@cli.command() | ||
|
@@ -293,21 +291,21 @@ def version(): | |
@click.argument("tx_hash", nargs=1) | ||
@click.option("--contracts_file", nargs=1) | ||
@network_option | ||
def debug(tx_hash, network, contracts_file): | ||
async def debug(tx_hash, network, contracts_file): | ||
""" | ||
Locate an error in a transaction using available contracts. | ||
|
||
Alias for `nile status --debug`. | ||
""" | ||
status_command(normalize_number(tx_hash), network, "debug", contracts_file) | ||
await status_command(normalize_number(tx_hash), network, "debug", contracts_file) | ||
|
||
|
||
@cli.command() | ||
@click.argument("tx_hash", nargs=1) | ||
@click.option("--contracts_file", nargs=1) | ||
@network_option | ||
@watch_option | ||
def status(tx_hash, network, watch_mode, contracts_file): | ||
async def status(tx_hash, network, watch_mode, contracts_file): | ||
""" | ||
Get the status of a transaction. | ||
|
||
|
@@ -320,7 +318,7 @@ def status(tx_hash, network, watch_mode, contracts_file): | |
$ nile status --debug transaction_hash | ||
Same as `status --track` then locate errors if rejected using local artifacts | ||
""" | ||
status_command( | ||
await status_command( | ||
normalize_number(tx_hash), | ||
network, | ||
watch_mode=watch_mode, | ||
|
@@ -331,24 +329,24 @@ def status(tx_hash, network, watch_mode, contracts_file): | |
@cli.command() | ||
@click.option("--predeployed/--registered", default=False) | ||
@network_option | ||
def get_accounts(network, predeployed): | ||
async def get_accounts(network, predeployed): | ||
"""Retrieve and manage deployed accounts.""" | ||
if not predeployed: | ||
return get_accounts_command(network) | ||
return await get_accounts_command(network) | ||
else: | ||
return get_predeployed_accounts_command(network) | ||
return await get_predeployed_accounts_command(network) | ||
|
||
|
||
@cli.command() | ||
@click.argument("contract_address") | ||
@network_option | ||
def get_nonce(contract_address, network): | ||
async def get_nonce(contract_address, network): | ||
"""Retrieve the nonce for a contract.""" | ||
return get_nonce_command(normalize_number(contract_address), network) | ||
return await get_nonce_command(normalize_number(contract_address), network) | ||
|
||
|
||
cli = load_plugins(cli) | ||
|
||
|
||
if __name__ == "__main__": | ||
cli() | ||
cli(_anyion_backend="asyncio") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this results in this being logged every time:
|
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is asyncclick usage implying a requirement to update plugins accordingly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great question! I'm honestly not sure. I'll try and test it to find out