From 47c2e4fbdcae711e12d8a215b320b4506d45cbc5 Mon Sep 17 00:00:00 2001 From: Lukasz Kozlowski Date: Mon, 4 Nov 2024 20:52:22 +0100 Subject: [PATCH] Improve coverage in exe mod --- Cargo.lock | 2 ++ Cargo.toml | 1 + src/exe/mod.rs | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 541ccd22..553c3498 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -880,6 +880,8 @@ dependencies = [ "once_cell", "paste", "phf", + "rand 0.8.5", + "rstest", "serde", "serde_json", "sha2 0.10.8", diff --git a/Cargo.toml b/Cargo.toml index 8a900666..13e252fb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -69,6 +69,7 @@ gloo-timers = { version = "0.3.0", features = ["futures"] } [dev-dependencies] anyhow = "1.0.89" alloy-primitives = { version = "0.8.5", default-features = false } +blockifier = { git = "https://github.com/sergey-melnychuk/sequencer.git", tag = "beerus-wasm-2024-09-22", version = "=0.8.0-rc.2", features = ["testing"] } chrono = "0.4.38" katana-core = { git = "https://github.com/dojoengine/dojo", tag = "v1.0.0-alpha.9" } katana-executor = { git = "https://github.com/dojoengine/dojo", tag = "v1.0.0-alpha.9" } diff --git a/src/exe/mod.rs b/src/exe/mod.rs index 8c682191..f6e1975e 100644 --- a/src/exe/mod.rs +++ b/src/exe/mod.rs @@ -318,3 +318,53 @@ impl BlockifierState for StateProxy { tracing::info!(?class_hash, pcs.len = pcs.len(), "add_visited_pcs"); } } + +#[cfg(test)] +mod tests { + + use blockifier::execution::contract_class::ContractClassV1; + use starknet_api::core::PatriciaKey; + + use super::*; + struct MockHttpClient; + + impl crate::gen::client::blocking::HttpClient for MockHttpClient { + fn post( + &self, + _url: &str, + _request: &iamgroot::jsonrpc::Request, + ) -> std::result::Result { + Err(iamgroot::jsonrpc::Error {code: 0, message: "0".into()}) + } + } + + #[test] + fn test_luke() { + let mock = MockHttpClient{}; + let mut proxy = StateProxy { + client: gen::client::blocking::Client::new("test", mock), + state: State { + block_number: 0, + block_hash: gen::Felt::try_new("0x0").unwrap(), + root: gen::Felt::try_new("0x0").unwrap(), + } + }; + + proxy.set_storage_at( + ContractAddress(PatriciaKey::try_from(starknet_crypto::Felt::ZERO).unwrap()), + StarknetStorageKey(PatriciaKey::try_from(starknet_crypto::Felt::ZERO).unwrap()), + starknet_crypto::Felt::ZERO, + ).unwrap(); + proxy.increment_nonce( + ContractAddress(PatriciaKey::try_from(starknet_crypto::Felt::ZERO).unwrap()), + ).unwrap(); + proxy.set_class_hash_at( + ContractAddress(PatriciaKey::try_from(starknet_crypto::Felt::ZERO).unwrap()), + ClassHash(starknet_crypto::Felt::ZERO), + ).unwrap(); + proxy.set_contract_class(ClassHash(starknet_crypto::Felt::ZERO), ContractClass::V1(ContractClassV1::empty_for_testing())).unwrap(); + proxy.set_compiled_class_hash(ClassHash(starknet_crypto::Felt::ZERO), CompiledClassHash(starknet_crypto::Felt::ZERO)).unwrap(); + proxy.add_visited_pcs(ClassHash(starknet_crypto::Felt::ZERO), &HashSet::new()); + + } +} \ No newline at end of file