Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
tcoratger committed Apr 3, 2024
1 parent a77c1fe commit fcb81b7
Show file tree
Hide file tree
Showing 21 changed files with 140 additions and 172 deletions.
12 changes: 2 additions & 10 deletions crates/dojo-lang/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,7 @@ impl GeneratedFileAuxData for DojoAuxData {
self
}
fn eq(&self, other: &dyn GeneratedFileAuxData) -> bool {
if let Some(other) = other.as_any().downcast_ref::<Self>() {
self == other
} else {
false
}
if let Some(other) = other.as_any().downcast_ref::<Self>() { self == other } else { false }
}
}

Expand All @@ -92,11 +88,7 @@ impl GeneratedFileAuxData for ComputedValuesAuxData {
self
}
fn eq(&self, other: &dyn GeneratedFileAuxData) -> bool {
if let Some(other) = other.as_any().downcast_ref::<Self>() {
self == other
} else {
false
}
if let Some(other) = other.as_any().downcast_ref::<Self>() { self == other } else { false }
}
}

Expand Down
6 changes: 1 addition & 5 deletions crates/dojo-world/src/migration/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ pub struct ClassDiff {

impl StateDiff for ClassDiff {
fn is_same(&self) -> bool {
if let Some(remote) = self.remote {
self.local == remote
} else {
false
}
if let Some(remote) = self.remote { self.local == remote } else { false }
}
}

Expand Down
6 changes: 1 addition & 5 deletions crates/dojo-world/src/migration/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@ pub struct ContractDiff {

impl StateDiff for ContractDiff {
fn is_same(&self) -> bool {
if let Some(remote) = self.remote {
self.local == remote
} else {
false
}
if let Some(remote) = self.remote { self.local == remote } else { false }
}
}

Expand Down
11 changes: 4 additions & 7 deletions crates/katana/core/src/sequencer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,13 +286,10 @@ impl<EF: ExecutorFactory> KatanaSequencer<EF> {

let tx @ Some(_) = tx else {
return Ok(self.pending_executor().as_ref().and_then(|exec| {
exec.read().transactions().iter().find_map(|tx| {
if tx.0.hash == *hash {
Some(tx.0.clone())
} else {
None
}
})
exec.read()
.transactions()
.iter()
.find_map(|tx| if tx.0.hash == *hash { Some(tx.0.clone()) } else { None })
}));
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,7 @@ impl<S: StateDb> StateProvider for CachedState<S> {
};

let hash = hash.0.into();
if hash == FieldElement::ZERO {
Ok(None)
} else {
Ok(Some(hash))
}
if hash == FieldElement::ZERO { Ok(None) } else { Ok(Some(hash)) }
}

fn nonce(
Expand Down
7 changes: 3 additions & 4 deletions crates/katana/executor/src/implementation/sir/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -553,10 +553,9 @@ mod tests {
ClassHash::default(),
"class hash of nonexistant contract should default to zero"
);
assert!(actual_compiled_hash
.unwrap_err()
.to_string()
.contains("No compiled class hash found"));
assert!(
actual_compiled_hash.unwrap_err().to_string().contains("No compiled class hash found")
);
assert!(actual_compiled_class.unwrap_err().to_string().contains("No compiled class found"));

let sp: Box<dyn StateProvider> = Box::new(cached_state);
Expand Down
10 changes: 6 additions & 4 deletions crates/katana/primitives/src/genesis/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1088,10 +1088,12 @@ mod tests {
fn genesis_from_json_with_unresolved_paths() {
let file = File::open("./src/genesis/test-genesis.json").unwrap();
let json: GenesisJson = serde_json::from_reader(file).unwrap();
assert!(Genesis::try_from(json)
.unwrap_err()
.to_string()
.contains("Unresolved class artifact path"));
assert!(
Genesis::try_from(json)
.unwrap_err()
.to_string()
.contains("Unresolved class artifact path")
);
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion crates/katana/rpc/rpc-api/src/torii.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ use katana_rpc_types::transaction::{TransactionsPage, TransactionsPageCursor};
pub trait ToriiApi {
#[method(name = "getTransactions")]
async fn get_transactions(&self, cursor: TransactionsPageCursor)
-> RpcResult<TransactionsPage>;
-> RpcResult<TransactionsPage>;
}
6 changes: 1 addition & 5 deletions crates/katana/storage/db/src/mdbx/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,11 +304,7 @@ impl<T: Table> Walker<'_, RW, T> {
impl<K: TransactionKind, T: Table> std::iter::Iterator for Walker<'_, K, T> {
type Item = Result<KeyValue<T>, DatabaseError>;
fn next(&mut self) -> Option<Self::Item> {
if let value @ Some(_) = self.start.take() {
value
} else {
self.cursor.next().transpose()
}
if let value @ Some(_) = self.start.take() { value } else { self.cursor.next().transpose() }
}
}

Expand Down
6 changes: 1 addition & 5 deletions crates/katana/storage/provider/src/providers/db/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,7 @@ impl HistoricalStateProvider {
// then that means there is no change happening before the pinned block number.
let pos = {
if let Some(pos) = block_list.last().and_then(|num| {
if block_number >= *num {
Some(block_list.len() - 1)
} else {
None
}
if block_number >= *num { Some(block_list.len() - 1) } else { None }
}) {
Some(pos)
} else {
Expand Down
2 changes: 1 addition & 1 deletion crates/katana/storage/provider/src/traits/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ pub trait ContractClassWriter: Send + Sync {

/// Retrieves the Sierra class definition of a contract class given its class hash.
fn set_sierra_class(&self, hash: ClassHash, sierra: FlattenedSierraClass)
-> ProviderResult<()>;
-> ProviderResult<()>;
}
2 changes: 1 addition & 1 deletion crates/katana/storage/provider/src/traits/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub trait StateProvider: ContractClassProvider + Send + Sync {

/// Returns the class hash of a contract.
fn class_hash_of_contract(&self, address: ContractAddress)
-> ProviderResult<Option<ClassHash>>;
-> ProviderResult<Option<ClassHash>>;
}

/// A type which can create [`StateProvider`] for states at a particular block.
Expand Down
18 changes: 10 additions & 8 deletions crates/sozo/ops/src/migration/migration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,16 @@ async fn migrate_with_small_fee_multiplier_will_fail() {
ExecutionEncoding::New,
);

assert!(execute_strategy(
&ws,
&migration,
&account,
Some(TxConfig { fee_estimate_multiplier: Some(0.2f64), wait: false, receipt: false }),
)
.await
.is_err());
assert!(
execute_strategy(
&ws,
&migration,
&account,
Some(TxConfig { fee_estimate_multiplier: Some(0.2f64), wait: false, receipt: false }),
)
.await
.is_err()
);
sequencer.stop().unwrap();
}

Expand Down
114 changes: 60 additions & 54 deletions crates/sozo/ops/src/tests/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,17 @@ async fn call_with_bad_address() {
let provider = sequencer.provider();
let world_reader = WorldContractReader::new(world.address, provider);

assert!(call::call(
world_reader,
"0xBadCoffeeBadCode".to_string(),
ENTRYPOINT.to_string(),
vec![FieldElement::ZERO, FieldElement::ZERO],
None
)
.await
.is_err());
assert!(
call::call(
world_reader,
"0xBadCoffeeBadCode".to_string(),
ENTRYPOINT.to_string(),
vec![FieldElement::ZERO, FieldElement::ZERO],
None
)
.await
.is_err()
);
}

#[tokio::test]
Expand All @@ -43,15 +45,17 @@ async fn call_with_bad_name() {
let provider = sequencer.provider();
let world_reader = WorldContractReader::new(world.address, provider);

assert!(call::call(
world_reader,
"BadName".to_string(),
ENTRYPOINT.to_string(),
vec![FieldElement::ZERO, FieldElement::ZERO],
None
)
.await
.is_err());
assert!(
call::call(
world_reader,
"BadName".to_string(),
ENTRYPOINT.to_string(),
vec![FieldElement::ZERO, FieldElement::ZERO],
None
)
.await
.is_err()
);
}

#[tokio::test]
Expand All @@ -63,15 +67,17 @@ async fn call_with_bad_entrypoint() {
let provider = sequencer.provider();
let world_reader = WorldContractReader::new(world.address, provider);

assert!(call::call(
world_reader,
CONTRACT_NAME.to_string(),
"BadEntryPoint".to_string(),
vec![FieldElement::ZERO, FieldElement::ZERO],
None
)
.await
.is_err());
assert!(
call::call(
world_reader,
CONTRACT_NAME.to_string(),
"BadEntryPoint".to_string(),
vec![FieldElement::ZERO, FieldElement::ZERO],
None
)
.await
.is_err()
);
}

#[tokio::test]
Expand All @@ -83,15 +89,11 @@ async fn call_with_bad_calldata() {
let provider = sequencer.provider();
let world_reader = WorldContractReader::new(world.address, provider);

assert!(call::call(
world_reader,
CONTRACT_NAME.to_string(),
ENTRYPOINT.to_string(),
vec![],
None
)
.await
.is_err());
assert!(
call::call(world_reader, CONTRACT_NAME.to_string(), ENTRYPOINT.to_string(), vec![], None)
.await
.is_err()
);
}

#[tokio::test]
Expand All @@ -103,15 +105,17 @@ async fn call_with_contract_name() {
let provider = sequencer.provider();
let world_reader = WorldContractReader::new(world.address, provider);

assert!(call::call(
world_reader,
CONTRACT_NAME.to_string(),
ENTRYPOINT.to_string(),
vec![FieldElement::ZERO, FieldElement::ZERO],
None,
)
.await
.is_ok());
assert!(
call::call(
world_reader,
CONTRACT_NAME.to_string(),
ENTRYPOINT.to_string(),
vec![FieldElement::ZERO, FieldElement::ZERO],
None,
)
.await
.is_ok()
);
}

#[tokio::test]
Expand All @@ -129,13 +133,15 @@ async fn call_with_contract_address() {
.await
.unwrap();

assert!(call::call(
world_reader,
format!("{:#x}", contract_address),
ENTRYPOINT.to_string(),
vec![FieldElement::ZERO, FieldElement::ZERO],
None,
)
.await
.is_ok());
assert!(
call::call(
world_reader,
format!("{:#x}", contract_address),
ENTRYPOINT.to_string(),
vec![FieldElement::ZERO, FieldElement::ZERO],
None,
)
.await
.is_ok()
);
}
8 changes: 5 additions & 3 deletions crates/torii/client/src/client/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,10 @@ mod tests {
);
assert!(actual_values == expected_values);
assert!(storage.storage.read().len() == model.packed_size as usize);
assert!(actual_storage_addresses
.into_iter()
.all(|address| expected_storage_addresses.contains(&address)));
assert!(
actual_storage_addresses
.into_iter()
.all(|address| expected_storage_addresses.contains(&address))
);
}
}
6 changes: 1 addition & 5 deletions crates/torii/client/src/client/subscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,7 @@ impl SubscriptionService {
let storage_entries = diff.storage_diffs.into_iter().find_map(|d| {
let expected = self.world_metadata.read().world_address;
let current = d.address;
if current == expected {
Some(d.storage_entries)
} else {
None
}
if current == expected { Some(d.storage_entries) } else { None }
});

let Some(entries) = storage_entries else {
Expand Down
12 changes: 5 additions & 7 deletions crates/torii/graphql/src/object/entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,8 @@ impl ResolvableObject for EntityObject {
}

fn subscriptions(&self) -> Option<Vec<SubscriptionField>> {
Some(vec![SubscriptionField::new(
"entityUpdated",
TypeRef::named_nn(self.type_name()),
|ctx| {
Some(vec![
SubscriptionField::new("entityUpdated", TypeRef::named_nn(self.type_name()), |ctx| {
SubscriptionFieldFuture::new(async move {
let id = match ctx.args.get("id") {
Some(id) => Some(id.string()?.to_string()),
Expand All @@ -83,9 +81,9 @@ impl ResolvableObject for EntityObject {
}
}))
})
},
)
.argument(InputValue::new("id", TypeRef::named(TypeRef::ID)))])
})
.argument(InputValue::new("id", TypeRef::named(TypeRef::ID))),
])
}
}

Expand Down
Loading

0 comments on commit fcb81b7

Please sign in to comment.