depolymerization

wire gateway for Bitcoin/Ethereum
Log | Files | Refs | Submodules | README | LICENSE

commit 5d96e3d3dee1db26967b7b23cfa35a0e13790127
parent d1722dd88446ba4b8c425f73b259885aac76165d
Author: Antoine A <>
Date:   Wed,  8 Dec 2021 02:32:13 +0100

Prepare for more exhaustive history test

Diffstat:
Mscript/test_btc_wire.sh | 6++----
Mscript/test_gateway.sh | 48+++++++++++++++++++++++++++++++-----------------
Mwire-gateway/src/main.rs | 24++++++++++++++++++++----
3 files changed, 53 insertions(+), 25 deletions(-)

diff --git a/script/test_btc_wire.sh b/script/test_btc_wire.sh @@ -3,10 +3,8 @@ set -eu # Cleanup to run whenever we exit -function cleanup() -{ - for n in `jobs -p` - do +function cleanup() { + for n in `jobs -p`; do kill $n 2> /dev/null || true done wait diff --git a/script/test_gateway.sh b/script/test_gateway.sh @@ -3,10 +3,8 @@ set -eu # Cleanup to run whenever we exit -function cleanup() -{ - for n in `jobs -p` - do +function cleanup() { + for n in `jobs -p`; do kill $n 2> /dev/null || true done wait @@ -31,27 +29,39 @@ echo "" # Get client address ADDRESS=address + echo -n "Making wire transfer to exchange ..." -taler-exchange-wire-gateway-client \ - -b $BANK_ENDPOINT \ - -S 0ZSX8SH0M30KHX8K3Y1DAMVGDQV82XEF9DG1HC4QMQ3QWYT4AF00 \ - -D payto://bitcoin/$ADDRESS \ - -a BTC:0.00004 > /dev/null +for n in `seq 1 9`; do + taler-exchange-wire-gateway-client \ + -b $BANK_ENDPOINT \ + -S `openssl rand -hex 26` \ + -D payto://bitcoin/$ADDRESS \ + -a BTC:0.0000$n > /dev/null +done echo " OK" echo -n "Requesting exchange incoming transaction list ..." -taler-exchange-wire-gateway-client -b $BANK_ENDPOINT -i | grep BTC:0.00004 > /dev/null +ALL=`taler-exchange-wire-gateway-client -b $BANK_ENDPOINT -i` +for n in `seq 1 9`; do + echo $ALL | grep BTC:0.0000$n > /dev/null +done echo " OK" echo -n "Making wire transfer from exchange..." -taler-exchange-wire-gateway-client \ +for n in `seq 1 9`; do + taler-exchange-wire-gateway-client \ -b $BANK_ENDPOINT \ -C payto://bitcoin/$ADDRESS \ - -a BTC:0.00002 > /dev/null + -a BTC:0.0000$n > /dev/null +done + echo " OK" echo -n "Requesting exchange's outgoing transaction list..." -taler-exchange-wire-gateway-client -b $BANK_ENDPOINT -o | grep BTC:0.00002 > /dev/null +ALL=`taler-exchange-wire-gateway-client -b $BANK_ENDPOINT -o` +for n in `seq 1 9`; do + echo $ALL | grep BTC:0.0000$n > /dev/null +done echo " OK" @@ -69,9 +79,7 @@ test `curl -w %{http_code} -s -o /dev/null ${BANK_ENDPOINT}transfer` -eq 405 && # ----- Request format ----- # echo -n "Bad payto url..." -COUNT=0 -for bad_payto in http://bitcoin/$ADDRESS payto://btc/$ADDRESS payto://bitcoin/$ADDRESS?id=admin payto://bitcoin/$ADDRESS#admin -do +for bad_payto in http://bitcoin/$ADDRESS payto://btc/$ADDRESS payto://bitcoin/$ADDRESS?id=admin payto://bitcoin/$ADDRESS#admin; do taler-exchange-wire-gateway-client -b $BANK_ENDPOINT -C $bad_payto -a BTC:0.00042 2>&1 | grep -q "(400/24)" && echo -n " OK" || echo -n " Failed" done echo "" @@ -79,6 +87,12 @@ echo "" #echo -n "Bad bitcoin address..." #taler-exchange-wire-gateway-client -b $BANK_ENDPOINT -C payto://bitcoin/ADDRESS -a BTC:0.00042 2>&1 | grep -q "(400/26)" && echo " OK" || echo " Failed" -echo -n "Bad amount..." +echo -n "Bad transaction amount..." taler-exchange-wire-gateway-client -b $BANK_ENDPOINT -C payto://bitcoin/$ADDRESS -a ATC:0.00042 2>&1 | grep -q "(400/26)" && echo " OK" || echo " Failed" + +echo -n "Bad history delta..." +for bad_delta in incoming outgoing incoming?delta=0 outgoing?delta=0; do + test `curl -w %{http_code} -s -o /dev/null ${BANK_ENDPOINT}history/$bad_delta` -eq 400 && echo -n " OK" || echo -n " Failed" +done +echo "" exit 0 diff --git a/wire-gateway/src/main.rs b/wire-gateway/src/main.rs @@ -10,6 +10,7 @@ use hyper::{ service::{make_service_fn, service_fn}, Body, Error, Method, Request, Response, Server, StatusCode, }; + use tokio::io::AsyncReadExt; use tokio_postgres::{Client, NoTls}; use url::Url; @@ -138,6 +139,23 @@ fn assert_method(parts: &Parts, method: Method) -> Result<(), ServerErr> { } } +fn history_params(parts: &Parts) -> Result<HistoryParams, ServerErr> { + let params: HistoryParams = serde_urlencoded::from_str(parts.uri.query().unwrap_or("")) + .map_err(|_| { + ( + StatusCode::BAD_REQUEST, + ErrorCode::GENERIC_PARAMETER_MALFORMED, + ) + })?; + if params.delta == 0 { + return Err(( + StatusCode::BAD_REQUEST, + ErrorCode::GENERIC_PARAMETER_MALFORMED, + )); + } + Ok(params) +} + async fn router( req: Request<Body>, state: &'static ServerState, @@ -177,8 +195,7 @@ async fn router( } "/history/incoming" => { assert_method(&parts, Method::GET)?; - let params: HistoryParams = - serde_urlencoded::from_str(parts.uri.query().unwrap_or("")).unwrap(); + let params = history_params(&parts)?; let transactions = state .client .query( @@ -214,8 +231,7 @@ async fn router( } "/history/outgoing" => { assert_method(&parts, Method::GET)?; - let params: HistoryParams = - serde_urlencoded::from_str(parts.uri.query().unwrap_or("")).unwrap(); + let params = history_params(&parts)?; let transactions = state .client