Skip to content
This repository has been archived by the owner on Jan 9, 2025. It is now read-only.

Commit

Permalink
fix CI & address review
Browse files Browse the repository at this point in the history
  • Loading branch information
enitrat committed Jun 12, 2024
1 parent 0ce6a21 commit a9b40e7
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <PATH_TO_FILE>
Expand Down
2 changes: 1 addition & 1 deletion deployments/kakarot-sepolia/l1-addresses.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"StarknetMessagingLocal": {
"StarknetCore": {
"address": "0x74ca1ac5bd4c3c97006d2b7b9375dd3b6c17accd"
}
}
2 changes: 1 addition & 1 deletion deployments/kakarot-staging/l1-addresses.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"StarknetMessagingLocal": {
"StarknetCore": {
"address": "0xc7c9ea7fD0921Cb6EDd9a3184F88cF1b821aA82B"
}
}
12 changes: 11 additions & 1 deletion kakarot_scripts/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,23 @@ 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,
},
"goerli": {
"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,
},
"sepolia": {
"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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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 = [
Expand Down
34 changes: 18 additions & 16 deletions kakarot_scripts/utils/l1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"],
Expand All @@ -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,
Expand All @@ -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"]))
Expand All @@ -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 = {
Expand All @@ -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}")
Expand Down
5 changes: 0 additions & 5 deletions l1-addresses/katana/l1-addresses.json

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -49,7 +49,7 @@ contract L1Receiver {
external
payable
{
_snMessaging.sendMessageToL2{value: msg.value}(
_starknetMessaging.sendMessageToL2{value: msg.value}(
contractAddress,
selector,
payload
Expand All @@ -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
Expand All @@ -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.
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down
13 changes: 6 additions & 7 deletions tests/end_to_end/L1L2Messaging/test_messaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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,
)
Expand All @@ -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])

0 comments on commit a9b40e7

Please sign in to comment.