fedimint_testing/btc/
mod.rs

1pub mod mock;
2pub mod real;
3
4use async_trait::async_trait;
5use bitcoin::{Address, Transaction, Txid};
6use fedimint_core::Amount;
7use fedimint_core::txoproof::TxOutProof;
8
9#[async_trait]
10pub trait BitcoinTest {
11    /// Make the underlying instance act as if it was exclusively available
12    /// for the existence of the returned guard.
13    async fn lock_exclusive(&self) -> Box<dyn BitcoinTest + Send + Sync>;
14
15    /// Mines a given number of blocks
16    async fn mine_blocks(&self, block_num: u64) -> Vec<bitcoin::BlockHash>;
17
18    /// Prepare funding wallet
19    ///
20    /// If needed will mine initial 100 blocks for `send_and_mine_block` to
21    /// work.
22    async fn prepare_funding_wallet(&self);
23
24    /// Send some bitcoin to an address then mine a block to confirm it.
25    /// Returns the proof that the transaction occurred.
26    ///
27    /// The implementation is responsible for making sure the funds can
28    /// be sent (e.g. first 100 blocks are mined to make funds available)
29    async fn send_and_mine_block(
30        &self,
31        address: &Address,
32        amount: bitcoin::Amount,
33    ) -> (TxOutProof, Transaction);
34
35    /// Returns a new address.
36    async fn get_new_address(&self) -> Address;
37
38    /// Mine a block to include any pending transactions then get the amount
39    /// received to an address
40    async fn mine_block_and_get_received(&self, address: &Address) -> Amount;
41
42    /// Waits till tx is found in mempool and returns the fees
43    async fn get_mempool_tx_fee(&self, txid: &Txid) -> Amount;
44
45    /// Returns the block height for the txid if found.
46    ///
47    /// Note: this exists since there's a bug for using bitcoind without txindex
48    /// for finding a tx block height.
49    /// see: `<https://github.com/fedimint/fedimint/issues/5329>`
50    async fn get_tx_block_height(&self, txid: &Txid) -> Option<u64>;
51
52    /// Returns the current block count
53    async fn get_block_count(&self) -> u64;
54
55    /// Returns a transaction with the provided txid if it exists in the mempool
56    async fn get_mempool_tx(&self, txid: &Txid) -> Option<bitcoin::Transaction>;
57}