From d3bb1cb6dad83ce3cc13860be514b26152bfa48d Mon Sep 17 00:00:00 2001 From: PatrickAlphaC <54278053+PatrickAlphaC@users.noreply.github.com> Date: Fri, 18 Oct 2024 03:38:56 -0400 Subject: [PATCH 1/2] feat: uv style config --- docs/source/_autogenerated/eravm_defaults.rst | 4 + .../_autogenerated/explorer_defaults.rst | 318 ++++++++++++++++++ docs/source/_autogenerated/fork_defaults.rst | 4 + docs/source/_autogenerated/pyevm_defaults.rst | 4 + docs/source/_generate_vars.py | 43 +++ docs/source/conf.py | 2 +- docs/source/core_concepts/moccasin_toml.rst | 42 ++- docs/source/core_concepts/networks.rst | 35 +- docs/source/core_concepts/networks/eravm.rst | 18 + .../networks/forked_networks.rst | 7 +- docs/source/core_concepts/networks/pyevm.rst | 7 +- docs/source/core_concepts/project.rst | 12 +- docs/source/explorer_network_defaults.rst | 4 + docs/source/how-tos/verify_contracts.rst | 47 +++ docs/source/moccasin_wrapper_for_docs.py | 9 - docs/source/toctree.rst | 5 +- .../tutorials/zksync-getting-started.rst | 52 +++ justfile | 1 + moccasin/commands/config_.py | 2 +- moccasin/config.py | 232 ++++++++++--- moccasin/constants/vars.py | 26 +- pyproject.toml | 8 +- tests/cli/deployments/conftest.py | 3 + tests/conftest.py | 25 ++ tests/data/complex_project/pyproject.toml | 13 + tests/data/no_config_project/.hello | 0 tests/data/no_config_project/.python-version | 1 + tests/data/no_config_project/README.md | 0 tests/data/no_config_project/contracts/hi.vy | 4 + tests/data/no_config_project/hello.py | 6 + tests/data/no_config_project/pyproject.toml | 12 + tests/data/purge_project/moccasin.toml | 2 +- tests/integration/test_integration_install.py | 82 +++-- tests/integration/test_integration_purge.py | 33 +- tests/unit/test_unit_config.py | 22 ++ uv.lock | 8 +- 36 files changed, 953 insertions(+), 140 deletions(-) create mode 100644 docs/source/_autogenerated/eravm_defaults.rst create mode 100644 docs/source/_autogenerated/explorer_defaults.rst create mode 100644 docs/source/_autogenerated/fork_defaults.rst create mode 100644 docs/source/_autogenerated/pyevm_defaults.rst create mode 100644 docs/source/_generate_vars.py create mode 100644 docs/source/core_concepts/networks/eravm.rst create mode 100644 docs/source/explorer_network_defaults.rst create mode 100644 docs/source/how-tos/verify_contracts.rst create mode 100644 docs/source/tutorials/zksync-getting-started.rst create mode 100644 tests/data/no_config_project/.hello create mode 100644 tests/data/no_config_project/.python-version create mode 100644 tests/data/no_config_project/README.md create mode 100644 tests/data/no_config_project/contracts/hi.vy create mode 100644 tests/data/no_config_project/hello.py create mode 100644 tests/data/no_config_project/pyproject.toml diff --git a/docs/source/_autogenerated/eravm_defaults.rst b/docs/source/_autogenerated/eravm_defaults.rst new file mode 100644 index 0000000..f9c616f --- /dev/null +++ b/docs/source/_autogenerated/eravm_defaults.rst @@ -0,0 +1,4 @@ +is_zksync = true +prompt_live = false +save_to_db = false +live_or_staging = false diff --git a/docs/source/_autogenerated/explorer_defaults.rst b/docs/source/_autogenerated/explorer_defaults.rst new file mode 100644 index 0000000..8a43d70 --- /dev/null +++ b/docs/source/_autogenerated/explorer_defaults.rst @@ -0,0 +1,318 @@ +[mainnet] +explorer = "https://eth.blockscout.com/" +explorer_type = "blockscout" +multicall2 = "0x5BA1e12693Dc8F9c48aAD8770482f4739bEeD696" +chain_id = 1 + +[sepolia] +explorer = "https://eth-sepolia.blockscout.com/" +explorer_type = "blockscout" +multicall2 = "" +chain_id = 11155111 + +[goerli] +explorer = "https://eth-goerli.blockscout.com/" +explorer_type = "blockscout" +multicall2 = "0x5BA1e12693Dc8F9c48aAD8770482f4739bEeD696" +chain_id = 5 + +[arbitrum] +explorer = "https://arbitrum.blockscout.com/" +explorer_type = "blockscout" +multicall2 = "0x5B5CFE992AdAC0C9D48E05854B2d91C73a003858" +chain_id = 42161 + +[optimism-main] +explorer = "https://optimism.blockscout.com/" +explorer_type = "blockscout" +multicall2 = "0x2DC0E2aa608532Da689e89e237dF582B783E552C" +chain_id = 10 + +[optimism-test] +explorer = "https://optimism-sepolia.blockscout.com/" +explorer_type = "blockscout" +multicall2 = "0x2DC0E2aa608532Da689e89e237dF582B783E552C" +chain_id = 420 + +[polygon-main] +explorer = "https://polygon.blockscout.com/" +explorer_type = "blockscout" +multicall2 = "0xc8E51042792d7405184DfCa245F2d27B94D013b6" +chain_id = 137 + +[gnosis-main] +explorer = "https://gnosis.blockscout.com/" +explorer_type = "blockscout" +multicall2 = "" +chain_id = 100 + +[gnosis-test] +explorer = "https://gnosis-chiado.blockscout.com/" +explorer_type = "blockscout" +multicall2 = "" +chain_id = 10200 + +[base-main] +explorer = "https://base.blockscout.com/" +explorer_type = "blockscout" +multicall2 = "" +chain_id = 8453 + +[syscoin] +explorer = "https://explorer.syscoin.org/" +explorer_type = "blockscout" +multicall2 = "" +chain_id = 57 + +[ethereumclassic] +explorer = "https://etc.blockscout.com/" +explorer_type = "blockscout" +multicall2 = "" +chain_id = 61 + +[nova-network] +explorer = "https://explorer.novanetwork.io/" +explorer_type = "blockscout" +multicall2 = "" +chain_id = 87 + +[velas] +explorer = "https://evmexplorer.velas.com/" +explorer_type = "blockscout" +multicall2 = "" +chain_id = 106 + +[thundercore] +explorer = "https://explorer-mainnet.thundercore.com/" +explorer_type = "blockscout" +multicall2 = "" +chain_id = 108 + +[fuse] +explorer = "https://explorer.fuse.io/" +explorer_type = "blockscout" +multicall2 = "" +chain_id = 122 + +[heco] +explorer = "" +multicall2 = "" +chain_id = 128 + +[shimmer_evm] +explorer = "https://explorer.evm.shimmer.network/" +explorer_type = "blockscout" +multicall2 = "" +chain_id = 148 + +[manta] +explorer = "https://pacific-explorer.manta.network/" +explorer_type = "blockscout" +multicall2 = "" +chain_id = 169 + +[energyweb] +explorer = "https://explorer.energyweb.org/" +explorer_type = "blockscout" +multicall2 = "" +chain_id = 246 + +[oasys] +explorer = "https://explorer.oasys.games/" +explorer_type = "blockscout" +multicall2 = "" +chain_id = 248 + +[omax] +explorer = "https://omaxscan.com/" +multicall2 = "" +chain_id = 311 + +[filecoin] +explorer = "https://filecoin.blockscout.com/" +explorer_type = "blockscout" +multicall2 = "" +chain_id = 314 + +[kucoin] +explorer = "https://scan.kcc.io/" +multicall2 = "" +chain_id = 321 + +[zksync-era] +explorer = "https://zksync2-mainnet-explorer.zksync.io" +explorer_type = "zksyncexplorer" +multicall2 = "" +chain_id = 324 + +[sepolia-zksync-era] +explorer = "https://explorer.sepolia.era.zksync.dev" +explorer_type = "zksyncexplorer" +multicall2 = "" +chain_id = 300 + +[shiden] +explorer = "https://shiden.blockscout.com/" +explorer_type = "blockscout" +multicall2 = "" +chain_id = 336 + +[rollux] +explorer = "https://explorer.rollux.com/" +explorer_type = "blockscout" +multicall2 = "" +chain_id = 570 + +[astar] +explorer = "https://astar.blockscout.com/" +explorer_type = "blockscout" +multicall2 = "" +chain_id = 592 + +[callisto] +explorer = "https://explorer.callisto.network/" +explorer_type = "blockscout" +multicall2 = "" +chain_id = 820 + +[lyra-chain] +explorer = "https://explorer.lyra.finance/" +explorer_type = "blockscout" +multicall2 = "" +chain_id = 957 + +[bifrost] +explorer = "https://explorer.mainnet.bifrostnetwork.com/" +explorer_type = "blockscout" +multicall2 = "" +chain_id = 996 + +[metis] +explorer = "https://andromeda-explorer.metis.io/" +explorer_type = "blockscout" +multicall2 = "" +chain_id = 1088 + +[polygon-zkevm] +explorer = "https://zkevm.blockscout.com/" +explorer_type = "blockscout" +multicall2 = "" +chain_id = 1101 + +[core] +explorer = "" +multicall2 = "" +chain_id = 1116 + +[lisk] +explorer = "https://blockscout.lisk.com/" +explorer_type = "blockscout" +multicall2 = "" +chain_id = 1135 + +[reya-network] +explorer = "https://explorer.reya.network/" +explorer_type = "blockscout" +multicall2 = "" +chain_id = 1729 + +[onus] +explorer = "https://explorer.onuschain.io/" +explorer_type = "blockscout" +multicall2 = "" +chain_id = 1975 + +[hubblenet] +explorer = "" +multicall2 = "" +chain_id = 1992 + +[sanko] +explorer = "https://explorer.sanko.xyz/" +explorer_type = "blockscout" +multicall2 = "" +chain_id = 1996 + +[dogechain] +explorer = "https://explorer.dogechain.dog/" +explorer_type = "blockscout" +multicall2 = "" +chain_id = 2000 + +[milkomeda] +explorer = "https://explorer-mainnet-cardano-evm.c1.milkomeda.com/" +explorer_type = "blockscout" +multicall2 = "" +chain_id = 2001 + +[kava] +explorer = "https://testnet.kavascan.com/" +explorer_type = "blockscout" +multicall2 = "" +chain_id = 2222 + +[mantle] +explorer = "https://explorer.mantle.xyz/" +explorer_type = "blockscout" +multicall2 = "" +chain_id = 5000 + +[zetachain] +explorer = "https://zetachain.blockscout.com/" +explorer_type = "blockscout" +multicall2 = "" +chain_id = 7000 + +[celo] +explorer = "https://explorer.celo.org/mainnet/" +explorer_type = "blockscout" +multicall2 = "" +chain_id = 42220 + +[oasis] +explorer = "https://explorer.emerald.oasis.dev/" +explorer_type = "blockscout" +multicall2 = "" +chain_id = 42262 + +[linea] +explorer = "https://explorer.linea.build/" +explorer_type = "blockscout" +multicall2 = "" +chain_id = 59144 + +[blast] +explorer = "https://blast.blockscout.com/" +explorer_type = "blockscout" +multicall2 = "" +chain_id = 81457 + +[taiko] +explorer = "https://blockscoutapi.mainnet.taiko.xyz/" +explorer_type = "blockscout" +multicall2 = "" +chain_id = 167000 + +[scroll] +explorer = "https://blockscout.scroll.io/" +explorer_type = "blockscout" +multicall2 = "" +chain_id = 534352 + +[zora] +explorer = "https://explorer.zora.energy/" +explorer_type = "blockscout" +multicall2 = "" +chain_id = 7777777 + +[neon] +explorer = "https://neon.blockscout.com/" +explorer_type = "blockscout" +multicall2 = "" +chain_id = 245022934 + +[aurora] +explorer = "https://explorer.mainnet.aurora.dev/" +explorer_type = "blockscout" +multicall2 = "" +chain_id = 1313161554 diff --git a/docs/source/_autogenerated/fork_defaults.rst b/docs/source/_autogenerated/fork_defaults.rst new file mode 100644 index 0000000..da6769e --- /dev/null +++ b/docs/source/_autogenerated/fork_defaults.rst @@ -0,0 +1,4 @@ +is_zksync = false +prompt_live = false +save_to_db = false +live_or_staging = false diff --git a/docs/source/_autogenerated/pyevm_defaults.rst b/docs/source/_autogenerated/pyevm_defaults.rst new file mode 100644 index 0000000..da6769e --- /dev/null +++ b/docs/source/_autogenerated/pyevm_defaults.rst @@ -0,0 +1,4 @@ +is_zksync = false +prompt_live = false +save_to_db = false +live_or_staging = false diff --git a/docs/source/_generate_vars.py b/docs/source/_generate_vars.py new file mode 100644 index 0000000..e9ad089 --- /dev/null +++ b/docs/source/_generate_vars.py @@ -0,0 +1,43 @@ +from pathlib import Path + +import tomli_w + +from moccasin.constants.vars import ( + DEFAULT_NETWORKS_BY_NAME, + ERAVM, + FORK_NETWORK_DEFAULTS, + LOCAL_NETWORK_DEFAULTS, + PYEVM, +) + +AUTOGENERATED_DIR = Path(__file__).parent.joinpath("_autogenerated") + +PYEVM_FILE = "pyevm_defaults.rst" +ERAVM_FILE = "eravm_defaults.rst" +FORKS_FILE = "fork_defaults.rst" +EXPLORER_FILE = "explorer_defaults.rst" + + +def clean_dict_for_toml(networks_dict): + cleaned = {} + for network, config in networks_dict.items(): + cleaned[network] = {k: ("" if v is None else v) for k, v in config.items()} + return cleaned + + +if __name__ == "__main__": + with open(AUTOGENERATED_DIR.joinpath(PYEVM_FILE), "wb") as f: + defaults = LOCAL_NETWORK_DEFAULTS[PYEVM] + tomli_w.dump(defaults, f) + + with open(AUTOGENERATED_DIR.joinpath(ERAVM_FILE), "wb") as f: + defaults = LOCAL_NETWORK_DEFAULTS[ERAVM] + tomli_w.dump(defaults, f) + + with open(AUTOGENERATED_DIR.joinpath(FORKS_FILE), "wb") as f: + defaults = FORK_NETWORK_DEFAULTS + tomli_w.dump(defaults, f) + + with open(AUTOGENERATED_DIR.joinpath(EXPLORER_FILE), "wb") as f: + defaults = clean_dict_for_toml(DEFAULT_NETWORKS_BY_NAME) + tomli_w.dump(defaults, f) diff --git a/docs/source/conf.py b/docs/source/conf.py index 6fe11e3..023c942 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -31,7 +31,7 @@ master_doc = "toctree" templates_path = ["_templates"] -exclude_patterns = [".DS_Store"] +exclude_patterns = [".DS_Store", "_autogenerated/*.rst", "coming_soon.rst"] # -- Options for HTML output ------------------------------------------------- # https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output diff --git a/docs/source/core_concepts/moccasin_toml.rst b/docs/source/core_concepts/moccasin_toml.rst index 769dc9b..b6322fb 100644 --- a/docs/source/core_concepts/moccasin_toml.rst +++ b/docs/source/core_concepts/moccasin_toml.rst @@ -51,6 +51,40 @@ Extra data is a dictionary of data where you can put whatever you'd like. You ca from moccasin import config print(config.get_config().extra_data["my_key"]) +``pyproject.toml`` +================== + +If you like, you don't even need to use a ``moccasin.toml``, and instead you can just use a normal ``pyproject.toml`` file. + +.. important:: + + If you have a ``moccasin.toml`` file, that file will have precedence over the ``pyproject.toml`` file. So if you have a parameter defined in both files, the value in the ``moccasin.toml`` file will be used. + + +An example ``pyproject.toml`` with a ``moccasin`` section would look like this: + +.. code-block:: toml + + # unrelated to your moccasin project, aka, "normal" python project settings + [project] + name = "project-no-config" + version = "0.1.0" + description = "Add your description here" + readme = "README.md" + requires-python = ">=3.11, <=3.13" + dependencies = [] + + # moccasin project settings + [tool.moccasin.project] + src = "contracts" + dot_env = ".hello" + + [tool.moccasin.networks.sepolia] + url = "https://ethereum-sepolia-rpc.publicnode.com" + +You have all the same options as you would in a ``moccasin.toml`` file, you'll just need to prepend each with ``[tool.moccasin]``. + + Order Of Operations =================== @@ -59,8 +93,10 @@ Whenever you run a script, you'll want to remember this order: 1. Script 2. Command Line 3. ``moccasin.toml`` -4. Defaults +4. ``pyproject.toml`` +5. Defaults + +Whatever you place in your python script, will be the value used, even if your command line has a different value. Similarly, any flag passed to the command line will override any values in your ``moccasin.toml``, which will override any values in ``pyproject.toml``, which will override default values moccasin sets. -Whatever you place in your python script, will be the value used, even if your command line has a different value. Similarly, any flag passed to the command line will override any values in your ``moccasin.toml``, which will override any default values moccasin sets. +This allows you to set your config file up, but if you want to make a tweak you don't have to touch your source code, you can just adjust it on the fly! -This allows you to set your config file up, but if you want to make a tweak you don't have to touch your source code, you can just adjust it on the fly! \ No newline at end of file diff --git a/docs/source/core_concepts/networks.rst b/docs/source/core_concepts/networks.rst index 84f80d9..3bcf427 100644 --- a/docs/source/core_concepts/networks.rst +++ b/docs/source/core_concepts/networks.rst @@ -1,7 +1,7 @@ Networks ======== -Networks in `moccasin` are identified in your ``moccasin.toml``. The complete list of options you can set for your network can be identified in the example here: +Networks in ``moccasin`` are identified in your ``moccasin.toml``. The complete list of options you can set for your network can be identified in the example here: .. code-block:: toml @@ -16,32 +16,37 @@ Networks in `moccasin` are identified in your ``moccasin.toml``. The complete li save_to_db = true db_path = ".deployments.db" -Let's walk through what each of these options mean. +Let's walk through some of the options here. -- `url`: The URL of the network you are connecting to. -- `chain_id`: The chain ID of the network you are connecting to. -- `is_fork`: If you are forking a network, set this to `true`. -- `is_zksync`: If you are connecting to a zkSync network, set this to `true`. -- `default_account_name`: The default account name to use when deploying contracts. This will be the name of your account you created with your :doc:`wallet ` command. -- `unsafe_password_file`: The location of the password file for your account. This is a file that contains the password for your account. BE SURE TO NEVER PUSH THIS PASSWORD TO GITHUB IF YOU USE THIS. -- `extra-data`: This is a dictionary of extra data you can use in your contracts. -- `save_to_db`: If you want to save your :doc:`deployments ` to a database. -- `db_path`: The database path of your :doc:`deployments `. +.. note:: -You'll notice there is no `private-key`. We highly discourage having private keys in plain text. + You can see a full list of options in the :doc:`all moccasin toml parameters page`. -When working with a network from the command line, for example to :doc:`run a script