diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e23494a34..dc65ba0e3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -165,7 +165,7 @@ jobs: run: | make fetch-ssj-artifacts cp .env.example .env - make run-katana & make test-end-to-end + make run-nodes & make test-end-to-end ef-tests: runs-on: ubuntu-latest-32-cores diff --git a/README.md b/README.md index fd5088e33..6a710feab 100644 --- a/README.md +++ b/README.md @@ -161,8 +161,8 @@ make test # Run only unit tests make test-unit -# Run only integration tests -make test-integration +# Run only e2e tests +make test-end-to-end # Run a specific test file pytest diff --git a/deployments/kakarot-sepolia/l1-addresses.json b/deployments/kakarot-sepolia/l1-addresses.json index 28762965e..a365173e0 100644 --- a/deployments/kakarot-sepolia/l1-addresses.json +++ b/deployments/kakarot-sepolia/l1-addresses.json @@ -1,5 +1,5 @@ { - "StarknetMessagingLocal": { + "StarknetCore": { "address": "0x74ca1ac5bd4c3c97006d2b7b9375dd3b6c17accd" } } diff --git a/deployments/kakarot-staging/l1-addresses.json b/deployments/kakarot-staging/l1-addresses.json index c2f3d9aa3..ab00407ec 100644 --- a/deployments/kakarot-staging/l1-addresses.json +++ b/deployments/kakarot-staging/l1-addresses.json @@ -1,5 +1,5 @@ { - "StarknetMessagingLocal": { + "StarknetCore": { "address": "0xc7c9ea7fD0921Cb6EDd9a3184F88cF1b821aA82B" } } diff --git a/kakarot_scripts/constants.py b/kakarot_scripts/constants.py index 7a93796c2..64c621637 100644 --- a/kakarot_scripts/constants.py +++ b/kakarot_scripts/constants.py @@ -34,6 +34,7 @@ class NetworkType(Enum): "name": "mainnet", "explorer_url": "https://starkscan.co", "rpc_url": f"https://starknet-mainnet.infura.io/v3/{os.getenv('INFURA_KEY')}", + "l1_rpc_url": f"https://mainnet.infura.io/v3/{os.getenv('INFURA_KEY')}", "type": NetworkType.PROD, "chain_id": StarknetChainId.MAINNET, }, @@ -41,6 +42,7 @@ class NetworkType(Enum): "name": "starknet-goerli", "explorer_url": "https://testnet.starkscan.co", "rpc_url": f"https://starknet-goerli.infura.io/v3/{os.getenv('INFURA_KEY')}", + "l1_rpc_url": f"https://goerli.infura.io/v3/{os.getenv('INFURA_KEY')}", "type": NetworkType.PROD, "chain_id": StarknetChainId.GOERLI, }, @@ -48,6 +50,7 @@ class NetworkType(Enum): "name": "starknet-sepolia", "explorer_url": "https://sepolia.starkscan.co/", "rpc_url": "https://starknet-sepolia.public.blastapi.io/rpc/v0_6", + "l1_rpc_url": f"https://sepolia.infura.io/v3/{os.getenv('INFURA_KEY')}", "type": NetworkType.PROD, "chain_id": StarknetChainId.SEPOLIA_TESTNET, "check_interval": 5, @@ -57,6 +60,7 @@ class NetworkType(Enum): "name": "starknet-devnet", "explorer_url": "", "rpc_url": "http://127.0.0.1:5050/rpc", + "l1_rpc_url": "http://127.0.0.1:8545", "type": NetworkType.DEV, "check_interval": 0.01, "max_wait": 1, @@ -65,6 +69,7 @@ class NetworkType(Enum): "name": "katana", "explorer_url": "", "rpc_url": os.getenv("KATANA_RPC_URL", "http://127.0.0.1:5050"), + "l1_rpc_url": "http://127.0.0.1:8545", "type": NetworkType.DEV, "check_interval": 0.01, "max_wait": 2, @@ -73,6 +78,7 @@ class NetworkType(Enum): "name": "madara", "explorer_url": "", "rpc_url": os.getenv("MADARA_RPC_URL", "http://127.0.0.1:9944"), + "l1_rpc_url": "http://127.0.0.1:8545", "type": NetworkType.DEV, "check_interval": 6, "max_wait": 30, @@ -81,6 +87,7 @@ class NetworkType(Enum): "name": "sharingan", "explorer_url": "", "rpc_url": os.getenv("SHARINGAN_RPC_URL"), + "l1_rpc_url": "http://127.0.0.1:8545", "type": NetworkType.PROD, "check_interval": 6, "max_wait": 30, @@ -89,6 +96,7 @@ class NetworkType(Enum): "name": "kakarot-sepolia", "explorer_url": "", "rpc_url": os.getenv("KAKAROT_SEPOLIA_RPC_URL"), + "l1_rpc_url": f"https://sepolia.infura.io/v3/{os.getenv('INFURA_KEY')}", "type": NetworkType.PROD, "check_interval": 6, "max_wait": 360, @@ -97,6 +105,7 @@ class NetworkType(Enum): "name": "kakarot-staging", "explorer_url": "", "rpc_url": os.getenv("KAKAROT_STAGING_RPC_URL"), + "l1_rpc_url": f"https://sepolia.infura.io/v3/{os.getenv('INFURA_KEY')}", "type": NetworkType.STAGING, "check_interval": 1, "max_wait": 30, @@ -135,6 +144,7 @@ class NetworkType(Enum): NETWORK["private_key"] = os.getenv("PRIVATE_KEY") RPC_CLIENT = FullNodeClient(node_url=NETWORK["rpc_url"]) +L1_RPC_PROVIDER = Web3(Web3.HTTPProvider(NETWORK["l1_rpc_url"])) WEB3 = Web3() try: @@ -195,7 +205,7 @@ class ArtifactType(Enum): DEPLOYMENTS_DIR = Path("deployments") / NETWORK["name"] DEPLOYMENTS_DIR.mkdir(exist_ok=True, parents=True) -L1_ADDRESSES_DIR = Path("l1-addresses") / NETWORK["name"] +L1_ADDRESSES_DIR = Path("deployments") / NETWORK["name"] / "l1-addresses" L1_ADDRESSES_DIR.mkdir(exist_ok=True, parents=True) COMPILED_CONTRACTS = [ diff --git a/kakarot_scripts/utils/l1.py b/kakarot_scripts/utils/l1.py index a30d15bc1..86a7fde4d 100644 --- a/kakarot_scripts/utils/l1.py +++ b/kakarot_scripts/utils/l1.py @@ -11,7 +11,12 @@ from web3.contract import Contract as Web3Contract from web3.exceptions import NoABIFunctionsFound -from kakarot_scripts.constants import EVM_ADDRESS, EVM_PRIVATE_KEY, L1_ADDRESSES_DIR +from kakarot_scripts.constants import ( + EVM_ADDRESS, + EVM_PRIVATE_KEY, + L1_ADDRESSES_DIR, + L1_RPC_PROVIDER, +) from kakarot_scripts.utils.kakarot import ( EvmTransactionError, _parse_events, @@ -25,13 +30,10 @@ logger.setLevel(logging.INFO) -anvil_url = "http://127.0.0.1:8545" -anvil_provider = Web3(Web3.HTTPProvider(anvil_url)) - -if anvil_provider.is_connected(): - logger.info("ℹ️ Connected to Anvil for local development") +if L1_RPC_PROVIDER.is_connected(): + logger.info("ℹ️ Connected to L1 RPC") else: - print("Failed to connect to Anvil") + print("Failed to connect to L1 RPC") def dump_l1_addresses(deployments): @@ -62,7 +64,7 @@ def get_l1_addresses(): def l1_contract_exists(address: HexBytes) -> bool: try: - code = anvil_provider.eth.get_code(address) + code = L1_RPC_PROVIDER.eth.get_code(address) if len(code) != 0: logger.info(f"ℹ️ Contract at address {address} already exists") return True @@ -109,7 +111,7 @@ def get_l1_contract( contract = cast( Web3Contract, - anvil_provider.eth.contract( + L1_RPC_PROVIDER.eth.contract( address=to_checksum_address(address) if address is not None else address, abi=artifacts["abi"], bytecode=artifacts["bytecode"], @@ -135,10 +137,10 @@ async def send_l1_transaction( ): """Execute the data at the EVM contract on an L1 node.""" evm_account = caller_eoa or EvmAccount.from_key(EVM_PRIVATE_KEY) - nonce = anvil_provider.eth.get_transaction_count(evm_account.address) + nonce = L1_RPC_PROVIDER.eth.get_transaction_count(evm_account.address) payload = { "type": 0x2, - "chainId": anvil_provider.eth.chain_id, + "chainId": L1_RPC_PROVIDER.eth.chain_id, "nonce": nonce, "gas": gas, "maxPriorityFeePerGas": 1, @@ -155,11 +157,11 @@ async def send_l1_transaction( evm_account.key, ) - tx_hash = anvil_provider.eth.send_raw_transaction(evm_tx.rawTransaction) - receipt = anvil_provider.eth.wait_for_transaction_receipt(tx_hash) + tx_hash = L1_RPC_PROVIDER.eth.send_raw_transaction(evm_tx.rawTransaction) + receipt = L1_RPC_PROVIDER.eth.wait_for_transaction_receipt(tx_hash) response = [] if not receipt.status: - trace = anvil_provider.manager.request_blocking( + trace = L1_RPC_PROVIDER.manager.request_blocking( "debug_traceTransaction", [tx_hash, {"tracer": "callTracer"}] ) response = bytes(HexBytes(trace["returnValue"])) @@ -185,7 +187,7 @@ async def _wrapper(self, *args, **kwargs): if caller_eoa_ else int(EVM_ADDRESS, 16) ) - nonce = anvil_provider.eth.get_transaction_count( + nonce = L1_RPC_PROVIDER.eth.get_transaction_count( Web3.to_checksum_address(f"{origin:040x}") ) payload = { @@ -198,7 +200,7 @@ async def _wrapper(self, *args, **kwargs): "data": HexBytes(calldata), "access_list": [], } - result = anvil_provider.eth.call(payload) + result = L1_RPC_PROVIDER.eth.call(payload) return result logger.info(f"⏳ Executing {fun} at address {self.address}") diff --git a/l1-addresses/katana/l1-addresses.json b/l1-addresses/katana/l1-addresses.json deleted file mode 100644 index 69e463f9f..000000000 --- a/l1-addresses/katana/l1-addresses.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "StarknetMessagingLocal": { - "address": "0x5FbDB2315678afecb367f032d93F642f64180aa3" - } -} \ No newline at end of file diff --git a/solidity_contracts/src/L1L2Messaging/L1Receiver.sol b/solidity_contracts/src/L1L2Messaging/MessageConsumerTest.sol similarity index 87% rename from solidity_contracts/src/L1L2Messaging/L1Receiver.sol rename to solidity_contracts/src/L1L2Messaging/MessageConsumerTest.sol index 6b7744db9..f7567bb50 100644 --- a/solidity_contracts/src/L1L2Messaging/L1Receiver.sol +++ b/solidity_contracts/src/L1L2Messaging/MessageConsumerTest.sol @@ -12,21 +12,21 @@ error InvalidPayload(); @title Test contract to receive / send messages to starknet. @author Glihm https://github.com/glihm/starknet-messaging-dev */ -contract L1Receiver { +contract MessageConsumerTest { // - IStarknetMessaging private _snMessaging; + IStarknetMessaging private _starknetMessaging; uint256 private _cairoMessaging; /** @notice Constructor. @param snMessaging The address of Starknet Core contract, responsible - or messaging. + for messaging. @param cairoMessaging The address, on L2, of the Cairo contract that relays Kakarot messages. */ constructor(address snMessaging, uint256 cairoMessaging) { - _snMessaging = IStarknetMessaging(snMessaging); + _starknetMessaging = IStarknetMessaging(snMessaging); _cairoMessaging = cairoMessaging; } @@ -49,7 +49,7 @@ contract L1Receiver { external payable { - _snMessaging.sendMessageToL2{value: msg.value}( + _starknetMessaging.sendMessageToL2{value: msg.value}( contractAddress, selector, payload @@ -71,7 +71,7 @@ contract L1Receiver { uint256[] memory payload = new uint256[](1); payload[0] = value; - _snMessaging.sendMessageToL2{value: msg.value}( + _starknetMessaging.sendMessageToL2{value: msg.value}( contractAddress, selector, payload @@ -93,7 +93,7 @@ contract L1Receiver { external { // Will revert if the message is not consumable. - bytes32 msghash = _snMessaging.consumeMessageFromL2(_cairoMessaging, payload); + bytes32 msghash = _starknetMessaging.consumeMessageFromL2(_cairoMessaging, payload); // The previous call returns the message hash (bytes32) // that can be used if necessary. @@ -113,7 +113,7 @@ contract L1Receiver { ) external { - _snMessaging.consumeMessageFromL2(fromAddress, payload); + _starknetMessaging.consumeMessageFromL2(fromAddress, payload); // We expect the payload to contain only a felt252 value (which is a uint256 in solidity). if (payload.length != 1) { @@ -133,7 +133,7 @@ contract L1Receiver { ) external { - _snMessaging.consumeMessageFromL2(fromAddress, payload); + _starknetMessaging.consumeMessageFromL2(fromAddress, payload); // We expect the payload to contain field `a` and `b` from `MyData`. if (payload.length != 2) { diff --git a/tests/end_to_end/L1L2Messaging/test_messaging.py b/tests/end_to_end/L1L2Messaging/test_messaging.py index 2bf10aa81..e361e3fc8 100644 --- a/tests/end_to_end/L1L2Messaging/test_messaging.py +++ b/tests/end_to_end/L1L2Messaging/test_messaging.py @@ -13,9 +13,8 @@ @pytest.fixture(scope="session") async def sn_messaging_local(deploy_l1_contract, owner): - # If the contract is already deployed on the anvil instance, we can get the address from the deployments file + # If the contract is already deployed on the l1, we can get the address from the deployments file # Otherwise, we deploy it - l1_addresses = get_l1_addresses() if l1_addresses.get("StarknetMessagingLocal"): address = l1_addresses["StarknetMessagingLocal"]["address"] @@ -51,11 +50,11 @@ async def message_sender_l2(deploy_contract, owner): @pytest.fixture(scope="session") -async def l1_receiver(deploy_l1_contract, sn_messaging_local): +async def message_consumer_test(deploy_l1_contract, sn_messaging_local): cairo_messaging_address = get_deployments()["CairoMessaging"]["address"] return await deploy_l1_contract( "L1L2Messaging", - "L1Receiver", + "MessageConsumerTest", sn_messaging_local.address, cairo_messaging_address, ) @@ -73,8 +72,8 @@ async def wait_for_message(sn_messaging_local): async def test_should_send_message_to_l1( - sn_messaging_local, l1_receiver, message_sender_l2 + sn_messaging_local, message_consumer_test, message_sender_l2 ): - await message_sender_l2.sendMessageToL1(l1_receiver.address, 42) + await message_sender_l2.sendMessageToL1(message_consumer_test.address, 42) await wait_for_message(sn_messaging_local) - await l1_receiver.consumeMessage([42]) + await message_consumer_test.consumeMessage([42])