From a63a987fe696db20a0b236542c29792655a7bc66 Mon Sep 17 00:00:00 2001 From: greged93 <82421016+greged93@users.noreply.github.com> Date: Mon, 10 Jun 2024 19:16:46 +0200 Subject: [PATCH] redeploy + some fixes (#1196) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Time spent on this PR: 0.3 day ## Pull request type Please check the type of change your PR introduces: - [x] Bugfix - [ ] Feature - [ ] Code style update (formatting, renaming) - [ ] Refactoring (no functional changes, no api changes) - [ ] Build related changes - [ ] Documentation content changes - [ ] Other (please describe): ## What is the current behavior? Staging can't run correctly currently. Resolves #NA ## What is the new behavior? - Upgrades Kakarot on staging - Adds a type of network "staging" which allows upgrades but also uses the "EVM" fixture. - - - This change is [Reviewable](https://reviewable.io/reviews/kkrt-labs/kakarot/1196) --- deployments/kakarot-staging/declarations.json | 4 +-- deployments/kakarot-staging/deployments.json | 4 +-- kakarot_scripts/constants.py | 27 ++++++++++++------- kakarot_scripts/deploy_kakarot.py | 26 +++++++++++++++--- kakarot_scripts/utils/starknet.py | 27 +++++++++++++++++-- tests/end_to_end/conftest.py | 3 ++- 6 files changed, 71 insertions(+), 20 deletions(-) diff --git a/deployments/kakarot-staging/declarations.json b/deployments/kakarot-staging/declarations.json index 1883c3317..03ed7e86e 100644 --- a/deployments/kakarot-staging/declarations.json +++ b/deployments/kakarot-staging/declarations.json @@ -1,9 +1,9 @@ { - "kakarot": "0x7a4394ca8608f89bb947e81d364e18a3651369c67ec1f008ae2b9fae3dee69a", + "kakarot": "0x701a9ab6675823700bb14629c63683f720ffbb57dc445d6c87ebfea8e55904a", "account_contract": "0x1276d0b017701646f8646b69de6c3b3584edce71879678a679f28c07a9971cf", "account_contract_fixture": "0x3a247bfdb923a0e950871336d9ffd9d1d052ef79ce31909954f5c2e81e77e00", "uninitialized_account": "0x600f6862938312a05a0cfecba0dcaf37693efc9e4075a6adfb62e196022678e", - "EVM": "0x7f14daf9420729ca261433e62404b0415c308e15f7f6fc576f665110e2ac8b9", + "EVM": "0x76157e8119e18e6df44c7f7511857136898480104422510463462e1b1c149e5", "OpenzeppelinAccount": "0x6153ccf69fd20f832c794df36e19135f0070d0576144f0b47f75a226e4be530", "Cairo1Helpers": "0x28ece3751ecf5bdf2d791eb64a65bfb6a8816432b698870dba2f38a36101d58", "Cairo1HelpersFixture": "0x4e7811d9bbba41193bd3c77d05c16f7aaa55dd1d601686b50f6fa0e3766a712", diff --git a/deployments/kakarot-staging/deployments.json b/deployments/kakarot-staging/deployments.json index 20bf499ec..4e13b4368 100644 --- a/deployments/kakarot-staging/deployments.json +++ b/deployments/kakarot-staging/deployments.json @@ -5,8 +5,8 @@ "artifact": "build/kakarot.json" }, "EVM": { - "address": "0x75902a70542cd56454643f9c3fead34d3acb77012ed4c4a0356bcd044a73dc4", - "tx": "0x40c861ad7dcb7a5fd90f0d3164c99c6e6e9d746820f9a0fa34f98d2f9c22bdc", + "address": "0x4a64f9b67916a4496dd3ca2321dd1f5739d0dff33c0930684da1c695691c88f", + "tx": "0x7a805d7b596283b7d56afaded869f0384379cd99faf28ba6ca1e1aa098497d2", "artifact": "build/fixtures/EVM.json" }, "Counter": { diff --git a/kakarot_scripts/constants.py b/kakarot_scripts/constants.py index 03ea193d7..3e133ce6e 100644 --- a/kakarot_scripts/constants.py +++ b/kakarot_scripts/constants.py @@ -22,26 +22,33 @@ BEACON_ROOT_ADDRESS = "0x000F3df6D732807Ef1319fB7B8bB8522d0Beac02" + +class NetworkType(Enum): + PROD = "prod" + DEV = "dev" + STAGING = "staging" + + NETWORKS = { "mainnet": { "name": "mainnet", "explorer_url": "https://starkscan.co", "rpc_url": f"https://starknet-mainnet.infura.io/v3/{os.getenv('INFURA_KEY')}", - "devnet": False, + "type": NetworkType.PROD, "chain_id": StarknetChainId.MAINNET, }, "goerli": { "name": "starknet-goerli", "explorer_url": "https://testnet.starkscan.co", "rpc_url": f"https://starknet-goerli.infura.io/v3/{os.getenv('INFURA_KEY')}", - "devnet": False, + "type": NetworkType.PROD, "chain_id": StarknetChainId.GOERLI, }, "sepolia": { "name": "starknet-sepolia", "explorer_url": "https://sepolia.starkscan.co/", "rpc_url": "https://starknet-sepolia.public.blastapi.io/rpc/v0_6", - "devnet": False, + "type": NetworkType.PROD, "chain_id": StarknetChainId.SEPOLIA_TESTNET, "check_interval": 5, "max_wait": 30, @@ -50,7 +57,7 @@ "name": "starknet-devnet", "explorer_url": "", "rpc_url": "http://127.0.0.1:5050/rpc", - "devnet": True, + "type": NetworkType.DEV, "check_interval": 0.01, "max_wait": 1, }, @@ -58,7 +65,7 @@ "name": "katana", "explorer_url": "", "rpc_url": os.getenv("KATANA_RPC_URL", "http://127.0.0.1:5050"), - "devnet": True, + "type": NetworkType.DEV, "check_interval": 0.01, "max_wait": 2, }, @@ -66,7 +73,7 @@ "name": "madara", "explorer_url": "", "rpc_url": os.getenv("MADARA_RPC_URL", "http://127.0.0.1:9944"), - "devnet": False, + "type": NetworkType.DEV, "check_interval": 6, "max_wait": 30, }, @@ -74,7 +81,7 @@ "name": "sharingan", "explorer_url": "", "rpc_url": os.getenv("SHARINGAN_RPC_URL"), - "devnet": False, + "type": NetworkType.PROD, "check_interval": 6, "max_wait": 30, }, @@ -82,7 +89,7 @@ "name": "kakarot-sepolia", "explorer_url": "", "rpc_url": os.getenv("KAKAROT_SEPOLIA_RPC_URL"), - "devnet": False, + "type": NetworkType.PROD, "check_interval": 6, "max_wait": 360, }, @@ -90,7 +97,7 @@ "name": "kakarot-staging", "explorer_url": "", "rpc_url": os.getenv("KAKAROT_STAGING_RPC_URL"), - "devnet": True, + "type": NetworkType.STAGING, "check_interval": 1, "max_wait": 30, }, @@ -108,7 +115,7 @@ "name": os.getenv("RPC_NAME", "custom-rpc"), "rpc_url": os.getenv("RPC_URL"), "explorer_url": "", - "devnet": False, + "type": NetworkType.PROD, "check_interval": float(os.getenv("CHECK_INTERVAL", 0.1)), "max_wait": float(os.getenv("MAX_WAIT", 30)), } diff --git a/kakarot_scripts/deploy_kakarot.py b/kakarot_scripts/deploy_kakarot.py index bd9964246..4a9019674 100644 --- a/kakarot_scripts/deploy_kakarot.py +++ b/kakarot_scripts/deploy_kakarot.py @@ -10,6 +10,7 @@ EVM_ADDRESS, NETWORK, RPC_CLIENT, + NetworkType, ) from kakarot_scripts.utils.starknet import ( declare, @@ -20,6 +21,7 @@ get_deployments, get_starknet_account, invoke, + upgrade, ) logging.basicConfig() @@ -43,7 +45,7 @@ async def main(): class_hash = get_declarations() deployments = get_deployments() - if deployments.get("kakarot") and not NETWORK["devnet"]: + if deployments.get("kakarot") and NETWORK["type"] is not NetworkType.DEV: logger.info("ℹ️ Kakarot already deployed, checking version.") deployed_class_hash = await RPC_CLIENT.get_class_hash_at( deployments["kakarot"]["address"] @@ -74,7 +76,25 @@ async def main(): BLOCK_GAS_LIMIT, ) - if NETWORK["devnet"]: + if NETWORK["type"] is NetworkType.STAGING: + deployments["EVM"] = await upgrade( + "EVM", + [ + account.address, # owner + ETH_TOKEN_ADDRESS, # native_token_address_ + class_hash["account_contract"], # account_contract_class_hash_ + class_hash[ + "uninitialized_account" + ], # uninitialized_account_class_hash_ + class_hash["Cairo1Helpers"], + COINBASE, + BLOCK_GAS_LIMIT, + ], + ) + deployments["Counter"] = await upgrade("Counter") + deployments["MockPragmaOracle"] = await upgrade("MockPragmaOracle") + + if NETWORK["type"] is NetworkType.DEV: deployments["EVM"] = await deploy( "EVM", account.address, # owner @@ -94,7 +114,7 @@ async def main(): logger.info(f"ℹ️ Found default EVM address {EVM_ADDRESS}") from kakarot_scripts.utils.kakarot import get_eoa - amount = 0.02 if not NETWORK["devnet"] else 100 + amount = 0.02 if NETWORK["type"] is not NetworkType.DEV else 100 await get_eoa(amount=amount) diff --git a/kakarot_scripts/utils/starknet.py b/kakarot_scripts/utils/starknet.py index 2450fa05a..d04f0c022 100644 --- a/kakarot_scripts/utils/starknet.py +++ b/kakarot_scripts/utils/starknet.py @@ -46,6 +46,7 @@ SOURCE_DIR, ArtifactType, ChainId, + NetworkType, ) logging.basicConfig() @@ -308,9 +309,13 @@ def compile_contract(contract): artifact, "--cairo_path", str(SOURCE_DIR), - *(["--no_debug_info"] if not NETWORK["devnet"] else []), + *(["--no_debug_info"] if NETWORK["type"] is not NetworkType.DEV else []), *(["--account_contract"] if contract["is_account_contract"] else []), - *(["--disable_hint_validation"] if NETWORK["devnet"] else []), + *( + ["--disable_hint_validation"] + if NETWORK["type"] is NetworkType.DEV + else [] + ), ], capture_output=True, ) @@ -480,6 +485,24 @@ async def deploy(contract_name, *args): } +async def upgrade(contract_name, *args): + deployments = get_deployments() + if not deployments.get(contract_name): + return await deploy(contract_name, *args) + + logger.info(f"ℹ️ {contract_name} already deployed, checking version.") + class_hash = get_declarations() + + deployed_class_hash = await RPC_CLIENT.get_class_hash_at( + deployments[contract_name]["address"] + ) + if deployed_class_hash != class_hash[contract_name]: + logger.info(f"ℹ️ redeploying {contract_name}.") + return await deploy(contract_name, *args) + + return deployments[contract_name] + + async def invoke_address(contract_address, function_name, *calldata, account=None): account = account or (await get_starknet_account()) logger.info( diff --git a/tests/end_to_end/conftest.py b/tests/end_to_end/conftest.py index 7fabac363..f1788e3d0 100644 --- a/tests/end_to_end/conftest.py +++ b/tests/end_to_end/conftest.py @@ -9,6 +9,7 @@ from starknet_py.contract import Contract from starknet_py.net.account.account import Account +from kakarot_scripts.constants import NetworkType from kakarot_scripts.utils.starknet import wait_for_transaction from tests.utils.helpers import generate_random_private_key @@ -28,7 +29,7 @@ def default_fee(): """ from kakarot_scripts.constants import NETWORK - if NETWORK["devnet"]: + if NETWORK["type"] is NetworkType.DEV: return int(0) else: return int(1e16)