Skip to content

Commit

Permalink
fmt clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
Larkooo committed Nov 8, 2024
1 parent 8b41cf2 commit a2c064e
Show file tree
Hide file tree
Showing 11 changed files with 100 additions and 53 deletions.
4 changes: 2 additions & 2 deletions bin/torii/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ struct Args {
contracts: Vec<Contract>,

Check warning on line 143 in bin/torii/src/main.rs

View check run for this annotation

Codecov / codecov/patch

bin/torii/src/main.rs#L143

Added line #L143 was not covered by tests

/// Event messages that are going to be treated as historical
/// A list of the model tags (namespace-name)
/// A list of the model tags (namespace-name)
#[arg(long, value_delimiter = ',')]
historical_events: Vec<String>,

Check warning on line 148 in bin/torii/src/main.rs

View check run for this annotation

Codecov / codecov/patch

bin/torii/src/main.rs#L148

Added line #L148 was not covered by tests

Expand Down Expand Up @@ -252,7 +252,7 @@ async fn main() -> anyhow::Result<()> {
polling_interval: Duration::from_millis(args.polling_interval),
flags,
event_processor_config: EventProcessorConfig {
historical_events: args.historical_events,
historical_events: args.historical_events.into_iter().collect(),
},

Check warning on line 256 in bin/torii/src/main.rs

View check run for this annotation

Codecov / codecov/patch

bin/torii/src/main.rs#L254-L256

Added lines #L254 - L256 were not covered by tests
},
shutdown_tx.clone(),
Expand Down
18 changes: 13 additions & 5 deletions bin/torii/torii.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# Example configuration file for Torii
# contracts = [
# { type = "WORLD", address = "<WORLD_CONTRACT_ADDRESS>" },
# { type = "ERC20", address = "<ERC20_CONTRACT_ADDRESS>" },
# { type = "ERC721", address = "<ERC721_CONTRACT_ADDRESS>" },
# ]
world_address="0x054d0f13bf3fb5f15a8674c5204aad35e3022af96bcc23bdbd16b7e297ffd399"
addr="0.0.0.0:8080"
rpc="http://0.0.0.0:5050"

historical_events=["ns-Moved", "ns-Spawned"]

[[contracts]]
type="ERC20"
address="0x0"

[[contracts]]
type="ERC721"
address="0x123"
10 changes: 7 additions & 3 deletions crates/torii/core/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ use crate::processors::store_del_record::StoreDelRecordProcessor;
use crate::processors::store_set_record::StoreSetRecordProcessor;
use crate::processors::store_update_member::StoreUpdateMemberProcessor;
use crate::processors::store_update_record::StoreUpdateRecordProcessor;
use crate::processors::{BlockProcessor, EventProcessor, EventProcessorConfig, TransactionProcessor};
use crate::processors::{
BlockProcessor, EventProcessor, EventProcessorConfig, TransactionProcessor,
};
use crate::sql::{Cursors, Sql};
use crate::types::{Contract, ContractType};

Expand Down Expand Up @@ -219,9 +221,11 @@ impl<P: Provider + Send + Sync + std::fmt::Debug + 'static> Engine<P> {
config: EngineConfig,
shutdown_tx: Sender<()>,
block_tx: Option<BoundedSender<u64>>,
contracts: &Vec<Contract>,
contracts: &[Contract],
) -> Self {
let contracts = Arc::new(contracts.iter().map(|contract| (contract.address, contract.r#type)).collect());
let contracts = Arc::new(
contracts.iter().map(|contract| (contract.address, contract.r#type)).collect(),
);

Self {
world: Arc::new(world),
Expand Down
3 changes: 2 additions & 1 deletion crates/torii/core/src/processors/event_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ where
entity.deserialize(&mut keys_and_unpacked)?;

// TODO: this must come from some torii's configuration.
let historical = config.historical_events.contains(&format!("{}-{}", model.namespace, model.name));
let historical =
config.historical_events.contains(&format!("{}-{}", model.namespace, model.name));
db.set_event_message(entity, event_id, block_timestamp, historical).await?;
Ok(())
}
Expand Down
4 changes: 3 additions & 1 deletion crates/torii/core/src/processors/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::collections::HashSet;

use anyhow::{Error, Result};
use async_trait::async_trait;
use dojo_world::contracts::world::WorldContractReader;
Expand Down Expand Up @@ -26,7 +28,7 @@ const ENTITY_ID_INDEX: usize = 1;

#[derive(Clone, Debug, Default)]
pub struct EventProcessorConfig {
pub historical_events: Vec<String>,
pub historical_events: HashSet<String>,
}

#[async_trait]
Expand Down
2 changes: 1 addition & 1 deletion crates/torii/core/src/sql/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ where
EngineConfig::default(),
shutdown_tx,
None,
&vec![Contract { address: world_address, r#type: ContractType::WORLD }],
&[Contract { address: world_address, r#type: ContractType::WORLD }],
);

let data = engine.fetch_range(0, to, &HashMap::new()).await.unwrap();
Expand Down
22 changes: 14 additions & 8 deletions crates/torii/graphql/src/tests/metadata_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,13 @@ mod tests {
tokio::spawn(async move {
executor.run().await.unwrap();
});
let mut db =
Sql::new(pool.clone(), sender, &vec![Contract { address: Felt::ZERO, r#type: ContractType::WORLD }])
.await
.unwrap();
let mut db = Sql::new(
pool.clone(),
sender,
&vec![Contract { address: Felt::ZERO, r#type: ContractType::WORLD }],
)
.await
.unwrap();
let schema = build_schema(&pool).await.unwrap();

let cover_img = "QWxsIHlvdXIgYmFzZSBiZWxvbmcgdG8gdXM=";
Expand Down Expand Up @@ -117,10 +120,13 @@ mod tests {
tokio::spawn(async move {
executor.run().await.unwrap();
});
let mut db =
Sql::new(pool.clone(), sender, &vec![Contract { address: Felt::ZERO, r#type: ContractType::WORLD }])
.await
.unwrap();
let mut db = Sql::new(
pool.clone(),
sender,
&vec![Contract { address: Felt::ZERO, r#type: ContractType::WORLD }],
)
.await
.unwrap();
let schema = build_schema(&pool).await.unwrap();

db.set_metadata(&RESOURCE, URI, BLOCK_TIMESTAMP).unwrap();
Expand Down
12 changes: 8 additions & 4 deletions crates/torii/graphql/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,13 @@ pub async fn spinup_types_test(path: &str) -> Result<SqlitePool> {
tokio::spawn(async move {
executor.run().await.unwrap();
});
let db = Sql::new(pool.clone(), sender, &vec![Contract { address: world_address, r#type: ContractType::WORLD }])
.await
.unwrap();
let db = Sql::new(
pool.clone(),
sender,
&vec![Contract { address: world_address, r#type: ContractType::WORLD }],
)
.await
.unwrap();

let (shutdown_tx, _) = broadcast::channel(1);
let mut engine = Engine::new(
Expand All @@ -358,7 +362,7 @@ pub async fn spinup_types_test(path: &str) -> Result<SqlitePool> {
EngineConfig::default(),
shutdown_tx,
None,
&vec![Contract { address: world_address, r#type: ContractType::WORLD }],
&[Contract { address: world_address, r#type: ContractType::WORLD }],
);

let to = account.provider().block_hash_and_number().await?.block_number;
Expand Down
55 changes: 35 additions & 20 deletions crates/torii/graphql/src/tests/subscription_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@ mod tests {
tokio::spawn(async move {
executor.run().await.unwrap();
});
let mut db =
Sql::new(pool.clone(), sender, &vec![Contract { address: Felt::ZERO, r#type: ContractType::WORLD }])
.await
.unwrap();
let mut db = Sql::new(
pool.clone(),
sender,
&vec![Contract { address: Felt::ZERO, r#type: ContractType::WORLD }],
)
.await
.unwrap();

model_fixtures(&mut db).await;
// 0. Preprocess expected entity value
Expand Down Expand Up @@ -174,10 +177,13 @@ mod tests {
tokio::spawn(async move {
executor.run().await.unwrap();
});
let mut db =
Sql::new(pool.clone(), sender, &vec![Contract { address: Felt::ZERO, r#type: ContractType::WORLD }])
.await
.unwrap();
let mut db = Sql::new(
pool.clone(),
sender,
&vec![Contract { address: Felt::ZERO, r#type: ContractType::WORLD }],
)
.await
.unwrap();

model_fixtures(&mut db).await;
// 0. Preprocess expected entity value
Expand Down Expand Up @@ -298,10 +304,13 @@ mod tests {
tokio::spawn(async move {
executor.run().await.unwrap();
});
let mut db =
Sql::new(pool.clone(), sender, &vec![Contract { address: Felt::ZERO, r#type: ContractType::WORLD }])
.await
.unwrap();
let mut db = Sql::new(
pool.clone(),
sender,
&vec![Contract { address: Felt::ZERO, r#type: ContractType::WORLD }],
)
.await
.unwrap();
// 0. Preprocess model value
let namespace = "types_test".to_string();
let model_name = "Subrecord".to_string();
Expand Down Expand Up @@ -372,10 +381,13 @@ mod tests {
tokio::spawn(async move {
executor.run().await.unwrap();
});
let mut db =
Sql::new(pool.clone(), sender, &vec![Contract { address: Felt::ZERO, r#type: ContractType::WORLD }])
.await
.unwrap();
let mut db = Sql::new(
pool.clone(),
sender,
&vec![Contract { address: Felt::ZERO, r#type: ContractType::WORLD }],
)
.await
.unwrap();
// 0. Preprocess model value
let namespace = "types_test".to_string();
let model_name = "Subrecord".to_string();
Expand Down Expand Up @@ -447,10 +459,13 @@ mod tests {
tokio::spawn(async move {
executor.run().await.unwrap();
});
let mut db =
Sql::new(pool.clone(), sender, &vec![Contract { address: Felt::ZERO, r#type: ContractType::WORLD }])
.await
.unwrap();
let mut db = Sql::new(
pool.clone(),
sender,
&vec![Contract { address: Felt::ZERO, r#type: ContractType::WORLD }],
)
.await
.unwrap();
let block_timestamp: u64 = 1710754478_u64;
let (tx, mut rx) = mpsc::channel(7);
tokio::spawn(async move {
Expand Down
12 changes: 8 additions & 4 deletions crates/torii/grpc/src/server/tests/entities_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,13 @@ async fn test_entities_queries(sequencer: &RunnerCtx) {
tokio::spawn(async move {
executor.run().await.unwrap();
});
let db = Sql::new(pool.clone(), sender, &vec![Contract { address: world_address, r#type: ContractType::WORLD }])
.await
.unwrap();
let db = Sql::new(
pool.clone(),
sender,
&vec![Contract { address: world_address, r#type: ContractType::WORLD }],
)
.await
.unwrap();

let (shutdown_tx, _) = broadcast::channel(1);
let mut engine = Engine::new(
Expand All @@ -105,7 +109,7 @@ async fn test_entities_queries(sequencer: &RunnerCtx) {
EngineConfig::default(),
shutdown_tx,
None,
&vec![Contract { address: world_address, r#type: ContractType::WORLD }],
&[Contract { address: world_address, r#type: ContractType::WORLD }],
);

let to = provider.block_hash_and_number().await.unwrap().block_number;
Expand Down
11 changes: 7 additions & 4 deletions crates/torii/libp2p/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -577,10 +577,13 @@ mod test {
tokio::spawn(async move {
executor.run().await.unwrap();
});
let mut db =
Sql::new(pool.clone(), sender, &vec![Contract { address: Felt::ZERO, r#type: ContractType::WORLD }])
.await
.unwrap();
let mut db = Sql::new(
pool.clone(),
sender,
&vec![Contract { address: Felt::ZERO, r#type: ContractType::WORLD }],
)
.await
.unwrap();

// Register the model of our Message
db.register_model(
Expand Down

0 comments on commit a2c064e

Please sign in to comment.