diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..6472f1a --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,88 @@ +name: CI + +on: + merge_group: + pull_request: + push: + branches: + - main + +env: + CARGO_TERM_COLOR: always + +jobs: + typos: + name: Check Typos + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Run Typos + uses: crate-ci/typos@v1.34.0 + + format: + name: Check Formatting + runs-on: ubuntu-latest + timeout-minutes: 30 + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Install Rust toolchain with rustfmt + uses: dtolnay/rust-toolchain@stable + with: + components: rustfmt + - name: Run cargo fmt --check + run: cargo fmt --all -- --check + + lint: + name: Lint + runs-on: ubuntu-latest + timeout-minutes: 30 + steps: + - name: Checkout sources + uses: actions/checkout@v4 + + - name: Install System Dependencies + run: | + sudo apt-get update + sudo apt-get install --no-install-recommends libasound2-dev libudev-dev protobuf-compiler libprotobuf-dev + + - name: Install Rust toolchain with clippy + uses: dtolnay/rust-toolchain@stable + with: + components: clippy + + - name: Cache Cargo + uses: Swatinem/rust-cache@v2 + with: + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.toml') }} # Unified cache key + + - name: Run Clippy (Linting) + run: cargo clippy --tests --examples -- -D warnings + + - name: Run Rustdoc (Documentation Check) + run: cargo rustdoc -- -D warnings + + test: + name: Build and Test + runs-on: ubuntu-latest + timeout-minutes: 30 + steps: + - name: Checkout sources + uses: actions/checkout@v4 + + - name: Install System Dependencies + run: | + sudo apt-get update + sudo apt-get install --no-install-recommends libasound2-dev libudev-dev protobuf-compiler libprotobuf-dev + + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@stable + + - name: Cache Cargo + uses: Swatinem/rust-cache@v2 + with: + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.toml') }} + + - name: Run Cargo Tests + run: cargo test diff --git a/examples/intro.rs b/examples/intro.rs index 1c8a363..fb748a8 100644 --- a/examples/intro.rs +++ b/examples/intro.rs @@ -202,7 +202,7 @@ fn on_dojo_events( for ev in ev_retrieve_entities.read() { info!(entity_id = ?ev.entity_id, "Torii update"); - // Felt::ZERO is being emitted once, when the subcription is initialized. + // Felt::ZERO is being emitted once, when the subscription is initialized. // We don't want to spawn a cube for this. if ev.entity_id == Felt::ZERO { continue; @@ -215,7 +215,7 @@ fn on_dojo_events( "di-Position" => { ev_position_updated.write(PositionUpdatedEvent(m.into())); } - name if name == "di-Moves".to_string() => {} + "di-Moves" => {} _ => { warn!("Model not handled: {:?}", m); } diff --git a/src/plugin.rs b/src/plugin.rs index e03ea50..cb19e7b 100644 --- a/src/plugin.rs +++ b/src/plugin.rs @@ -77,6 +77,11 @@ pub struct StarknetConnection { >, } +type SubscriptionMessage = (Felt, Vec); + +type SubscriptionSender = Option>>>; +type SubscriptionReceiver = Option>>>; + /// Torii connection state. #[derive(Default)] pub struct ToriiConnection { @@ -85,8 +90,8 @@ pub struct ToriiConnection { pub pending_retrieve_entities: VecDeque>>, pub subscriptions: Arc>>>, - pub subscription_sender: Option)>>>>, - pub subscription_receiver: Option)>>>>, + pub subscription_sender: SubscriptionSender, + pub subscription_receiver: SubscriptionReceiver, } /// Dojo resource that embeds Starknet and Torii connection. @@ -228,7 +233,7 @@ fn check_torii_task( mut ev_initialized: EventWriter, ) { if let Some(task) = &mut dojo.torii.init_task { - if let Ok(Ok(client)) = tokio.runtime.block_on(async { task.await }) { + if let Ok(Ok(client)) = tokio.runtime.block_on(task) { info!("Torii client initialized."); dojo.torii.client = Some(Arc::new(Mutex::new(client))); dojo.torii.init_task = None; @@ -238,7 +243,7 @@ fn check_torii_task( if !dojo.torii.pending_retrieve_entities.is_empty() { if let Some(task) = dojo.torii.pending_retrieve_entities.pop_front() { - if let Ok(Ok(response)) = tokio.runtime.block_on(async { task.await }) { + if let Ok(Ok(response)) = tokio.runtime.block_on(task) { debug!("Retrieve entities response: {:?}", response); for e in response.entities { ev_retrieve_entities.write(DojoEntityUpdated { @@ -270,7 +275,7 @@ fn check_torii_task( /// that have been queued to be sent to the blockchain. fn check_sn_task(tokio: Res, mut dojo: ResMut) { if let Some(task) = &mut dojo.sn.connecting_task { - if let Ok(account) = tokio.runtime.block_on(async { task.await }) { + if let Ok(account) = tokio.runtime.block_on(task) { info!("Connected to Starknet."); dojo.sn.account = Some(account); dojo.sn.connecting_task = None; @@ -279,7 +284,7 @@ fn check_sn_task(tokio: Res, mut dojo: ResMut) { if !dojo.sn.pending_txs.is_empty() && dojo.sn.account.is_some() { if let Some(task) = dojo.sn.pending_txs.pop_front() { - match tokio.runtime.block_on(async { task.await }) { + match tokio.runtime.block_on(task) { Ok(tx_result) => match tx_result { Ok(result) => { info!("Transaction completed: {:#x}", result.transaction_hash);