diff --git a/components/chainhook-cli/src/service/tests/helpers/mock_stacks_node.rs b/components/chainhook-cli/src/service/tests/helpers/mock_stacks_node.rs index 883853689..c07b65475 100644 --- a/components/chainhook-cli/src/service/tests/helpers/mock_stacks_node.rs +++ b/components/chainhook-cli/src/service/tests/helpers/mock_stacks_node.rs @@ -1,7 +1,9 @@ use crate::scan::stacks::{Record, RecordKind}; use crate::service::tests::helpers::mock_bitcoin_rpc::TipData; use chainhook_sdk::indexer::bitcoin::NewBitcoinBlock; -use chainhook_sdk::indexer::stacks::{NewBlock, NewEvent, NewTransaction, RewardSet, RewardSetSigner}; +use chainhook_sdk::indexer::stacks::{ + NewBlock, NewEvent, NewTransaction, RewardSet, RewardSetSigner, +}; use chainhook_sdk::types::{ FTBurnEventData, FTMintEventData, FTTransferEventData, NFTBurnEventData, NFTMintEventData, NFTTransferEventData, STXBurnEventData, STXLockEventData, STXMintEventData, @@ -87,6 +89,13 @@ fn create_stacks_new_event( } else { None }; + let tenure_change_event = if let StacksTransactionEventPayload::TenureChangeEvent(data) = &event + { + event_type = "tenure_change_event".to_string(); + Some(serde_json::to_value(data).unwrap()) + } else { + None + }; let contract_event = if let StacksTransactionEventPayload::SmartContractEvent(data) = &event { event_type = "smart_contract_print_event".to_string(); Some(serde_json::to_value(data).unwrap()) @@ -112,6 +121,7 @@ fn create_stacks_new_event( data_map_insert_event: None, data_map_update_event: None, data_map_delete_event: None, + tenure_change_event, contract_event, } } @@ -336,12 +346,7 @@ pub async fn mine_stacks_block( .map_err(|e| format!("failed to send new_block request: {}", e))? .text() .await - .map_err(|e| { - format!( - "failed to parse response for new_block request: {}", - e - ) - })?; + .map_err(|e| format!("failed to parse response for new_block request: {}", e))?; Ok(()) } @@ -414,12 +419,7 @@ async fn call_new_burn_block( .map_err(|e| format!("failed to send new_burn_block request: {}", e))? .text() .await - .map_err(|e| { - format!( - "failed to parse response for new_burn_block request: {}", - e - ) - })?; + .map_err(|e| format!("failed to parse response for new_burn_block request: {}", e))?; Ok(()) } diff --git a/components/chainhook-sdk/src/indexer/stacks/mod.rs b/components/chainhook-sdk/src/indexer/stacks/mod.rs index 472bc7ab3..5237311f1 100644 --- a/components/chainhook-sdk/src/indexer/stacks/mod.rs +++ b/components/chainhook-sdk/src/indexer/stacks/mod.rs @@ -147,6 +147,7 @@ pub struct NewEvent { pub data_map_insert_event: Option, pub data_map_update_event: Option, pub data_map_delete_event: Option, + pub tenure_change_event: Option, pub contract_event: Option, } @@ -278,6 +279,15 @@ impl NewEvent { index: self.event_index, }, }); + } else if let Some(ref event_data) = self.tenure_change_event { + let data: TenureChangeEventData = + serde_json::from_value(event_data.clone()).expect("Unable to decode event_data"); + return Ok(StacksTransactionEvent { + event_payload: StacksTransactionEventPayload::TenureChangeEvent(data.clone()), + position: StacksTransactionEventPosition { + index: self.event_index, + }, + }); } else if let Some(ref event_data) = self.contract_event { let data: SmartContractEventData = serde_json::from_value(event_data.clone()).expect("Unable to decode event_data"); diff --git a/components/chainhook-sdk/src/indexer/stacks/tests.rs b/components/chainhook-sdk/src/indexer/stacks/tests.rs index 51d4d2a5c..45a56d6d0 100644 --- a/components/chainhook-sdk/src/indexer/stacks/tests.rs +++ b/components/chainhook-sdk/src/indexer/stacks/tests.rs @@ -3,6 +3,7 @@ use chainhook_types::{ FTBurnEventData, FTMintEventData, FTTransferEventData, NFTBurnEventData, NFTMintEventData, NFTTransferEventData, STXBurnEventData, STXLockEventData, STXMintEventData, STXTransferEventData, SmartContractEventData, StacksTransactionEventPayload, + TenureChangeEventData, }; use crate::indexer::tests::helpers::stacks_events::create_new_event_from_stacks_event; @@ -213,10 +214,10 @@ fn test_stacks_vector_040() { process_stacks_blocks_and_check_expectations((helpers::stacks_shapes::get_vector_040(), None)); } -// #[test] -// fn test_stacks_vector_041() { -// process_stacks_blocks_and_check_expectations((helpers::shapes::get_vector_041(), None)); -// } +#[test] +fn test_stacks_vector_041() { + process_stacks_blocks_and_check_expectations((helpers::stacks_shapes::get_vector_041(), None)); +} #[test] fn test_stacks_vector_042() { @@ -363,6 +364,9 @@ fn test_stacks_vector_055() { topic: "print".to_string(), hex_value: String::new(), }); "smart_contract_print_event")] +#[test_case(StacksTransactionEventPayload::TenureChangeEvent(TenureChangeEventData { + consensus_hash: String::new(), +}); "tenure_change_event")] fn new_events_can_be_converted_into_chainhook_event(original_event: StacksTransactionEventPayload) { let new_event = create_new_event_from_stacks_event(original_event.clone()); let event = new_event.into_chainhook_event().unwrap(); @@ -392,6 +396,7 @@ fn into_chainhook_event_rejects_invalid_missing_event() { data_map_insert_event: None, data_map_update_event: None, data_map_delete_event: None, + tenure_change_event: None, contract_event: None, }; new_event diff --git a/components/chainhook-sdk/src/indexer/tests/helpers/stacks_events.rs b/components/chainhook-sdk/src/indexer/tests/helpers/stacks_events.rs index 4ca977bc5..cc9ede7c2 100644 --- a/components/chainhook-sdk/src/indexer/tests/helpers/stacks_events.rs +++ b/components/chainhook-sdk/src/indexer/tests/helpers/stacks_events.rs @@ -91,6 +91,13 @@ pub fn create_new_event_from_stacks_event(event: StacksTransactionEventPayload) } else { None }; + let tenure_change_event = if let StacksTransactionEventPayload::TenureChangeEvent(data) = &event + { + event_type = "tenure_change".to_string(); + Some(serde_json::to_value(data).unwrap()) + } else { + None + }; let contract_event = if let StacksTransactionEventPayload::SmartContractEvent(data) = &event { event_type = "smart_contract_print_event".to_string(); Some(serde_json::to_value(data).unwrap()) @@ -116,6 +123,7 @@ pub fn create_new_event_from_stacks_event(event: StacksTransactionEventPayload) data_map_insert_event, data_map_update_event, data_map_delete_event, + tenure_change_event, contract_event, } } diff --git a/docs/chainhook-openapi.json b/docs/chainhook-openapi.json index 989f3c230..7d535bfe8 100644 --- a/docs/chainhook-openapi.json +++ b/docs/chainhook-openapi.json @@ -1180,6 +1180,27 @@ } } }, + { + "type": "object", + "required": [ + "actions", + "scope" + ], + "properties": { + "scope": { + "type": "string", + "enum": [ + "tenure_change" + ] + }, + "actions": { + "type": "array", + "items": { + "type": "string" + } + } + } + }, { "type": "object", "oneOf": [