Skip to content

Commit

Permalink
Correct fetching Bitcoin TXs in the processor docker tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kayabaNerve committed Apr 21, 2024
1 parent ef3ed9b commit 0b6c0b1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
15 changes: 13 additions & 2 deletions tests/processor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,16 +416,27 @@ impl Coordinator {
}
}

pub async fn get_transaction(&self, ops: &DockerOperations, tx: &[u8]) -> Option<Vec<u8>> {
pub async fn get_published_transaction(
&self,
ops: &DockerOperations,
tx: &[u8],
) -> Option<Vec<u8>> {
let rpc_url = network_rpc(self.network, ops, &self.network_handle);
match self.network {
NetworkId::Bitcoin => {
use bitcoin_serai::{bitcoin::consensus::Encodable, rpc::Rpc};

let rpc =
Rpc::new(rpc_url).await.expect("couldn't connect to the coordinator's Bitcoin RPC");

// Bitcoin publishes a 0-byte TX ID to reduce variables
// Accordingly, read the mempool to find the (presumed relevant) TX
let entries: Vec<String> =
rpc.rpc_call("getrawmempool", serde_json::json!([false])).await.unwrap();
assert_eq!(entries.len(), 1, "more than one entry in the mempool, so unclear which to get");

let mut hash = [0; 32];
hash.copy_from_slice(tx);
hash.copy_from_slice(&hex::decode(&entries[0]).unwrap());
if let Ok(tx) = rpc.get_transaction(&hash).await {
let mut buf = vec![];
tx.consensus_encode(&mut buf).unwrap();
Expand Down
4 changes: 2 additions & 2 deletions tests/processor/src/tests/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,12 +261,12 @@ fn send_test() {
let participating =
participating.iter().map(|p| usize::from(u16::from(*p) - 1)).collect::<HashSet<_>>();
for participant in &participating {
assert!(coordinators[*participant].get_transaction(&ops, &tx_id).await.is_some());
assert!(coordinators[*participant].get_published_transaction(&ops, &tx_id).await.is_some());
}

// Publish this transaction to the left out nodes
let tx = coordinators[*participating.iter().next().unwrap()]
.get_transaction(&ops, &tx_id)
.get_published_transaction(&ops, &tx_id)
.await
.unwrap();
for (i, coordinator) in coordinators.iter_mut().enumerate() {
Expand Down

0 comments on commit 0b6c0b1

Please sign in to comment.