diff --git a/Cargo.lock b/Cargo.lock index c5416c85d..bc2cbc293 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4002,27 +4002,6 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" -[[package]] -name = "hive-utils" -version = "0.1.0" -dependencies = [ - "cargo-husky", - "eyre", - "kakarot-rpc-core", - "kakarot-test-utils", - "katana-core", - "lazy_static", - "reth-primitives", - "rstest", - "serde", - "serde_json", - "serde_with", - "starknet", - "starknet_api", - "tokio", - "url", -] - [[package]] name = "hmac" version = "0.12.1" @@ -4900,9 +4879,12 @@ dependencies = [ "dotenv", "ethers", "ethers-solc 2.0.9", + "eyre", "foundry-config", "futures", "git2", + "jsonrpsee 0.18.2", + "kakarot-rpc", "kakarot-rpc-core", "katana-core", "lazy_static", @@ -4913,6 +4895,7 @@ dependencies = [ "serde_with", "starknet", "starknet-crypto 0.5.1", + "starknet_api", "tokio", "url", ] diff --git a/Cargo.toml b/Cargo.toml index d09a86265..75909f6af 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [workspace] -members = ["crates/eth-rpc", "crates/core", "crates/hive-utils", "crates/test-utils"] +members = ["crates/eth-rpc", "crates/core", "crates/test-utils"] resolver = "2" [workspace.package] diff --git a/crates/eth-rpc/Cargo.toml b/crates/eth-rpc/Cargo.toml index 469b3d837..9784a4487 100644 --- a/crates/eth-rpc/Cargo.toml +++ b/crates/eth-rpc/Cargo.toml @@ -43,9 +43,9 @@ tracing-subscriber = { version = "0.3.3", features = ["env-filter"] } # for cross-compiling openssl = { version = "0.10", features = ["vendored"] } -kakarot-test-utils = { path = "../test-utils" } [dev-dependencies] cargo-husky = { workspace = true } ethers = { workspace = true } rstest = { workspace = true } +kakarot-test-utils = { path = "../test-utils" } diff --git a/crates/eth-rpc/src/lib.rs b/crates/eth-rpc/src/lib.rs index efc1fe3e0..d4f97854f 100644 --- a/crates/eth-rpc/src/lib.rs +++ b/crates/eth-rpc/src/lib.rs @@ -7,7 +7,6 @@ pub mod api; pub mod config; pub mod rpc; pub mod servers; -pub mod test_utils; use eyre::Result; use jsonrpsee::server::{ServerBuilder, ServerHandle}; diff --git a/crates/eth-rpc/tests/integration.rs b/crates/eth-rpc/tests/integration.rs index 3cb1f0487..49406b7a1 100644 --- a/crates/eth-rpc/tests/integration.rs +++ b/crates/eth-rpc/tests/integration.rs @@ -4,9 +4,9 @@ mod integration_tests { use dotenv::dotenv; use ethers::prelude::{Block as EthersBlock, Http as EthersHttp, H256 as EthersH256}; - use kakarot_rpc::test_utils::start_kakarot_rpc_server; use kakarot_test_utils::deploy_helpers::KakarotTestEnvironmentContext; use kakarot_test_utils::fixtures::kakarot_test_env_ctx; + use kakarot_test_utils::rpc_helpers::start_kakarot_rpc_server; use reth_primitives::U64; use rstest::*; diff --git a/crates/hive-utils/Cargo.toml b/crates/hive-utils/Cargo.toml deleted file mode 100644 index ee7aff2f6..000000000 --- a/crates/hive-utils/Cargo.toml +++ /dev/null @@ -1,30 +0,0 @@ -[package] -name = "hive-utils" -version = { workspace = true } -edition = { workspace = true } -description = { workspace = true } -homepage = { workspace = true } - -[dependencies] -eyre = { workspace = true } -kakarot-rpc-core = { path = "../core" } -lazy_static = { workspace = true } -reth-primitives = { workspace = true } -serde = { workspace = true } -serde_json = { workspace = true } -serde_with = { workspace = true } -starknet = { workspace = true } -starknet_api = { workspace = true } -tokio = { workspace = true } -url = { workspace = true } - -kakarot-test-utils = { path = "../test-utils" } - -[dev-dependencies] -cargo-husky = { workspace = true } -katana-core = { workspace = true } -rstest = { workspace = true } - -[[bin]] -name = "dump-genesis" -path = "src/hive/bin/dump-genesis.rs" diff --git a/crates/test-utils/Cargo.toml b/crates/test-utils/Cargo.toml index b569daddd..b8b2681d0 100644 --- a/crates/test-utils/Cargo.toml +++ b/crates/test-utils/Cargo.toml @@ -13,11 +13,17 @@ license.workspace = true [dependencies] kakarot-rpc-core={ path = "../core" } +kakarot-rpc= { path = "../eth-rpc" } + +# rpc +jsonrpsee = { workspace = true } dojo-test-utils = { workspace = true } +eyre = { workspace = true } katana-core = { workspace = true } reth-primitives = { workspace = true } starknet = { workspace = true } +starknet_api = { workspace = true } starknet-crypto = { workspace = true } url = { workspace = true } @@ -44,3 +50,7 @@ dump = ["git2"] name = "dump-katana" path = "src/bin/dump-katana.rs" required-features = ["dump"] + +[[bin]] +name = "dump-genesis" +path = "src/bin/dump-genesis.rs" diff --git a/crates/hive-utils/src/hive/bin/dump-genesis.rs b/crates/test-utils/src/bin/dump-genesis.rs similarity index 76% rename from crates/hive-utils/src/hive/bin/dump-genesis.rs rename to crates/test-utils/src/bin/dump-genesis.rs index dcbb48361..e6f238e19 100644 --- a/crates/hive-utils/src/hive/bin/dump-genesis.rs +++ b/crates/test-utils/src/bin/dump-genesis.rs @@ -1,6 +1,8 @@ use std::path::Path; -use hive_utils::hive::genesis::{serialize_hive_to_madara_genesis_config, GenesisLoader, HiveGenesisConfig}; +use kakarot_test_utils::hive_utils::hive::genesis::{ + serialize_hive_to_madara_genesis_config, GenesisLoader, HiveGenesisConfig, +}; #[tokio::main] async fn main() { @@ -9,7 +11,8 @@ async fn main() { // Read the madara genesis let madara_loader = - serde_json::from_str::(std::include_str!("../../test_data/madara_genesis.json")).unwrap(); + serde_json::from_str::(std::include_str!("../hive_utils/test_data/madara_genesis.json")) + .unwrap(); let combined_genesis = Path::new(".hive/genesis.json"); let compiled_path = Path::new("cairo-contracts/kakarot"); diff --git a/crates/hive-utils/Dockerfile b/crates/test-utils/src/hive_utils/Dockerfile similarity index 100% rename from crates/hive-utils/Dockerfile rename to crates/test-utils/src/hive_utils/Dockerfile diff --git a/crates/hive-utils/src/hive/genesis.rs b/crates/test-utils/src/hive_utils/hive/genesis.rs similarity index 94% rename from crates/hive-utils/src/hive/genesis.rs rename to crates/test-utils/src/hive_utils/hive/genesis.rs index 75fc1490d..6aed0f43e 100644 --- a/crates/hive-utils/src/hive/genesis.rs +++ b/crates/test-utils/src/hive_utils/hive/genesis.rs @@ -6,18 +6,18 @@ use std::path::Path; use eyre::Result; use kakarot_rpc_core::client::constants::STARKNET_NATIVE_TOKEN; use kakarot_rpc_core::models::felt::Felt252Wrapper; -use kakarot_test_utils::deploy_helpers::compute_kakarot_contracts_class_hash; use lazy_static::lazy_static; use reth_primitives::{Address, Bytes, H256, U256, U64}; use serde::{Deserialize, Serialize}; use starknet::core::types::FieldElement; -use crate::kakarot::compute_starknet_address; -use crate::madara::utils::{ +use crate::deploy_helpers::compute_kakarot_contracts_class_hash; +use crate::hive_utils::kakarot::compute_starknet_address; +use crate::hive_utils::madara::utils::{ genesis_approve_kakarot, genesis_fund_starknet_address, genesis_set_bytecode, genesis_set_storage_kakarot_contract_account, genesis_set_storage_starknet_contract, }; -use crate::types::{ClassHash, ContractAddress, ContractStorageKey, Felt, StorageValue}; +use crate::hive_utils::types::{ClassHash, ContractAddress, ContractStorageKey, Felt, StorageValue}; #[derive(Deserialize, Serialize)] pub struct GenesisLoader { @@ -261,7 +261,7 @@ mod tests { #[test] fn test_read_hive_genesis() { // Read the hive genesis file - let genesis = HiveGenesisConfig::from_file("./src/test_data/hive_genesis.json").unwrap(); + let genesis = HiveGenesisConfig::from_file("./src/hive_utils/test_data/hive_genesis.json").unwrap(); // Verify the genesis file has the expected number of accounts assert_eq!(genesis.alloc.len(), 7); @@ -300,10 +300,10 @@ mod tests { #[tokio::test] async fn test_madara_genesis() { // Given - let hive_genesis = HiveGenesisConfig::from_file("./src/test_data/hive_genesis.json").unwrap(); + let hive_genesis = HiveGenesisConfig::from_file("./src/hive_utils/test_data/hive_genesis.json").unwrap(); let madara_loader = serde_json::from_str::(std::include_str!("../test_data/madara_genesis.json")).unwrap(); - let combined_genesis = Path::new("./src/test_data/combined_genesis.json"); + let combined_genesis = Path::new("./src/hive_utils/test_data/combined_genesis.json"); let compiled_path = Path::new("./cairo-contracts/build"); // When @@ -312,12 +312,12 @@ mod tests { .unwrap(); // Then - let combined_genesis = fs::read_to_string("./src/test_data/combined_genesis.json").unwrap(); + let combined_genesis = fs::read_to_string("./src/hive_utils/test_data/combined_genesis.json").unwrap(); let loader: GenesisLoader = serde_json::from_str(&combined_genesis).expect("Failed to read combined_genesis.json"); assert_eq!(9 + 3 + 7, loader.contracts.len()); // 9 original + 3 Kakarot contracts + 7 hive // After - fs::remove_file("./src/test_data/combined_genesis.json").unwrap(); + fs::remove_file("./src/hive_utils/test_data/combined_genesis.json").unwrap(); } } diff --git a/crates/hive-utils/src/hive/mod.rs b/crates/test-utils/src/hive_utils/hive/mod.rs similarity index 100% rename from crates/hive-utils/src/hive/mod.rs rename to crates/test-utils/src/hive_utils/hive/mod.rs diff --git a/crates/hive-utils/src/kakarot.rs b/crates/test-utils/src/hive_utils/kakarot.rs similarity index 94% rename from crates/hive-utils/src/kakarot.rs rename to crates/test-utils/src/hive_utils/kakarot.rs index 3997d58f2..77a496310 100644 --- a/crates/hive-utils/src/kakarot.rs +++ b/crates/test-utils/src/hive_utils/kakarot.rs @@ -27,12 +27,12 @@ pub fn compute_starknet_address( #[cfg(test)] mod tests { use kakarot_rpc_core::mock::constants::ACCOUNT_ADDRESS; - use kakarot_test_utils::deploy_helpers::KakarotTestEnvironmentContext; - use kakarot_test_utils::fixtures::kakarot_test_env_ctx; use rstest::*; use starknet::core::types::{BlockId, BlockTag}; use super::compute_starknet_address; + use crate::deploy_helpers::KakarotTestEnvironmentContext; + use crate::fixtures::kakarot_test_env_ctx; /// This test is done against the Kakarot system deployed on the Starknet test sequencer. /// It tests the compute_starknet_address function by comparing the result of the computation diff --git a/crates/hive-utils/src/madara/mod.rs b/crates/test-utils/src/hive_utils/madara/mod.rs similarity index 100% rename from crates/hive-utils/src/madara/mod.rs rename to crates/test-utils/src/hive_utils/madara/mod.rs diff --git a/crates/hive-utils/src/madara/utils.rs b/crates/test-utils/src/hive_utils/madara/utils.rs similarity index 99% rename from crates/hive-utils/src/madara/utils.rs rename to crates/test-utils/src/hive_utils/madara/utils.rs index e55c98d00..2a4a7d5fe 100644 --- a/crates/hive-utils/src/madara/utils.rs +++ b/crates/test-utils/src/hive_utils/madara/utils.rs @@ -4,7 +4,7 @@ use reth_primitives::{Bytes, U256}; use starknet::core::types::FieldElement; use starknet::core::utils::get_storage_var_address; -use crate::types::{ContractAddress, StorageKey, StorageValue}; +use crate::hive_utils::types::{ContractAddress, StorageKey, StorageValue}; /// Generates the genesis storage tuples for setting the bytecode of a Kakarot countract account /// @@ -163,8 +163,6 @@ mod tests { use kakarot_rpc_core::contracts::account::Account; use kakarot_rpc_core::contracts::contract_account::ContractAccount; use kakarot_rpc_core::mock::constants::ACCOUNT_ADDRESS; - use kakarot_test_utils::deploy_helpers::KakarotTestEnvironmentContext; - use kakarot_test_utils::fixtures::kakarot_test_env_ctx; use reth_primitives::U256; use rstest::rstest; use starknet::core::types::{BlockId as StarknetBlockId, BlockTag, FieldElement}; @@ -174,6 +172,8 @@ mod tests { use starknet_api::state::StorageKey as StarknetStorageKey; use super::*; + use crate::deploy_helpers::KakarotTestEnvironmentContext; + use crate::fixtures::kakarot_test_env_ctx; /// This test verifies that the `genesis_set_storage_starknet_contract` function generates the /// correct storage data tuples for a given Starknet address, storage variable name, keys, diff --git a/crates/hive-utils/src/lib.rs b/crates/test-utils/src/hive_utils/mod.rs similarity index 100% rename from crates/hive-utils/src/lib.rs rename to crates/test-utils/src/hive_utils/mod.rs diff --git a/crates/hive-utils/scripts/start.sh b/crates/test-utils/src/hive_utils/scripts/start.sh similarity index 100% rename from crates/hive-utils/scripts/start.sh rename to crates/test-utils/src/hive_utils/scripts/start.sh diff --git a/crates/hive-utils/src/test_data/hive_genesis.json b/crates/test-utils/src/hive_utils/test_data/hive_genesis.json similarity index 100% rename from crates/hive-utils/src/test_data/hive_genesis.json rename to crates/test-utils/src/hive_utils/test_data/hive_genesis.json diff --git a/crates/hive-utils/src/test_data/madara_genesis.json b/crates/test-utils/src/hive_utils/test_data/madara_genesis.json similarity index 100% rename from crates/hive-utils/src/test_data/madara_genesis.json rename to crates/test-utils/src/hive_utils/test_data/madara_genesis.json diff --git a/crates/hive-utils/src/types.rs b/crates/test-utils/src/hive_utils/types.rs similarity index 100% rename from crates/hive-utils/src/types.rs rename to crates/test-utils/src/hive_utils/types.rs diff --git a/crates/test-utils/src/lib.rs b/crates/test-utils/src/lib.rs index 801c3faf1..fa02e0e95 100644 --- a/crates/test-utils/src/lib.rs +++ b/crates/test-utils/src/lib.rs @@ -2,3 +2,5 @@ pub mod constants; pub mod deploy_helpers; pub mod execution_helpers; pub mod fixtures; +pub mod hive_utils; +pub mod rpc_helpers; diff --git a/crates/eth-rpc/src/test_utils.rs b/crates/test-utils/src/rpc_helpers.rs similarity index 94% rename from crates/eth-rpc/src/test_utils.rs rename to crates/test-utils/src/rpc_helpers.rs index 110a9cb5d..bd10dc001 100644 --- a/crates/eth-rpc/src/test_utils.rs +++ b/crates/test-utils/src/rpc_helpers.rs @@ -2,16 +2,16 @@ use std::net::SocketAddr; use std::sync::Arc; use jsonrpsee::server::ServerHandle; +use kakarot_rpc::config::RPCConfig; +use kakarot_rpc::rpc::KakarotRpcModuleBuilder; +use kakarot_rpc::run_server; use kakarot_rpc_core::client::api::KakarotStarknetApi; use kakarot_rpc_core::client::config::{Network, StarknetConfig}; use kakarot_rpc_core::client::KakarotClient; -use kakarot_test_utils::deploy_helpers::KakarotTestEnvironmentContext; use starknet::providers::jsonrpc::HttpTransport; use starknet::providers::JsonRpcClient; -use crate::config::RPCConfig; -use crate::rpc::KakarotRpcModuleBuilder; -use crate::run_server; +use crate::deploy_helpers::KakarotTestEnvironmentContext; /// Sets up the environment for Kakarot RPC integration tests by deploying the Kakarot contracts /// and starting the Kakarot RPC server.