Merge branch 'olando-test' into 'master'

Add test for OLANDO authchain updates

See merge request riftenlabs/riftenlabs-indexer!42
This commit is contained in:
Dagur Valberg Johannsson 2025-10-14 07:44:29 +00:00
commit 9b624ece42

View file

@ -240,10 +240,14 @@ pub fn index_bcmr(
#[cfg(test)]
mod tests {
use bitcoincash::consensus::deserialize;
use bitcoincash::{consensus::deserialize, Block};
use crate::utiltx::ttor_sorted_kahn;
use super::*;
use electrum_client_netagnostic::{Client, ElectrumApi, Param};
#[test]
fn test_parse_bcmr() {
let tx_hex = "0200000001925bd92e424c0f0bc290a794f491abf19e61b6dcdec7e70747fcb54682fc9bb700000000644181707613f45069c8df981b2ef0cbd05158d5623602fac3ae2e13f69d05fa356c278f2f3a4e34f33a79e0f8375abd35051150ec024b3625807cea185528a5de9e412103b4680dffa1e34b3bfdb024fd0a8498eb24f59ba5ead34acfb74f9d8549db6f3a0000000003e8030000000000003eef925bd92e424c0f0bc290a794f491abf19e61b6dcdec7e70747fcb54682fc9bb710fdf40176a914bd4c90f2c64743fc0d3ea6a14973a5d628260b7388ac0000000000000000456a0442434d5220c705cc90a56ac7ef9a15ef90ebbc8ba7e60e4c622e5464d52d8baf7887949fcc1d736f636b2e6361756c64726f6e2e71756573742f62636d722e6a736f6ed9210000000000001976a914bd4c90f2c64743fc0d3ea6a14973a5d628260b7388ac00000000";
@ -270,4 +274,93 @@ mod tests {
// The hash value in this BCMR is 64 bytes. Not a valid sha256 hash.
assert!(result.is_none());
}
#[test]
#[ignore] // Integration test - requires network access. Run with `cargo test olando_issue --ignored`
fn olando_issue() {
// Test that the indexer is able to follow the auth chain for OLANDO token (part of issue #15).
// Map: block height -> expected txid of BCMR auth update transaction
let blocks_with_update: HashMap<u32, &str> = [
(
919723,
"1987b8c8114c2cf8492467da319a8856e81f49345f6385e6992cd820871bef87",
),
(
917546,
"6c422e57f64a2c21d3e9da9161e483393da17ee1a0d8aea3ebf9e6c944ddf473",
),
(
911009,
"de926cb4c086ce4c0cd79379a53149c54a21f43ccab322bef8429d60cd53a6a1",
),
(
910728,
"536e199357a02fe9ea071cf7d0df4431911fd2ad170867659e796f053f7e6045",
),
(
908242,
"0370d0ae6f1f0c7b49b5c3f7e271a1ebf4daef9d91450f2316e878a0a78d6d08",
),
(
906927,
"68a0067153db9925560d7adb956295b41de958058ccd78d5c1adfdf4e0e70ed9",
),
(
906218,
"20e8074d404e5e80c6d8cbe30d51c754ab86ae0b58bc8ec17f12afdb6380195d",
),
(
887082,
"6a806f2e01e11a2a4000bb736ffb5570dd55412582088abe95fce700a17a3922",
),
(
887074,
"7c71bbe3e3f52c5bf9965f454e7f87b86f097ecfec0705360e9284f38c360d65",
), // genesis
]
.iter()
.cloned()
.collect();
let client = Client::new(&format!("tcp://rostrum.cauldron.quest:50001")).unwrap();
let mut conn = Connection::open_in_memory().unwrap();
crate::db::bcmr::prepare_tables(&conn);
let tx = conn.transaction().unwrap();
// Process blocks in ascending order (lowest to highest)
let mut sorted_blocks: Vec<_> = blocks_with_update.iter().collect();
sorted_blocks.sort_by(|a, b| a.0.cmp(b.0));
for (block_height, expected_hash) in sorted_blocks {
let block = client
.raw_call("blockchain.block.get", vec![Param::U32(*block_height)])
.unwrap();
let block: Block = deserialize(&hex::decode(block.as_str().unwrap()).unwrap()).unwrap();
// Process this block immediately
let block_hash = block.block_hash();
let sorted_txs = ttor_sorted_kahn(block.txdata);
let expected_txid = *expected_hash;
// Index the block
index_bcmr(&tx, &block_hash, sorted_txs).unwrap();
let mut stmt = tx
.prepare("SELECT COUNT(*) FROM auth_chain_entry WHERE txid = ?")
.unwrap();
let count: i64 = stmt
.query_row([expected_txid], |row| row.get(0))
.unwrap_or(0);
assert_eq!(
count, 1,
"Expected 1 BCMR auth update for txid: {} in block {}",
expected_txid, block_height
);
}
tx.commit().unwrap();
}
}