From 37f422780c50a9f567f206a39b7d22e814d75b96 Mon Sep 17 00:00:00 2001 From: Alexander Evgin Date: Tue, 19 Nov 2024 20:43:12 +0400 Subject: [PATCH 1/3] Add GitHub workflow with basic Rust checks --- .github/workflows/ci.yaml | 46 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 .github/workflows/ci.yaml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..e32b8d4 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,46 @@ +name: Check gevulot-rs + +on: + pull_request: + push: + branches: + - main + tags: + - "*" + +jobs: + test: + name: All gevulot-rs checks + runs-on: ubuntu-latest + steps: + - name: Checkout source code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Install buf + uses: bufbuild/buf-setup-action@v1 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + + - name: Install Protoc + uses: arduino/setup-protoc@v3 + + - name: Install Rust + uses: dtolnay/rust-toolchain@stable + + - name: Use Rust cache + uses: Swatinem/rust-cache@v2 + + - name: Check formatting + run: cargo fmt --check + + - name: Check build + run: cargo check --locked + + # TODO: re-enable this after fixing all clippy warnings + # - name: Run linting + # run: cargo clippy --locked --no-deps -- --deny warnings + + - name: Run runtime-config tests + run: cargo test --locked runtime_config From 4d138c149cee38abb178a9700c5e6953f8a79ba0 Mon Sep 17 00:00:00 2001 From: Alexander Evgin Date: Tue, 19 Nov 2024 20:43:26 +0400 Subject: [PATCH 2/3] runtime-config: fix some tests --- src/runtime_config.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/runtime_config.rs b/src/runtime_config.rs index 8cfe256..c783d22 100644 --- a/src/runtime_config.rs +++ b/src/runtime_config.rs @@ -190,6 +190,7 @@ mod tests { } const EXAMPLE_CONFIG: &str = " + version: 1 working-dir: / command: prover args: [--log, info] @@ -213,7 +214,7 @@ mod tests { .expect("deserialization should succeed"); assert_eq!( &result.command.expect("command should be present"), - "/prover" + "prover" ); assert_eq!(result.args, vec!["--log".to_string(), "info".to_string()]); assert_eq!(result.env.len(), 1); From c4c508e12ccb9b8521a6dd86a8f8361037a0f168 Mon Sep 17 00:00:00 2001 From: Alexander Evgin Date: Tue, 19 Nov 2024 20:46:28 +0400 Subject: [PATCH 3/3] Fix code formatting Using default rustfmt settings, because we don't have rustfmt.toml here --- src/event_fetcher.rs | 12 +- src/events.rs | 580 +++++++++++++++++++++++++++++++----------- src/gevulot_client.rs | 2 +- src/lib.rs | 5 +- src/sudo_client.rs | 22 +- 5 files changed, 459 insertions(+), 162 deletions(-) diff --git a/src/event_fetcher.rs b/src/event_fetcher.rs index a25033b..546202c 100644 --- a/src/event_fetcher.rs +++ b/src/event_fetcher.rs @@ -107,7 +107,9 @@ where async fn process_block_results(&mut self, block_results: &BlockResults) -> Result<()> { if let Some(events) = &block_results.begin_block_events { for event in events.iter() { - self.handler.handle_event(event, block_results.height).await?; + self.handler + .handle_event(event, block_results.height) + .await?; } } if let Some(txs_results) = &block_results.txs_results { @@ -119,11 +121,15 @@ where } if let Some(events) = &block_results.end_block_events { for event in events.iter() { - self.handler.handle_event(event, block_results.height).await?; + self.handler + .handle_event(event, block_results.height) + .await?; } } for event in block_results.finalize_block_events.iter() { - self.handler.handle_event(event, block_results.height).await?; + self.handler + .handle_event(event, block_results.height) + .await?; } Ok(()) } diff --git a/src/events.rs b/src/events.rs index b1487e2..898e3cf 100644 --- a/src/events.rs +++ b/src/events.rs @@ -139,7 +139,11 @@ impl GevulotEvent { .filter(|attr| attr.key_bytes() == b"assigned-workers") .flat_map(|attr| { attr.value_str() - .map(|s| s.split(',').map(|x| x.trim().to_string()).collect::>()) + .map(|s| { + s.split(',') + .map(|x| x.trim().to_string()) + .collect::>() + }) .unwrap_or_default() }) .collect::>(); @@ -389,7 +393,11 @@ impl GevulotEvent { .filter(|attr| attr.key_bytes() == b"assigned-workers") .flat_map(|attr| { attr.value_str() - .map(|s| s.split(',').map(|x| x.trim().to_string()).collect::>()) + .map(|s| { + s.split(',') + .map(|x| x.trim().to_string()) + .collect::>() + }) .unwrap_or_default() }) .collect::>(); @@ -407,11 +415,15 @@ impl GevulotEvent { .filter(|attr| attr.key_bytes() == b"fallback-urls") .flat_map(|attr| { attr.value_str() - .map(|s| s.split(',').map(|x| x.trim().to_string()).collect::>()) + .map(|s| { + s.split(',') + .map(|x| x.trim().to_string()) + .collect::>() + }) .unwrap_or_default() }) .collect::>(); - + Ok(GevulotEvent::Pin(PinEvent::Create(PinCreateEvent { block_height, cid, @@ -633,328 +645,600 @@ mod tests { use super::*; use cosmrs::{rpc::dialect::v0_34::EventAttribute, tendermint::abci::Event}; - + #[test] fn test_from_cosmos_create_pin() { - let event = Event::new("create-pin", vec![ - EventAttribute{index: true, key: b"cid".to_vec(), value: b"QmYwMXeEc3Z64vqcPXx8p8Y8Y5tE9Y5sYW42FZ1U87Y".to_vec()}, - EventAttribute{index: true, key: b"creator".to_vec(), value: b"cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh".to_vec()}, - EventAttribute{index: true, key: b"assigned-workers".to_vec(), value: b"1,2,3".to_vec()}, - EventAttribute{index: true, key: b"retention-period".to_vec(), value: b"86400".to_vec()}, - EventAttribute{index: true, key: b"fallback-urls".to_vec(), value: b"https://example1.com,https://example2.org".to_vec()}, - EventAttribute{index: true, key: b"fallback-urls".to_vec(), value: b"https://example3.com".to_vec()}, - ]); - - + let event = Event::new( + "create-pin", + vec![ + EventAttribute { + index: true, + key: b"cid".to_vec(), + value: b"QmYwMXeEc3Z64vqcPXx8p8Y8Y5tE9Y5sYW42FZ1U87Y".to_vec(), + }, + EventAttribute { + index: true, + key: b"creator".to_vec(), + value: b"cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh".to_vec(), + }, + EventAttribute { + index: true, + key: b"assigned-workers".to_vec(), + value: b"1,2,3".to_vec(), + }, + EventAttribute { + index: true, + key: b"retention-period".to_vec(), + value: b"86400".to_vec(), + }, + EventAttribute { + index: true, + key: b"fallback-urls".to_vec(), + value: b"https://example1.com,https://example2.org".to_vec(), + }, + EventAttribute { + index: true, + key: b"fallback-urls".to_vec(), + value: b"https://example3.com".to_vec(), + }, + ], + ); + let parsed = GevulotEvent::from_cosmos(&event, Height::from(1000u32)); - + assert!(parsed.is_ok()); if let Ok(GevulotEvent::Pin(PinEvent::Create(event))) = parsed { assert_eq!(event.block_height, Height::from(1000u32)); assert_eq!(event.cid, "QmYwMXeEc3Z64vqcPXx8p8Y8Y5tE9Y5sYW42FZ1U87Y"); - assert_eq!(event.creator, "cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh"); + assert_eq!( + event.creator, + "cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh" + ); assert_eq!(event.assigned_workers, vec!["1", "2", "3"]); assert_eq!(event.retention_period, 86400); - assert_eq!(event.fallback_urls, vec!["https://example1.com", "https://example2.org", "https://example3.com"]); + assert_eq!( + event.fallback_urls, + vec![ + "https://example1.com", + "https://example2.org", + "https://example3.com" + ] + ); } else { panic!("Unexpected event type"); - } + } } #[test] fn test_from_cosmos_delete_pin() { - let event = Event::new("delete-pin", vec![ - EventAttribute{index: true, key: b"cid".to_vec(), value: b"QmYwMXeEc3Z64vqcPXx8p8Y8Y5tE9Y5sYW42FZ1U87Y".to_vec()}, - EventAttribute{index: true, key: b"creator".to_vec(), value: b"cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh".to_vec()}, - ]); - + let event = Event::new( + "delete-pin", + vec![ + EventAttribute { + index: true, + key: b"cid".to_vec(), + value: b"QmYwMXeEc3Z64vqcPXx8p8Y8Y5tE9Y5sYW42FZ1U87Y".to_vec(), + }, + EventAttribute { + index: true, + key: b"creator".to_vec(), + value: b"cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh".to_vec(), + }, + ], + ); + let parsed = GevulotEvent::from_cosmos(&event, Height::from(1000u32)); - + assert!(parsed.is_ok()); if let Ok(GevulotEvent::Pin(PinEvent::Delete(event))) = parsed { assert_eq!(event.block_height, Height::from(1000u32)); assert_eq!(event.cid, "QmYwMXeEc3Z64vqcPXx8p8Y8Y5tE9Y5sYW42FZ1U87Y"); - assert_eq!(event.creator, "cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh"); + assert_eq!( + event.creator, + "cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh" + ); } else { panic!("Unexpected event type"); - } + } } #[test] fn test_from_cosmos_ack_pin() { - let event = Event::new("ack-pin", vec![ - EventAttribute{index: true, key: b"cid".to_vec(), value: b"QmYwMXeEc3Z64vqcPXx8p8Y8Y5tE9Y5sYW42FZ1U87Y".to_vec()}, - EventAttribute{index: true, key: b"worker-id".to_vec(), value: b"worker1".to_vec()}, - EventAttribute{index: true, key: b"creator".to_vec(), value: b"cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh".to_vec()}, - ]); - + let event = Event::new( + "ack-pin", + vec![ + EventAttribute { + index: true, + key: b"cid".to_vec(), + value: b"QmYwMXeEc3Z64vqcPXx8p8Y8Y5tE9Y5sYW42FZ1U87Y".to_vec(), + }, + EventAttribute { + index: true, + key: b"worker-id".to_vec(), + value: b"worker1".to_vec(), + }, + EventAttribute { + index: true, + key: b"creator".to_vec(), + value: b"cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh".to_vec(), + }, + ], + ); + let parsed = GevulotEvent::from_cosmos(&event, Height::from(1000u32)); - + assert!(parsed.is_ok()); if let Ok(GevulotEvent::Pin(PinEvent::Ack(event))) = parsed { assert_eq!(event.block_height, Height::from(1000u32)); assert_eq!(event.cid, "QmYwMXeEc3Z64vqcPXx8p8Y8Y5tE9Y5sYW42FZ1U87Y"); assert_eq!(event.worker_id, "worker1"); - assert_eq!(event.creator, "cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh"); + assert_eq!( + event.creator, + "cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh" + ); } else { panic!("Unexpected event type"); - } + } } #[test] fn test_from_cosmos_create_worker() { - let event = Event::new("create-worker", vec![ - EventAttribute{index: true, key: b"worker-id".to_vec(), value: b"worker1".to_vec()}, - EventAttribute{index: true, key: b"creator".to_vec(), value: b"cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh".to_vec()}, - ]); - + let event = Event::new( + "create-worker", + vec![ + EventAttribute { + index: true, + key: b"worker-id".to_vec(), + value: b"worker1".to_vec(), + }, + EventAttribute { + index: true, + key: b"creator".to_vec(), + value: b"cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh".to_vec(), + }, + ], + ); + let parsed = GevulotEvent::from_cosmos(&event, Height::from(1000u32)); - + assert!(parsed.is_ok()); if let Ok(GevulotEvent::Worker(WorkerEvent::Create(event))) = parsed { assert_eq!(event.block_height, Height::from(1000u32)); assert_eq!(event.worker_id, "worker1"); - assert_eq!(event.creator, "cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh"); + assert_eq!( + event.creator, + "cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh" + ); } else { panic!("Unexpected event type"); - } + } } #[test] fn test_from_cosmos_update_worker() { - let event = Event::new("update-worker", vec![ - EventAttribute{index: true, key: b"worker-id".to_vec(), value: b"worker1".to_vec()}, - EventAttribute{index: true, key: b"creator".to_vec(), value: b"cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh".to_vec()}, - ]); - + let event = Event::new( + "update-worker", + vec![ + EventAttribute { + index: true, + key: b"worker-id".to_vec(), + value: b"worker1".to_vec(), + }, + EventAttribute { + index: true, + key: b"creator".to_vec(), + value: b"cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh".to_vec(), + }, + ], + ); + let parsed = GevulotEvent::from_cosmos(&event, Height::from(1000u32)); - + assert!(parsed.is_ok()); if let Ok(GevulotEvent::Worker(WorkerEvent::Update(event))) = parsed { assert_eq!(event.block_height, Height::from(1000u32)); assert_eq!(event.worker_id, "worker1"); - assert_eq!(event.creator, "cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh"); + assert_eq!( + event.creator, + "cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh" + ); } else { panic!("Unexpected event type"); - } + } } #[test] fn test_from_cosmos_delete_worker() { - let event = Event::new("delete-worker", vec![ - EventAttribute{index: true, key: b"worker-id".to_vec(), value: b"worker1".to_vec()}, - EventAttribute{index: true, key: b"creator".to_vec(), value: b"cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh".to_vec()}, - ]); - + let event = Event::new( + "delete-worker", + vec![ + EventAttribute { + index: true, + key: b"worker-id".to_vec(), + value: b"worker1".to_vec(), + }, + EventAttribute { + index: true, + key: b"creator".to_vec(), + value: b"cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh".to_vec(), + }, + ], + ); + let parsed = GevulotEvent::from_cosmos(&event, Height::from(1000u32)); - + assert!(parsed.is_ok()); if let Ok(GevulotEvent::Worker(WorkerEvent::Delete(event))) = parsed { assert_eq!(event.block_height, Height::from(1000u32)); assert_eq!(event.worker_id, "worker1"); - assert_eq!(event.creator, "cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh"); + assert_eq!( + event.creator, + "cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh" + ); } else { panic!("Unexpected event type"); - } + } } #[test] fn test_from_cosmos_announce_worker_exit() { - let event = Event::new("announce-worker-exit", vec![ - EventAttribute{index: true, key: b"worker-id".to_vec(), value: b"worker1".to_vec()}, - EventAttribute{index: true, key: b"creator".to_vec(), value: b"cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh".to_vec()}, - ]); - + let event = Event::new( + "announce-worker-exit", + vec![ + EventAttribute { + index: true, + key: b"worker-id".to_vec(), + value: b"worker1".to_vec(), + }, + EventAttribute { + index: true, + key: b"creator".to_vec(), + value: b"cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh".to_vec(), + }, + ], + ); + let parsed = GevulotEvent::from_cosmos(&event, Height::from(1000u32)); - + assert!(parsed.is_ok()); if let Ok(GevulotEvent::Worker(WorkerEvent::AnnounceExit(event))) = parsed { assert_eq!(event.block_height, Height::from(1000u32)); assert_eq!(event.worker_id, "worker1"); - assert_eq!(event.creator, "cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh"); + assert_eq!( + event.creator, + "cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh" + ); } else { panic!("Unexpected event type"); - } + } } #[test] fn test_from_cosmos_create_task() { - let event = Event::new("create-task", vec![ - EventAttribute{index: true, key: b"task-id".to_vec(), value: b"task1".to_vec()}, - EventAttribute{index: true, key: b"creator".to_vec(), value: b"cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh".to_vec()}, - EventAttribute{index: true, key: b"assigned-workers".to_vec(), value: b"worker1,worker2".to_vec()}, - EventAttribute{index: true, key: b"assigned-workers".to_vec(), value: b"worker3".to_vec()}, - - ]); - + let event = Event::new( + "create-task", + vec![ + EventAttribute { + index: true, + key: b"task-id".to_vec(), + value: b"task1".to_vec(), + }, + EventAttribute { + index: true, + key: b"creator".to_vec(), + value: b"cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh".to_vec(), + }, + EventAttribute { + index: true, + key: b"assigned-workers".to_vec(), + value: b"worker1,worker2".to_vec(), + }, + EventAttribute { + index: true, + key: b"assigned-workers".to_vec(), + value: b"worker3".to_vec(), + }, + ], + ); + let parsed = GevulotEvent::from_cosmos(&event, Height::from(1000u32)); - + assert!(parsed.is_ok()); if let Ok(GevulotEvent::Task(TaskEvent::Create(event))) = parsed { assert_eq!(event.block_height, Height::from(1000u32)); assert_eq!(event.task_id, "task1"); - assert_eq!(event.creator, "cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh"); - assert_eq!(event.assigned_workers, vec!["worker1", "worker2", "worker3"]); + assert_eq!( + event.creator, + "cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh" + ); + assert_eq!( + event.assigned_workers, + vec!["worker1", "worker2", "worker3"] + ); } else { panic!("Unexpected event type"); - } + } } #[test] fn test_from_cosmos_delete_task() { - let event = Event::new("delete-task", vec![ - EventAttribute{index: true, key: b"task-id".to_vec(), value: b"task1".to_vec()}, - EventAttribute{index: true, key: b"creator".to_vec(), value: b"cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh".to_vec()}, - ]); - + let event = Event::new( + "delete-task", + vec![ + EventAttribute { + index: true, + key: b"task-id".to_vec(), + value: b"task1".to_vec(), + }, + EventAttribute { + index: true, + key: b"creator".to_vec(), + value: b"cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh".to_vec(), + }, + ], + ); + let parsed = GevulotEvent::from_cosmos(&event, Height::from(1000u32)); - + assert!(parsed.is_ok()); if let Ok(GevulotEvent::Task(TaskEvent::Delete(event))) = parsed { assert_eq!(event.block_height, Height::from(1000u32)); assert_eq!(event.task_id, "task1"); - assert_eq!(event.creator, "cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh"); + assert_eq!( + event.creator, + "cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh" + ); } else { panic!("Unexpected event type"); - } + } } #[test] fn test_from_cosmos_finish_task() { - let event = Event::new("finish-task", vec![ - EventAttribute{index: true, key: b"task-id".to_vec(), value: b"task1".to_vec()}, - EventAttribute{index: true, key: b"creator".to_vec(), value: b"cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh".to_vec()}, - EventAttribute{index: true, key: b"worker-id".to_vec(), value: b"worker1".to_vec()}, - ]); - + let event = Event::new( + "finish-task", + vec![ + EventAttribute { + index: true, + key: b"task-id".to_vec(), + value: b"task1".to_vec(), + }, + EventAttribute { + index: true, + key: b"creator".to_vec(), + value: b"cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh".to_vec(), + }, + EventAttribute { + index: true, + key: b"worker-id".to_vec(), + value: b"worker1".to_vec(), + }, + ], + ); + let parsed = GevulotEvent::from_cosmos(&event, Height::from(1000u32)); - + assert!(parsed.is_ok()); if let Ok(GevulotEvent::Task(TaskEvent::Finish(event))) = parsed { assert_eq!(event.block_height, Height::from(1000u32)); assert_eq!(event.task_id, "task1"); - assert_eq!(event.creator, "cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh"); + assert_eq!( + event.creator, + "cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh" + ); assert_eq!(event.worker_id, "worker1"); } else { panic!("Unexpected event type"); - } + } } #[test] fn test_from_cosmos_create_workflow() { - let event = Event::new("create-workflow", vec![ - EventAttribute{index: true, key: b"workflow-id".to_vec(), value: b"workflow1".to_vec()}, - EventAttribute{index: true, key: b"creator".to_vec(), value: b"cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh".to_vec()}, - ]); - + let event = Event::new( + "create-workflow", + vec![ + EventAttribute { + index: true, + key: b"workflow-id".to_vec(), + value: b"workflow1".to_vec(), + }, + EventAttribute { + index: true, + key: b"creator".to_vec(), + value: b"cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh".to_vec(), + }, + ], + ); + let parsed = GevulotEvent::from_cosmos(&event, Height::from(1000u32)); - + assert!(parsed.is_ok()); if let Ok(GevulotEvent::Workflow(WorkflowEvent::Create(event))) = parsed { assert_eq!(event.block_height, Height::from(1000u32)); assert_eq!(event.workflow_id, "workflow1"); - assert_eq!(event.creator, "cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh"); + assert_eq!( + event.creator, + "cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh" + ); } else { panic!("Unexpected event type"); - } + } } #[test] fn test_from_cosmos_delete_workflow() { - let event = Event::new("delete-workflow", vec![ - EventAttribute{index: true, key: b"workflow-id".to_vec(), value: b"workflow1".to_vec()}, - EventAttribute{index: true, key: b"creator".to_vec(), value: b"cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh".to_vec()}, - ]); - + let event = Event::new( + "delete-workflow", + vec![ + EventAttribute { + index: true, + key: b"workflow-id".to_vec(), + value: b"workflow1".to_vec(), + }, + EventAttribute { + index: true, + key: b"creator".to_vec(), + value: b"cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh".to_vec(), + }, + ], + ); + let parsed = GevulotEvent::from_cosmos(&event, Height::from(1000u32)); - + assert!(parsed.is_ok()); if let Ok(GevulotEvent::Workflow(WorkflowEvent::Delete(event))) = parsed { assert_eq!(event.block_height, Height::from(1000u32)); assert_eq!(event.workflow_id, "workflow1"); - assert_eq!(event.creator, "cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh"); + assert_eq!( + event.creator, + "cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh" + ); } else { panic!("Unexpected event type"); - } + } } #[test] fn test_from_cosmos_progress_workflow() { - let event = Event::new("progress-workflow", vec![ - EventAttribute{index: true, key: b"workflow-id".to_vec(), value: b"workflow1".to_vec()}, - EventAttribute{index: true, key: b"creator".to_vec(), value: b"cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh".to_vec()}, - ]); - + let event = Event::new( + "progress-workflow", + vec![ + EventAttribute { + index: true, + key: b"workflow-id".to_vec(), + value: b"workflow1".to_vec(), + }, + EventAttribute { + index: true, + key: b"creator".to_vec(), + value: b"cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh".to_vec(), + }, + ], + ); + let parsed = GevulotEvent::from_cosmos(&event, Height::from(1000u32)); - + assert!(parsed.is_ok()); if let Ok(GevulotEvent::Workflow(WorkflowEvent::Progress(event))) = parsed { assert_eq!(event.block_height, Height::from(1000u32)); assert_eq!(event.workflow_id, "workflow1"); - assert_eq!(event.creator, "cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh"); + assert_eq!( + event.creator, + "cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh" + ); } else { panic!("Unexpected event type"); - } + } } #[test] fn test_from_cosmos_finish_workflow() { - let event = Event::new("finish-workflow", vec![ - EventAttribute{index: true, key: b"workflow-id".to_vec(), value: b"workflow1".to_vec()}, - EventAttribute{index: true, key: b"creator".to_vec(), value: b"cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh".to_vec()}, - ]); - + let event = Event::new( + "finish-workflow", + vec![ + EventAttribute { + index: true, + key: b"workflow-id".to_vec(), + value: b"workflow1".to_vec(), + }, + EventAttribute { + index: true, + key: b"creator".to_vec(), + value: b"cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh".to_vec(), + }, + ], + ); + let parsed = GevulotEvent::from_cosmos(&event, Height::from(1000u32)); - + assert!(parsed.is_ok()); if let Ok(GevulotEvent::Workflow(WorkflowEvent::Finish(event))) = parsed { assert_eq!(event.block_height, Height::from(1000u32)); assert_eq!(event.workflow_id, "workflow1"); - assert_eq!(event.creator, "cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh"); + assert_eq!( + event.creator, + "cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh" + ); } else { panic!("Unexpected event type"); - } + } } #[test] fn test_from_cosmos_accept_task() { - let event = Event::new("accept-task", vec![ - EventAttribute{index: true, key: b"task-id".to_vec(), value: b"task1".to_vec()}, - EventAttribute{index: true, key: b"worker-id".to_vec(), value: b"worker1".to_vec()}, - EventAttribute{index: true, key: b"creator".to_vec(), value: b"cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh".to_vec()}, - ]); - + let event = Event::new( + "accept-task", + vec![ + EventAttribute { + index: true, + key: b"task-id".to_vec(), + value: b"task1".to_vec(), + }, + EventAttribute { + index: true, + key: b"worker-id".to_vec(), + value: b"worker1".to_vec(), + }, + EventAttribute { + index: true, + key: b"creator".to_vec(), + value: b"cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh".to_vec(), + }, + ], + ); + let parsed = GevulotEvent::from_cosmos(&event, Height::from(1000u32)); - + assert!(parsed.is_ok()); if let Ok(GevulotEvent::Task(TaskEvent::Accept(event))) = parsed { assert_eq!(event.block_height, Height::from(1000u32)); assert_eq!(event.task_id, "task1"); assert_eq!(event.worker_id, "worker1"); - assert_eq!(event.creator, "cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh"); + assert_eq!( + event.creator, + "cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh" + ); } else { panic!("Unexpected event type"); - } + } } #[test] fn test_from_cosmos_decline_task() { - let event = Event::new("decline-task", vec![ - EventAttribute{index: true, key: b"task-id".to_vec(), value: b"task1".to_vec()}, - EventAttribute{index: true, key: b"worker-id".to_vec(), value: b"worker1".to_vec()}, - EventAttribute{index: true, key: b"creator".to_vec(), value: b"cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh".to_vec()}, - ]); - + let event = Event::new( + "decline-task", + vec![ + EventAttribute { + index: true, + key: b"task-id".to_vec(), + value: b"task1".to_vec(), + }, + EventAttribute { + index: true, + key: b"worker-id".to_vec(), + value: b"worker1".to_vec(), + }, + EventAttribute { + index: true, + key: b"creator".to_vec(), + value: b"cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh".to_vec(), + }, + ], + ); + let parsed = GevulotEvent::from_cosmos(&event, Height::from(1000u32)); - + assert!(parsed.is_ok()); if let Ok(GevulotEvent::Task(TaskEvent::Decline(event))) = parsed { assert_eq!(event.block_height, Height::from(1000u32)); assert_eq!(event.task_id, "task1"); assert_eq!(event.worker_id, "worker1"); - assert_eq!(event.creator, "cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh"); + assert_eq!( + event.creator, + "cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh" + ); } else { panic!("Unexpected event type"); - } + } } -} \ No newline at end of file +} diff --git a/src/gevulot_client.rs b/src/gevulot_client.rs index ee3bf8d..174f8a7 100644 --- a/src/gevulot_client.rs +++ b/src/gevulot_client.rs @@ -2,9 +2,9 @@ use crate::base_client::BaseClient; use crate::error::Result; use crate::gov_client::GovClient; use crate::pin_client::PinClient; +use crate::sudo_client::SudoClient; use crate::task_client::TaskClient; use crate::worker_client::WorkerClient; -use crate::sudo_client::SudoClient; use std::sync::Arc; use tokio::sync::RwLock; diff --git a/src/lib.rs b/src/lib.rs index 8c654dd..e0dca59 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,14 +6,14 @@ pub mod builders; pub mod gevulot_client; /// This module contains the client implementation for managing pins. pub mod pin_client; +/// This module contains the client implementation for sudo functionality. +pub mod sudo_client; /// This module contains the client implementation for managing tasks. pub mod task_client; /// This module contains the client implementation for managing workers. pub mod worker_client; /// This module contains the client implementation for managing workflows. pub mod workflow_client; -/// This module contains the client implementation for sudo functionality. -pub mod sudo_client; pub mod models; pub mod runtime_config; @@ -199,5 +199,4 @@ mod tests { cli.workers.delete(delete_worker_msg).await.unwrap(); } - } diff --git a/src/sudo_client.rs b/src/sudo_client.rs index fe9d3a5..5186734 100644 --- a/src/sudo_client.rs +++ b/src/sudo_client.rs @@ -5,10 +5,9 @@ use crate::{ base_client::BaseClient, error::Result, proto::gevulot::gevulot::{ - MsgSudoDeletePin, MsgSudoDeletePinResponse, - MsgSudoDeleteWorker, MsgSudoDeleteWorkerResponse, - MsgSudoDeleteTask, MsgSudoDeleteTaskResponse, - MsgSudoFreezeAccount, MsgSudoFreezeAccountResponse, + MsgSudoDeletePin, MsgSudoDeletePinResponse, MsgSudoDeleteTask, MsgSudoDeleteTaskResponse, + MsgSudoDeleteWorker, MsgSudoDeleteWorkerResponse, MsgSudoFreezeAccount, + MsgSudoFreezeAccountResponse, }, }; @@ -68,7 +67,10 @@ impl SudoClient { /// # Errors /// /// This function will return an error if the request to the Gevulot client fails. - pub async fn delete_worker(&mut self, msg: MsgSudoDeleteWorker) -> Result { + pub async fn delete_worker( + &mut self, + msg: MsgSudoDeleteWorker, + ) -> Result { let resp: MsgSudoDeleteWorkerResponse = self .base_client .write() @@ -91,7 +93,10 @@ impl SudoClient { /// # Errors /// /// This function will return an error if the request to the Gevulot client fails. - pub async fn delete_task(&mut self, msg: MsgSudoDeleteTask) -> Result { + pub async fn delete_task( + &mut self, + msg: MsgSudoDeleteTask, + ) -> Result { let resp: MsgSudoDeleteTaskResponse = self .base_client .write() @@ -114,7 +119,10 @@ impl SudoClient { /// # Errors /// /// This function will return an error if the request to the Gevulot client fails. - pub async fn freeze_account(&mut self, msg: MsgSudoFreezeAccount) -> Result { + pub async fn freeze_account( + &mut self, + msg: MsgSudoFreezeAccount, + ) -> Result { let resp: MsgSudoFreezeAccountResponse = self .base_client .write()