lnv2_module_tests/
common.rs1use devimint::cmd;
2use devimint::federation::Client;
3use fedimint_core::core::OperationId;
4use fedimint_lnv2_client::{FinalReceiveOperationState, FinalSendOperationState};
5use lightning_invoice::Bolt11Invoice;
6use substring::Substring;
7
8pub async fn receive(
9 client: &Client,
10 gateway: &str,
11 amount: u64,
12) -> anyhow::Result<(Bolt11Invoice, OperationId)> {
13 Ok(serde_json::from_value::<(Bolt11Invoice, OperationId)>(
14 cmd!(
15 client,
16 "module",
17 "lnv2",
18 "receive",
19 amount,
20 "--gateway",
21 gateway
22 )
23 .out_json()
24 .await?,
25 )?)
26}
27
28pub async fn send(
29 client: &Client,
30 gateway: &str,
31 invoice: &str,
32 final_state: FinalSendOperationState,
33) -> anyhow::Result<()> {
34 let send_op = serde_json::from_value::<OperationId>(
35 cmd!(
36 client,
37 "module",
38 "lnv2",
39 "send",
40 invoice,
41 "--gateway",
42 gateway
43 )
44 .out_json()
45 .await?,
46 )?;
47
48 assert_eq!(
49 cmd!(
50 client,
51 "module",
52 "lnv2",
53 "await-send",
54 serde_json::to_string(&send_op)?.substring(1, 65)
55 )
56 .out_json()
57 .await?,
58 serde_json::to_value(final_state).expect("JSON serialization failed"),
59 );
60
61 Ok(())
62}
63
64pub async fn await_receive_claimed(
65 client: &Client,
66 operation_id: OperationId,
67) -> anyhow::Result<()> {
68 assert_eq!(
69 cmd!(
70 client,
71 "module",
72 "lnv2",
73 "await-receive",
74 serde_json::to_string(&operation_id)?.substring(1, 65)
75 )
76 .out_json()
77 .await?,
78 serde_json::to_value(FinalReceiveOperationState::Claimed)
79 .expect("JSON serialization failed"),
80 );
81
82 Ok(())
83}