spark_rust/spark_test_utils/
deposit.rs

1use std::time::Duration;
2
3use crate::{error::SparkSdkError, spark_test_utils::MempoolFaucet, SparkSdk};
4use tokio::time::sleep;
5
6use super::{polling::poll_for_claim_deposit, DEPOSIT_CONFIRMATION_WAIT};
7
8/// Helper function to deposit funds for a user and claim them
9/// Returns a Result indicating success or failure
10pub async fn deposit_for_user(
11    sdk: &mut SparkSdk,
12    faucet: &MempoolFaucet,
13    amount: u64,
14) -> Result<(), SparkSdkError> {
15    // Get deposit address from the SDK
16    let deposit_address_response = sdk.generate_deposit_address().await.unwrap();
17    let deposit_address = deposit_address_response.deposit_address;
18
19    // Broadcast funds to the deposit address using the faucet
20    let txid = faucet.make_faucet_request(&deposit_address, amount).await?;
21
22    // Wait for confirmation and claim the deposit
23    sleep(Duration::from_secs(DEPOSIT_CONFIRMATION_WAIT)).await;
24    poll_for_claim_deposit(sdk, txid).await?;
25
26    Ok(())
27}