mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2024-10-31 15:20:15 +00:00
Test URL creation for default electrum HTTP API
This commit is contained in:
parent
d296c22ecf
commit
bc1d2bda54
@ -186,7 +186,7 @@ impl GetRawTransaction for Wallet {
|
||||
#[async_trait]
|
||||
impl GetBlockHeight for Wallet {
|
||||
async fn get_block_height(&self) -> Result<BlockHeight> {
|
||||
let url = self.http_url.join("blocks/tip/height")?;
|
||||
let url = blocks_tip_height_url(&self.http_url)?;
|
||||
let height = retry(ConstantBackoff::new(Duration::from_secs(1)), || async {
|
||||
let height = reqwest::Client::new()
|
||||
.request(Method::GET, url.clone())
|
||||
@ -210,8 +210,7 @@ impl GetBlockHeight for Wallet {
|
||||
#[async_trait]
|
||||
impl TransactionBlockHeight for Wallet {
|
||||
async fn transaction_block_height(&self, txid: Txid) -> Result<BlockHeight> {
|
||||
let url = self.http_url.join(&format!("tx/{}/status", txid))?;
|
||||
|
||||
let url = tx_status_url(txid, &self.http_url)?;
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
struct TransactionStatus {
|
||||
block_height: Option<u32>,
|
||||
@ -278,3 +277,42 @@ impl GetNetwork for Wallet {
|
||||
self.inner.lock().await.network()
|
||||
}
|
||||
}
|
||||
|
||||
fn tx_status_url(txid: Txid, base_url: &Url) -> Result<Url> {
|
||||
let url = base_url.join(&format!("tx/{}/status", txid))?;
|
||||
Ok(url)
|
||||
}
|
||||
|
||||
fn blocks_tip_height_url(base_url: &Url) -> Result<Url> {
|
||||
let url = base_url.join("blocks/tip/height")?;
|
||||
Ok(url)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::{
|
||||
bitcoin::{
|
||||
wallet::{blocks_tip_height_url, tx_status_url},
|
||||
Txid,
|
||||
},
|
||||
cli::config::DEFAULT_ELECTRUM_HTTP_URL,
|
||||
};
|
||||
use reqwest::Url;
|
||||
|
||||
#[test]
|
||||
fn create_tx_status_url_from_default_base_url_success() {
|
||||
let txid: Txid = Txid::default();
|
||||
let base_url = Url::parse(DEFAULT_ELECTRUM_HTTP_URL).expect("Could not parse url");
|
||||
let url = tx_status_url(txid, &base_url).expect("Could not create url");
|
||||
let expected = format!("https://blockstream.info/testnet/api/tx/{}/status", txid);
|
||||
assert_eq!(url.as_str(), expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn create_block_tip_height_url_from_default_base_url_success() {
|
||||
let base_url = Url::parse(DEFAULT_ELECTRUM_HTTP_URL).expect("Could not parse url");
|
||||
let url = blocks_tip_height_url(&base_url).expect("Could not create url");
|
||||
let expected = "https://blockstream.info/testnet/api/blocks/tip/height";
|
||||
assert_eq!(url.as_str(), expected);
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ use std::{
|
||||
use tracing::info;
|
||||
use url::Url;
|
||||
|
||||
const DEFAULT_ELECTRUM_HTTP_URL: &str = "https://blockstream.info/testnet/api/";
|
||||
pub const DEFAULT_ELECTRUM_HTTP_URL: &str = "https://blockstream.info/testnet/api/";
|
||||
const DEFAULT_ELECTRUM_RPC_URL: &str = "ssl://electrum.blockstream.info:60002";
|
||||
const DEFAULT_MONERO_WALLET_RPC_TESTNET_URL: &str = "http://127.0.0.1:38083/json_rpc";
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user