Skip to content

Commit

Permalink
refactor(tests-integration): refactor state reader (#1014)
Browse files Browse the repository at this point in the history
Changes:
- use papyrus test util to create storage
- hoist cairo0 var definition away from the storage stuff

style:
- use annotation instead of fish in the cairo0 var
- deref coercion over `as_slice`, more succinct

Co-Authored-By: Gilad Chase <[email protected]>
  • Loading branch information
giladchase and Gilad Chase authored Sep 25, 2024
1 parent c6e4e2e commit 8fa1dba
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 14 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

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

3 changes: 1 addition & 2 deletions crates/tests-integration/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ itertools.workspace = true
mempool_test_utils.workspace = true
papyrus_common.workspace = true
papyrus_rpc.workspace = true
papyrus_storage.workspace = true
papyrus_storage = { workspace = true, features = ["testing"] }
reqwest.workspace = true
serde_json.workspace = true
starknet-types-core.workspace = true
Expand All @@ -31,7 +31,6 @@ starknet_mempool_node.workspace = true
starknet_mempool_types.workspace = true
starknet_task_executor.workspace = true
strum.workspace = true
tempfile.workspace = true
tokio.workspace = true

[dev-dependencies]
Expand Down
18 changes: 7 additions & 11 deletions crates/tests-integration/src/state_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ use papyrus_storage::class::ClassStorageWriter;
use papyrus_storage::compiled_class::CasmStorageWriter;
use papyrus_storage::header::HeaderStorageWriter;
use papyrus_storage::state::StateStorageWriter;
use papyrus_storage::{open_storage, StorageConfig, StorageReader};
use papyrus_storage::test_utils::get_test_storage;
use papyrus_storage::StorageReader;
use starknet_api::block::{
BlockBody,
BlockHeader,
Expand All @@ -40,7 +41,6 @@ use starknet_api::{contract_address, felt, patricia_key};
use starknet_client::reader::PendingData;
use starknet_types_core::felt::Felt;
use strum::IntoEnumIterator;
use tempfile::tempdir;
use tokio::sync::RwLock;

use crate::integration_test_utils::get_available_socket;
Expand Down Expand Up @@ -196,16 +196,12 @@ fn write_state_to_papyrus_storage(
) -> StorageReader {
let block_number = BlockNumber(0);
let block_header = test_block_header(block_number);
let cairo0_contract_classes: Vec<_> =
cairo0_contract_classes.iter().map(|(hash, contract)| (*hash, contract)).collect();

let mut storage_config = StorageConfig::default();
let tempdir = tempdir().unwrap();
storage_config.db_config.path_prefix = tempdir.path().to_path_buf();
let (storage_reader, mut storage_writer) = open_storage(storage_config).unwrap();

let cairo0_contract_classes =
cairo0_contract_classes.iter().map(|(x, y)| (*x, y)).collect::<Vec<_>>();

let (storage_reader, mut storage_writer) = get_test_storage().0;
let mut write_txn = storage_writer.begin_rw_txn().unwrap();

for (class_hash, casm) in cairo1_contract_classes {
write_txn = write_txn.append_casm(class_hash, casm).unwrap();
}
Expand All @@ -216,7 +212,7 @@ fn write_state_to_papyrus_storage(
.unwrap()
.append_state_diff(block_number, state_diff)
.unwrap()
.append_classes(block_number, &[], cairo0_contract_classes.as_slice())
.append_classes(block_number, &[], &cairo0_contract_classes)
.unwrap()
.commit()
.unwrap();
Expand Down

0 comments on commit 8fa1dba

Please sign in to comment.