Skip to content

Commit

Permalink
wrap up config
Browse files Browse the repository at this point in the history
  • Loading branch information
Larkooo committed Nov 8, 2024
1 parent aa985f7 commit 7c19061
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 37 deletions.
10 changes: 6 additions & 4 deletions bin/torii/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ struct Args {
index_raw_events: bool,

/// ERC contract addresses to index
#[arg(long, value_parser = parse_erc_contracts, default_value = "")]
contracts: Vec<Contract>,
#[arg(long, default_value = "")]
contracts: String,

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

/// Configuration file
#[arg(long)]
Expand All @@ -158,6 +158,9 @@ async fn main() -> anyhow::Result<()> {
Args::from_arg_matches(&matches)?

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

View check run for this annotation

Codecov / codecov/patch

bin/torii/src/main.rs#L158

Added line #L158 was not covered by tests
};

let mut contracts = parse_erc_contracts(&args.contracts)?;
contracts.push(Contract { address: args.world_address, r#type: ContractType::WORLD });

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

View check run for this annotation

Codecov / codecov/patch

bin/torii/src/main.rs#L161-L162

Added lines #L161 - L162 were not covered by tests

let filter_layer = EnvFilter::try_from_default_env()
.unwrap_or_else(|_| EnvFilter::new("info,hyper_reverse_proxy=off"));

Expand Down Expand Up @@ -202,7 +205,6 @@ async fn main() -> anyhow::Result<()> {
// Get world address
let world = WorldContractReader::new(args.world_address, provider.clone());

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

View check run for this annotation

Codecov / codecov/patch

bin/torii/src/main.rs#L206

Added line #L206 was not covered by tests

let contracts = args.contracts.iter().map(|contract| (contract.address, contract.r#type)).collect();

let (mut executor, sender) = Executor::new(pool.clone(), shutdown_tx.clone()).await?;
tokio::spawn(async move {
Expand Down Expand Up @@ -242,7 +244,7 @@ async fn main() -> anyhow::Result<()> {
},
shutdown_tx.clone(),
Some(block_tx),
Arc::new(contracts),
&contracts,

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

View check run for this annotation

Codecov / codecov/patch

bin/torii/src/main.rs#L247

Added line #L247 was not covered by tests
);

let shutdown_rx = shutdown_tx.subscribe();
Expand Down
6 changes: 4 additions & 2 deletions crates/torii/core/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use crate::processors::store_update_member::StoreUpdateMemberProcessor;
use crate::processors::store_update_record::StoreUpdateRecordProcessor;
use crate::processors::{BlockProcessor, EventProcessor, TransactionProcessor};
use crate::sql::{Cursors, Sql};
use crate::types::ContractType;
use crate::types::{Contract, ContractType};

type EventProcessorMap<P> = HashMap<Felt, Vec<Box<dyn EventProcessor<P>>>>;

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

Self {
world: Arc::new(world),
db,
Expand Down
10 changes: 5 additions & 5 deletions crates/torii/core/src/sql/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::executor::{
Argument, DeleteEntityQuery, EventMessageQuery, QueryMessage, QueryType, ResetCursorsQuery,
SetHeadQuery, UpdateCursorsQuery,
};
use crate::types::ContractType;
use crate::types::Contract;
use crate::utils::utc_dt_string_from_timestamp;

type IsEventMessage = bool;
Expand Down Expand Up @@ -59,17 +59,17 @@ impl Sql {
pub async fn new(
pool: Pool<Sqlite>,
executor: UnboundedSender<QueryMessage>,
contracts: &HashMap<Felt, ContractType>,
contracts: &Vec<Contract>,
) -> Result<Self> {
for contract in contracts {
executor.send(QueryMessage::other(
"INSERT OR IGNORE INTO contracts (id, contract_address, contract_type) VALUES (?, \
?, ?)"
.to_string(),
vec![
Argument::FieldElement(*contract.0),
Argument::FieldElement(*contract.0),
Argument::String(contract.1.to_string()),
Argument::FieldElement(contract.address),
Argument::FieldElement(contract.address),
Argument::String(contract.r#type.to_string()),
],
))?;
}
Expand Down
10 changes: 5 additions & 5 deletions crates/torii/core/src/sql/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use tokio::sync::broadcast;
use crate::engine::{Engine, EngineConfig, Processors};
use crate::executor::Executor;
use crate::sql::Sql;
use crate::types::ContractType;
use crate::types::{Contract, ContractType};

pub async fn bootstrap_engine<P>(
world: WorldContractReader<P>,
Expand All @@ -45,7 +45,7 @@ where
EngineConfig::default(),
shutdown_tx,
None,
Arc::new(HashMap::from([(world_address, ContractType::WORLD)])),
&vec![Contract { address: world_address, r#type: ContractType::WORLD }],
);

let data = engine.fetch_range(0, to, &HashMap::new()).await.unwrap();
Expand Down Expand Up @@ -127,7 +127,7 @@ async fn test_load_from_remote(sequencer: &RunnerCtx) {
let db = Sql::new(
pool.clone(),
sender.clone(),
&HashMap::from([(world_reader.address, ContractType::WORLD)]),
&vec![Contract { address: world_reader.address, r#type: ContractType::WORLD }],
)
.await
.unwrap();
Expand Down Expand Up @@ -285,7 +285,7 @@ async fn test_load_from_remote_del(sequencer: &RunnerCtx) {
let db = Sql::new(
pool.clone(),
sender.clone(),
&HashMap::from([(world_reader.address, ContractType::WORLD)]),
&vec![Contract { address: world_reader.address, r#type: ContractType::WORLD }],

Check warning on line 288 in crates/torii/core/src/sql/test.rs

View check run for this annotation

Codecov / codecov/patch

crates/torii/core/src/sql/test.rs#L288

Added line #L288 was not covered by tests
)
.await
.unwrap();
Expand Down Expand Up @@ -371,7 +371,7 @@ async fn test_update_with_set_record(sequencer: &RunnerCtx) {
let db = Sql::new(
pool.clone(),
sender.clone(),
&HashMap::from([(world_reader.address, ContractType::WORLD)]),
&vec![Contract { address: world_reader.address, r#type: ContractType::WORLD }],
)
.await
.unwrap();
Expand Down
8 changes: 3 additions & 5 deletions crates/torii/graphql/src/tests/metadata_test.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
#[cfg(test)]
mod tests {
use std::collections::HashMap;

use dojo_world::config::{ProfileConfig, WorldMetadata};
use sqlx::SqlitePool;
use starknet::core::types::Felt;
use tokio::sync::broadcast;
use torii_core::executor::Executor;
use torii_core::sql::Sql;
use torii_core::types::ContractType;
use torii_core::types::{Contract, ContractType};

use crate::schema::build_schema;
use crate::tests::{run_graphql_query, Connection, Content, Metadata as SqlMetadata, Social};
Expand Down Expand Up @@ -59,7 +57,7 @@ mod tests {
executor.run().await.unwrap();
});
let mut db =
Sql::new(pool.clone(), sender, &HashMap::from([(Felt::ZERO, ContractType::WORLD)]))
Sql::new(pool.clone(), sender, &vec![Contract { address: Felt::ZERO, r#type: ContractType::WORLD }])
.await
.unwrap();
let schema = build_schema(&pool).await.unwrap();
Expand Down Expand Up @@ -120,7 +118,7 @@ mod tests {
executor.run().await.unwrap();
});
let mut db =
Sql::new(pool.clone(), sender, &HashMap::from([(Felt::ZERO, ContractType::WORLD)]))
Sql::new(pool.clone(), sender, &vec![Contract { address: Felt::ZERO, r#type: ContractType::WORLD }])
.await
.unwrap();
let schema = build_schema(&pool).await.unwrap();
Expand Down
6 changes: 3 additions & 3 deletions crates/torii/graphql/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use tokio_stream::StreamExt;
use torii_core::engine::{Engine, EngineConfig, Processors};
use torii_core::executor::Executor;
use torii_core::sql::Sql;
use torii_core::types::ContractType;
use torii_core::types::{Contract, ContractType};

mod entities_test;
mod events_test;
Expand Down Expand Up @@ -345,7 +345,7 @@ 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, &HashMap::from([(world_address, ContractType::WORLD)]))
let db = Sql::new(pool.clone(), sender, &vec![Contract { address: world_address, r#type: ContractType::WORLD }])
.await
.unwrap();

Expand All @@ -358,7 +358,7 @@ pub async fn spinup_types_test(path: &str) -> Result<SqlitePool> {
EngineConfig::default(),
shutdown_tx,
None,
Arc::new(HashMap::from([(world_address, ContractType::WORLD)])),
&vec![Contract { address: world_address, r#type: ContractType::WORLD }],
);

let to = account.provider().block_hash_and_number().await?.block_number;
Expand Down
13 changes: 6 additions & 7 deletions crates/torii/graphql/src/tests/subscription_test.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#[cfg(test)]
mod tests {
use std::collections::HashMap;
use std::str::FromStr;
use std::time::Duration;

Expand All @@ -17,7 +16,7 @@ mod tests {
use torii_core::executor::Executor;
use torii_core::sql::utils::felts_to_sql_string;
use torii_core::sql::Sql;
use torii_core::types::ContractType;
use torii_core::types::{Contract, ContractType};

use crate::tests::{model_fixtures, run_graphql_subscription};
use crate::utils;
Expand All @@ -32,7 +31,7 @@ mod tests {
executor.run().await.unwrap();
});
let mut db =
Sql::new(pool.clone(), sender, &HashMap::from([(Felt::ZERO, ContractType::WORLD)]))
Sql::new(pool.clone(), sender, &vec![Contract { address: Felt::ZERO, r#type: ContractType::WORLD }])
.await
.unwrap();

Expand Down Expand Up @@ -176,7 +175,7 @@ mod tests {
executor.run().await.unwrap();
});
let mut db =
Sql::new(pool.clone(), sender, &HashMap::from([(Felt::ZERO, ContractType::WORLD)]))
Sql::new(pool.clone(), sender, &vec![Contract { address: Felt::ZERO, r#type: ContractType::WORLD }])
.await
.unwrap();

Expand Down Expand Up @@ -300,7 +299,7 @@ mod tests {
executor.run().await.unwrap();
});
let mut db =
Sql::new(pool.clone(), sender, &HashMap::from([(Felt::ZERO, ContractType::WORLD)]))
Sql::new(pool.clone(), sender, &vec![Contract { address: Felt::ZERO, r#type: ContractType::WORLD }])
.await
.unwrap();
// 0. Preprocess model value
Expand Down Expand Up @@ -374,7 +373,7 @@ mod tests {
executor.run().await.unwrap();
});
let mut db =
Sql::new(pool.clone(), sender, &HashMap::from([(Felt::ZERO, ContractType::WORLD)]))
Sql::new(pool.clone(), sender, &vec![Contract { address: Felt::ZERO, r#type: ContractType::WORLD }])
.await
.unwrap();
// 0. Preprocess model value
Expand Down Expand Up @@ -449,7 +448,7 @@ mod tests {
executor.run().await.unwrap();
});
let mut db =
Sql::new(pool.clone(), sender, &HashMap::from([(Felt::ZERO, ContractType::WORLD)]))
Sql::new(pool.clone(), sender, &vec![Contract { address: Felt::ZERO, r#type: ContractType::WORLD }])
.await
.unwrap();
let block_timestamp: u64 = 1710754478_u64;
Expand Down
6 changes: 3 additions & 3 deletions crates/torii/grpc/src/server/tests/entities_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use tokio::sync::broadcast;
use torii_core::engine::{Engine, EngineConfig, Processors};
use torii_core::executor::Executor;
use torii_core::sql::Sql;
use torii_core::types::ContractType;
use torii_core::types::{Contract, ContractType};

use crate::proto::types::KeysClause;
use crate::server::DojoWorld;
Expand Down Expand Up @@ -92,7 +92,7 @@ async fn test_entities_queries(sequencer: &RunnerCtx) {
tokio::spawn(async move {
executor.run().await.unwrap();
});
let db = Sql::new(pool.clone(), sender, &HashMap::from([(world_address, ContractType::WORLD)]))
let db = Sql::new(pool.clone(), sender, &vec![Contract { address: world_address, r#type: ContractType::WORLD }])
.await
.unwrap();

Expand All @@ -105,7 +105,7 @@ async fn test_entities_queries(sequencer: &RunnerCtx) {
EngineConfig::default(),
shutdown_tx,
None,
Arc::new(HashMap::from([(world_address, ContractType::WORLD)])),
&vec![Contract { address: world_address, r#type: ContractType::WORLD }],
);

let to = provider.block_hash_and_number().await.unwrap().block_number;
Expand Down
5 changes: 2 additions & 3 deletions crates/torii/libp2p/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,6 @@ mod test {
#[cfg(not(target_arch = "wasm32"))]
#[tokio::test]
async fn test_client_messaging() -> Result<(), Box<dyn Error>> {
use std::collections::HashMap;
use std::time::Duration;

use dojo_types::schema::{Member, Struct, Ty};
Expand All @@ -541,7 +540,7 @@ mod test {
use tokio::time::sleep;
use torii_core::executor::Executor;
use torii_core::sql::Sql;
use torii_core::types::ContractType;
use torii_core::types::{Contract, ContractType};

use crate::server::Relay;
use crate::typed_data::{Domain, Field, SimpleField, TypedData};
Expand Down Expand Up @@ -579,7 +578,7 @@ mod test {
executor.run().await.unwrap();
});
let mut db =
Sql::new(pool.clone(), sender, &HashMap::from([(Felt::ZERO, ContractType::WORLD)]))
Sql::new(pool.clone(), sender, &vec![Contract { address: Felt::ZERO, r#type: ContractType::WORLD }])
.await
.unwrap();

Expand Down

0 comments on commit 7c19061

Please sign in to comment.