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

refactor(torii-client): remove storage packed size check #2116

Merged
merged 2 commits into from
Jun 28, 2024
Merged
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
5 changes: 0 additions & 5 deletions crates/torii/client/src/client/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ pub enum Error {
SubscriptionUninitialized,
#[error("Unknown model: {0}")]
UnknownModel(String),
#[error(
"Invalid amount of values for model {model}. Expected {expected_value_len} values, got \
{actual_value_len}"
)]
InvalidModelValuesLen { model: String, expected_value_len: usize, actual_value_len: usize },
#[error("Parsing error: {0}")]
Parse(#[from] ParseError),
#[error(transparent)]
Expand Down
54 changes: 0 additions & 54 deletions crates/torii/client/src/client/storage.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::cmp::Ordering;
use std::collections::{HashMap, HashSet};
use std::sync::Arc;

Expand Down Expand Up @@ -86,28 +85,6 @@ impl ModelStorage {
raw_keys: Vec<FieldElement>,
raw_values: Vec<FieldElement>,
) -> Result<(), Error> {
let model_name =
parse_cairo_short_string(&model).map_err(ParseError::ParseCairoShortString)?;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could potentially check that, but only if the layout if Fixed, which means everything is packed as before, hence the values should match.

We can address specific tests for that in an other PR, since related to some changes to the namespace will need test too.


let model_packed_size = self
.metadata
.read()
.model(&model_name)
.map(|model| model.packed_size)
.ok_or(Error::UnknownModel(model_name.clone()))?;

match raw_values.len().cmp(&(model_packed_size as usize)) {
Ordering::Greater | Ordering::Less => {
return Err(Error::InvalidModelValuesLen {
model: model_name,
actual_value_len: raw_values.len(),
expected_value_len: model_packed_size as usize,
});
}

Ordering::Equal => {}
}

let storage_addresses = self.get_model_storage_addresses(model, &raw_keys)?;
self.set_storages_at(storage_addresses.into_iter().zip(raw_values).collect());
self.index_model(model, raw_keys);
Expand Down Expand Up @@ -174,7 +151,6 @@ mod tests {
use starknet::core::utils::cairo_short_string_to_felt;
use starknet::macros::felt;

use crate::client::error::Error;
use crate::utils::compute_all_storage_addresses;

fn create_dummy_metadata() -> WorldMetadata {
Expand All @@ -199,36 +175,6 @@ mod tests {
super::ModelStorage::new(metadata)
}

#[test]
fn err_if_set_values_too_many() {
let storage = create_dummy_storage();
let keys = vec![felt!("0x12345")];
let values = vec![felt!("1"), felt!("2"), felt!("3"), felt!("4"), felt!("5")];
let model = cairo_short_string_to_felt("Position").unwrap();
let result = storage.set_model_storage(model, keys, values);

assert!(storage.storage.read().is_empty());
matches!(
result,
Err(Error::InvalidModelValuesLen { actual_value_len: 5, expected_value_len: 4, .. })
);
}

#[test]
fn err_if_set_values_too_few() {
let storage = create_dummy_storage();
let keys = vec![felt!("0x12345")];
let values = vec![felt!("1"), felt!("2")];
let model = cairo_short_string_to_felt("Position").unwrap();
let result = storage.set_model_storage(model, keys, values);

assert!(storage.storage.read().is_empty());
matches!(
result,
Err(Error::InvalidModelValuesLen { actual_value_len: 2, expected_value_len: 4, .. })
);
}

#[test]
fn set_and_get_model_value() {
let storage = create_dummy_storage();
Expand Down
Loading