Skip to content

Commit

Permalink
dev: refactor hive-utils crate and kakarot_rpc::test_utils to test_ut…
Browse files Browse the repository at this point in the history
…ils crate (#558)

* feat: refactor hive-utils crate to be part of test-utils crate

* dev: refactor hive-utils crate and kakarot-rpc::test_utils to test_utils crate

---------

Co-authored-by: Harsh Bajpai <harshbajpai@Harshs-MBP.bbrouter>
  • Loading branch information
bajpai244 and Harsh Bajpai authored Sep 14, 2023
1 parent 7654705 commit a299d79
Show file tree
Hide file tree
Showing 21 changed files with 42 additions and 75 deletions.
25 changes: 4 additions & 21 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
2 changes: 1 addition & 1 deletion crates/eth-rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
1 change: 0 additions & 1 deletion crates/eth-rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
2 changes: 1 addition & 1 deletion crates/eth-rpc/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;

Expand Down
30 changes: 0 additions & 30 deletions crates/hive-utils/Cargo.toml

This file was deleted.

10 changes: 10 additions & 0 deletions crates/test-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand All @@ -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"
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -9,7 +11,8 @@ async fn main() {

// Read the madara genesis
let madara_loader =
serde_json::from_str::<GenesisLoader>(std::include_str!("../../test_data/madara_genesis.json")).unwrap();
serde_json::from_str::<GenesisLoader>(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");

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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::<GenesisLoader>(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
Expand All @@ -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();
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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
///
Expand Down Expand Up @@ -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};
Expand All @@ -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,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions crates/test-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit a299d79

Please sign in to comment.