Skip to content

Commit c945a62

Browse files
committed
Tests: Use yaml needs funding in swap test
1 parent f78085a commit c945a62

1 file changed

Lines changed: 38 additions & 41 deletions

File tree

tests/swap.rs

Lines changed: 38 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ extern crate log;
33

44
use bitcoincore_rpc::RpcApi;
55
use farcaster_core::swap::SwapId;
6-
use farcaster_node::bus::ctl::{BitcoinFundingInfo, MoneroFundingInfo};
7-
use farcaster_node::bus::rpc::NodeInfo;
6+
use farcaster_node::bus::ctl::{BitcoinFundingInfo, MoneroFundingInfo, FundingInfo};
7+
use farcaster_node::bus::rpc::{NodeInfo, FundingInfos};
88
use farcaster_node::bus::CheckpointEntry;
99
use futures::future::join_all;
1010
use std::collections::HashSet;
@@ -2731,6 +2731,13 @@ fn cli_output_to_node_info(stdout: Vec<String>) -> NodeInfo {
27312731
.unwrap()
27322732
}
27332733

2734+
fn cli_output_to_funding_infos(stdout: Vec<String>) -> FundingInfos {
2735+
serde_yaml::from_str(
2736+
&stdout.iter().map(|line| format!("{}{}", line, "\n"))
2737+
.collect::<String>(),
2738+
).unwrap()
2739+
}
2740+
27342741
async fn retry_until_offer(args: Vec<String>) -> Vec<String> {
27352742
for _ in 0..ALLOWED_RETRIES {
27362743
let (stdout, _stderr) = run("../swap-cli", args.clone()).unwrap();
@@ -2875,22 +2882,17 @@ async fn retry_until_bitcoin_funding_address(
28752882
for _ in 0..ALLOWED_RETRIES {
28762883
let (stdout, _stderr) = run("../swap-cli", args.clone()).unwrap();
28772884

2878-
// get the btc funding address
2879-
let funding_infos: Vec<BitcoinFundingInfo> = stdout
2880-
.iter()
2881-
.filter_map(|element| {
2882-
info!("cli: {}", element);
2883-
if let Ok(funding_info) = BitcoinFundingInfo::from_str(element) {
2884-
if funding_info.swap_id == swap_id {
2885-
Some(funding_info)
2886-
} else {
2887-
None
2888-
}
2885+
let funding_infos: Vec<BitcoinFundingInfo> = cli_output_to_funding_infos(stdout).swaps_need_funding.iter().filter_map(|f|
2886+
if let FundingInfo::Bitcoin(info) = f {
2887+
if info.swap_id == swap_id {
2888+
Some(info)
2889+
28892890
} else {
28902891
None
28912892
}
2892-
})
2893-
.collect();
2893+
} else {
2894+
None
2895+
}).cloned().collect();
28942896

28952897
if !funding_infos.is_empty() {
28962898
return (funding_infos[0].address.clone(), funding_infos[0].amount);
@@ -2904,22 +2906,24 @@ async fn retry_until_funding_info_cleared(swap_id: SwapId, args: Vec<String>) {
29042906
for _ in 0..ALLOWED_RETRIES {
29052907
let (stdout, _stderr) = run("../swap-cli", args.clone()).unwrap();
29062908

2907-
// get the btc funding address
2908-
let funding_infos: Vec<BitcoinFundingInfo> = stdout
2909-
.iter()
2910-
.filter_map(|element| {
2911-
info!("cli: {}", element);
2912-
if let Ok(funding_info) = BitcoinFundingInfo::from_str(element) {
2913-
if funding_info.swap_id == swap_id {
2914-
Some(funding_info)
2909+
let funding_infos: Vec<FundingInfo> = cli_output_to_funding_infos(stdout).swaps_need_funding.iter().filter_map(|f|
2910+
match f {
2911+
FundingInfo::Bitcoin(info) => {
2912+
if info.swap_id == swap_id {
2913+
Some(FundingInfo::Bitcoin(info.clone()))
29152914
} else {
29162915
None
29172916
}
2918-
} else {
2919-
None
29202917
}
2921-
})
2922-
.collect();
2918+
FundingInfo::Monero(info) => {
2919+
if info.swap_id == swap_id {
2920+
Some(FundingInfo::Monero(info.clone()))
2921+
} else {
2922+
None
2923+
}
2924+
}
2925+
}
2926+
).collect();
29232927

29242928
if funding_infos.is_empty() {
29252929
return;
@@ -2935,23 +2939,16 @@ async fn retry_until_monero_funding_address(
29352939
) -> (monero::Address, monero::Amount) {
29362940
for _ in 0..ALLOWED_RETRIES {
29372941
let (stdout, _stderr) = run("../swap-cli", args.clone()).unwrap();
2938-
2939-
// get the monero funding address
2940-
let funding_infos: Vec<MoneroFundingInfo> = stdout
2941-
.iter()
2942-
.filter_map(|element| {
2943-
info!("cli: {}", element);
2944-
if let Ok(funding_info) = MoneroFundingInfo::from_str(element) {
2945-
if funding_info.swap_id == swap_id {
2946-
Some(funding_info)
2947-
} else {
2948-
None
2949-
}
2942+
let funding_infos: Vec<MoneroFundingInfo> = cli_output_to_funding_infos(stdout).swaps_need_funding.iter().filter_map(|f|
2943+
if let FundingInfo::Monero(info) = f {
2944+
if info.swap_id == swap_id {
2945+
Some(info)
29502946
} else {
29512947
None
29522948
}
2953-
})
2954-
.collect();
2949+
} else {
2950+
None
2951+
}).cloned().collect();
29552952

29562953
if !funding_infos.is_empty() {
29572954
return (funding_infos[0].address, funding_infos[0].amount);

0 commit comments

Comments
 (0)