Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve starknet-os/storage code #439

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions crates/starknet-os/src/storage/composite_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,22 @@ mod tests {

let key1 = vec![0, 1, 1];
let key2 = vec![0, 2, 2];
let key3 = vec![0, 3, 3];
let value1 = "hello".as_bytes().to_vec();
let value2 = "goodbye".as_bytes().to_vec();
let value3 = "yes".as_bytes().to_vec();

s1.set_value(key1.clone(), value1.clone()).await.unwrap();
s2.set_value(key2.clone(), value2.clone()).await.unwrap();

let storage = CompositeStorage::new(s1, s2);
let mut storage = CompositeStorage::new(s1, s2);

storage.set_value(key3.clone(), value3.clone()).await.unwrap();
assert_eq!(storage.get_value(&key1).await.unwrap(), Some(value1));
assert_eq!(storage.get_value(&key2).await.unwrap(), Some(value2));
assert_eq!(storage.get_value(&key3).await.unwrap(), Some(value3));

let missing_key = vec![0, 3, 3];
let missing_key = vec![0, 4, 4];
assert_eq!(storage.get_value(&missing_key).await.unwrap(), None);
}
}
16 changes: 0 additions & 16 deletions crates/starknet-os/src/storage/storage_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,19 +116,3 @@ pub async fn build_starknet_storage_async<S: Storage + Send + Sync, H: HashFunct

Ok((storage_by_address, initial_state, final_state))
}

/// Convert a starknet_api deprecated ContractClass to a cairo-vm ContractClass (v0 only).
/// Note that this makes a serialize -> deserialize pass, so it is not cheap!
pub fn deprecated_contract_class_api2vm(
api_class: &starknet_api::deprecated_contract_class::ContractClass,
) -> serde_json::Result<blockifier::execution::contract_class::ContractClass> {
let serialized = serde_json::to_string(&api_class)?;

let vm_class_v0_inner: blockifier::execution::contract_class::ContractClassV0Inner =
serde_json::from_str(serialized.as_str())?;

let vm_class_v0 = blockifier::execution::contract_class::ContractClassV0(std::sync::Arc::new(vm_class_v0_inner));
let vm_class = blockifier::execution::contract_class::ContractClass::V0(vm_class_v0);

Ok(vm_class)
}
Loading