Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Larkooo committed Feb 3, 2025
1 parent d45f9fc commit 0721b87
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
13 changes: 9 additions & 4 deletions crates/torii/sqlite/src/executor/erc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ use crate::executor::LOG_TARGET;
use crate::simple_broker::SimpleBroker;
use crate::types::{ContractType, TokenBalance};
use crate::utils::{
felt_to_sql_string, fetch_content_from_ipfs, sanitize_json_string, sql_string_to_u256, u256_to_sql_string, I256
felt_to_sql_string, fetch_content_from_ipfs, sanitize_json_string, sql_string_to_u256,
u256_to_sql_string, I256,
};

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -245,7 +246,9 @@ impl<'c, P: Provider + Sync + Send + 'static> Executor<'c, P> {
let metadata = Self::fetch_metadata(&token_uri).await;

Check warning on line 247 in crates/torii/sqlite/src/executor/erc.rs

View check run for this annotation

Codecov / codecov/patch

crates/torii/sqlite/src/executor/erc.rs#L247

Added line #L247 was not covered by tests
match metadata {
Ok(metadata) => serde_json::to_string(&metadata).context("Failed to serialize metadata")?,
Ok(metadata) => {
serde_json::to_string(&metadata).context("Failed to serialize metadata")?
}

Check warning on line 251 in crates/torii/sqlite/src/executor/erc.rs

View check run for this annotation

Codecov / codecov/patch

crates/torii/sqlite/src/executor/erc.rs#L249-L251

Added lines #L249 - L251 were not covered by tests
Err(err) => {
debug!(error = %err, token_uri = %token_uri, "Error fetching metadata");
warn!(
Expand Down Expand Up @@ -321,8 +324,10 @@ impl<'c, P: Provider + Sync + Send + 'static> Executor<'c, P> {
.collect::<String>();
let sanitized_json = sanitize_json_string(&decoded_str);

Check warning on line 325 in crates/torii/sqlite/src/executor/erc.rs

View check run for this annotation

Codecov / codecov/patch

crates/torii/sqlite/src/executor/erc.rs#L325

Added line #L325 was not covered by tests

let json: serde_json::Value = serde_json::from_str(&sanitized_json)
.with_context(|| format!("Failed to parse metadata JSON from data URI: {}", &uri))?;
let json: serde_json::Value =
serde_json::from_str(&sanitized_json).with_context(|| {
format!("Failed to parse metadata JSON from data URI: {}", &uri)
})?;

Check warning on line 330 in crates/torii/sqlite/src/executor/erc.rs

View check run for this annotation

Codecov / codecov/patch

crates/torii/sqlite/src/executor/erc.rs#L328-L330

Added lines #L328 - L330 were not covered by tests

Ok(json)
}
Expand Down
7 changes: 3 additions & 4 deletions crates/torii/sqlite/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub fn sanitize_json_string(s: &str) -> String {
let mut result = String::new();
let mut chars = s.chars().peekable();
let mut in_string = false;

while let Some(c) = chars.next() {
match c {
'"' => {
Expand Down Expand Up @@ -101,7 +101,7 @@ pub fn sanitize_json_string(s: &str) -> String {
}
}
}

result
}

Expand Down Expand Up @@ -224,14 +224,13 @@ mod tests {
let expected = r#"{"name":"\"Rage Shout\" DireWolf"}"#;
let sanitized = sanitize_json_string(input);
assert_eq!(sanitized, expected);

let input_escaped = r#"{"name":"\"Properly Escaped\" Wolf"}"#;
let expected_escaped = r#"{"name":"\"Properly Escaped\" Wolf"}"#;
let sanitized_escaped = sanitize_json_string(input_escaped);
assert_eq!(sanitized_escaped, expected_escaped);
}


#[test]
fn test_must_utc_datetime_from_timestamp() {
let timestamp = 1633027200;
Expand Down

0 comments on commit 0721b87

Please sign in to comment.