Skip to content

Commit

Permalink
fix: broken tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ludo Galabru committed Dec 26, 2023
1 parent ad33417 commit 7a0209b
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 10 deletions.
2 changes: 1 addition & 1 deletion components/chainhook-cli/src/scan/bitcoin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ pub async fn execute_predicates_action<'a>(
Ok(action) => {
actions_triggered += 1;
match action {
BitcoinChainhookOccurrence::Http(request) => {
BitcoinChainhookOccurrence::Http(request, _) => {
send_request(request, 10, 3, &ctx).await?
}
BitcoinChainhookOccurrence::File(path, bytes) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use chainhook_sdk::bitcoin::Network;
use chainhook_sdk::bitcoincore_rpc_json::GetRawTransactionResultVoutScriptPubKey;
use chainhook_sdk::indexer::bitcoin::BitcoinBlockFullBreakdown;
use chainhook_sdk::indexer::bitcoin::BitcoinTransactionFullBreakdown;
Expand Down Expand Up @@ -36,7 +37,7 @@ struct Rpc {

fn branch_and_height_to_hash(branch: Option<char>, height: u64) -> BlockHash {
let hash = Hash::from_str(&branch_and_height_to_hash_str(branch, height)).unwrap();
BlockHash::from_hash(hash)
BlockHash::from_raw_hash(hash)
}

#[derive(Clone, Serialize, Deserialize, Debug)]
Expand Down Expand Up @@ -139,7 +140,8 @@ fn handle_rpc(
hex: vec![],
req_sigs: None,
type_: None,
addresses: None,
addresses: vec![],
address: None
},
}],
};
Expand All @@ -164,7 +166,8 @@ fn handle_rpc(
hex: vec![],
req_sigs: None,
type_: None,
addresses: None,
addresses: vec![],
address: None
},
}],
};
Expand Down Expand Up @@ -192,7 +195,7 @@ fn handle_rpc(

let hash = branch_and_height_to_hash(Some(*branch), *chain_tip);
let blockchain_info = GetBlockchainInfoResult {
chain: "regtest".into(),
chain: Network::Regtest,
blocks: chain_tip.to_owned(),
headers: 0,
best_block_hash: hash,
Expand Down
2 changes: 1 addition & 1 deletion components/chainhook-sdk/src/chainhooks/bitcoin/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ fn test_opreturn_evaluation(script_pubkey: &str, rule: MatchingRule, matches: bo
)]
fn test_descriptor_evaluation(addr: &str, expr: &str) {
// turn the address into a script_pubkey with a 0x prefix, as expected by the evaluator.
let script_pubkey = Address::from_str(addr).unwrap().script_pubkey();
let script_pubkey = Address::from_str(addr).unwrap().assume_checked().script_pubkey();
let matching_script_pubkey = format!("0x{}", hex::encode(script_pubkey));

let rule = DescriptorMatchingRule {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,32 @@ pub fn generate_test_tx_bitcoin_p2pkh_transfer(
let pubkey_hash = recipient
.from_base58()
.expect("Unable to get bytes from btc address");
let slice = [
pubkey_hash[1],
pubkey_hash[2],
pubkey_hash[3],
pubkey_hash[4],
pubkey_hash[5],
pubkey_hash[6],
pubkey_hash[7],
pubkey_hash[8],
pubkey_hash[9],
pubkey_hash[10],
pubkey_hash[11],
pubkey_hash[12],
pubkey_hash[13],
pubkey_hash[14],
pubkey_hash[15],
pubkey_hash[16],
pubkey_hash[17],
pubkey_hash[18],
pubkey_hash[19],
pubkey_hash[20],
];
let script = BitcoinScriptBuilder::new()
.push_opcode(opcodes::all::OP_DUP)
.push_opcode(opcodes::all::OP_HASH160)
.push_slice(&pubkey_hash[1..21])
.push_slice(&slice)
.push_opcode(opcodes::all::OP_EQUALVERIFY)
.push_opcode(opcodes::all::OP_CHECKSIG)
.into_script();
Expand Down
9 changes: 6 additions & 3 deletions components/chainhook-sdk/src/observer/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use chainhook_types::{
BitcoinBlockSignaling, BitcoinChainEvent, BitcoinNetwork, BlockchainEvent,
BlockchainUpdatedWithHeaders, OrdinalInscriptionRevealData, OrdinalOperation,
StacksBlockUpdate, StacksChainEvent, StacksChainUpdatedWithBlocksData, StacksNetwork,
StacksNodeConfig,
StacksNodeConfig, OrdinalInscriptionNumber,
};
use hiro_system_kit;
use std::collections::BTreeMap;
Expand Down Expand Up @@ -1139,19 +1139,22 @@ fn test_bitcoin_chainhook_through_reorg() {
// The block pre-processor will simulate block augmentation with new informations, which should trigger
// registered predicates
let block_pre_processor_handle = std::thread::spawn(move || {
let mut cursor: u64 = 0;
let mut inscription_number = OrdinalInscriptionNumber::zero();
let mut cursor = 0;
while let Ok((mut blocks, _)) = block_pre_processor_in_rx.recv() {
for b in blocks.iter_mut() {
for (tx_index, tx) in b.block.transactions.iter_mut().enumerate() {
cursor += 1;
inscription_number.classic += 1;
inscription_number.jubilee += 1;
tx.metadata
.ordinal_operations
.push(OrdinalOperation::InscriptionRevealed(
OrdinalInscriptionRevealData {
content_bytes: format!("{cursor}"),
content_type: "".to_string(),
content_length: cursor as usize,
inscription_number: cursor as i64,
inscription_number: inscription_number.clone(),
inscription_fee: cursor,
inscription_output_value: cursor,
inscription_id: format!("{cursor}"),
Expand Down

0 comments on commit 7a0209b

Please sign in to comment.