api.rs (3191B)
1 /* 2 This file is part of TALER 3 Copyright (C) 2025 Taler Systems SA 4 5 TALER is free software; you can redistribute it and/or modify it under the 6 terms of the GNU Affero General Public License as published by the Free Software 7 Foundation; either version 3, or (at your option) any later version. 8 9 TALER is distributed in the hope that it will be useful, but WITHOUT ANY 10 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 11 A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. 12 13 You should have received a copy of the GNU Affero General Public License along with 14 TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> 15 */ 16 17 use std::str::FromStr; 18 19 use axum::Router; 20 use depolymerizer_bitcoin::{CONFIG_SOURCE, api::ServerState}; 21 use sqlx::PgPool; 22 use taler_api::{api::TalerRouter as _, auth::AuthMethod}; 23 use taler_common::{ 24 api_common::{HashCode, ShortHashCode}, 25 api_wire::{OutgoingHistory, TransferState, WireConfig}, 26 types::{amount::Currency, payto::payto}, 27 }; 28 use taler_test_utils::{ 29 db_test_setup, json, 30 routine::{admin_add_incoming_routine, routine_pagination, transfer_routine}, 31 server::TestServer, 32 }; 33 34 async fn setup() -> (Router, PgPool) { 35 let pool = db_test_setup(CONFIG_SOURCE).await; 36 let api = ServerState::start( 37 pool.clone(), 38 payto("payto://bitcoin/1FfmbHfnpaZjKFvyi1okTjJJusN455paPH"), 39 Currency::from_str("BTC").unwrap(), 40 ) 41 .await; 42 let server = Router::new() 43 .wire_gateway(api.clone(), AuthMethod::None) 44 .finalize(); 45 46 (server, pool) 47 } 48 49 #[tokio::test] 50 async fn config() { 51 let (server, _) = setup().await; 52 server 53 .get("/taler-wire-gateway/config") 54 .await 55 .assert_ok_json::<WireConfig>(); 56 } 57 58 #[tokio::test] 59 async fn transfer() { 60 let (server, _) = setup().await; 61 transfer_routine( 62 &server, 63 TransferState::pending, 64 &payto("payto://bitcoin/1FfmbHfnpaZjKFvyi1okTjJJusN455paPH?receiver-name=Anonymous"), 65 ) 66 .await; 67 } 68 69 #[tokio::test] 70 async fn outgoing_history() { 71 let (server, _) = setup().await; 72 routine_pagination::<OutgoingHistory, _>( 73 &server, 74 "/taler-wire-gateway/history/outgoing", 75 |it| { 76 it.outgoing_transactions 77 .into_iter() 78 .map(|it| *it.row_id as i64) 79 .collect() 80 }, 81 |s, _| async { 82 s.post("/taler-wire-gateway/transfer").json( 83 &json!({ 84 "request_uid": HashCode::rand(), 85 "amount": "BTC:10", 86 "exchange_base_url": "http://exchange.taler/", 87 "wtid": ShortHashCode::rand(), 88 "credit_account": "payto://bitcoin/1FfmbHfnpaZjKFvyi1okTjJJusN455paPH?receiver-name=Anonymous", 89 }) 90 ).await; 91 }, 92 ) 93 .await; 94 } 95 96 #[tokio::test] 97 async fn admin_add_incoming() { 98 let (server, _) = setup().await; 99 admin_add_incoming_routine( 100 &server, 101 &payto("payto://bitcoin/1FfmbHfnpaZjKFvyi1okTjJJusN455paPH?receiver-name=Anonymous"), 102 false, 103 ) 104 .await; 105 }