From 7eccc771b6bd99a1feacbd4321767ae8e76e2d2c Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 23 Aug 2023 14:14:28 +0200 Subject: switch merchant tests to fakebank, libeufin is a dumpster on fire --- src/testing/initialize_taler_system.sh | 2 +- src/testing/setup.sh | 2 +- src/testing/test_key_rotation.sh | 12 +- src/testing/test_merchant_instance_auth.sh | 2 +- src/testing/test_merchant_kyc.sh | 2 +- src/testing/test_merchant_order_autocleanup.sh | 59 ++++-- src/testing/test_merchant_order_creation.sh | 152 +++++++++----- src/testing/test_merchant_product_creation.sh | 51 +++-- src/testing/test_merchant_reserve_creation.sh | 90 +++++---- src/testing/test_merchant_transfer_tracking.sh | 95 ++++++--- src/testing/test_merchant_wirewatch.sh | 263 ++++++++++++++----------- src/testing/test_template.conf | 9 + 12 files changed, 466 insertions(+), 273 deletions(-) diff --git a/src/testing/initialize_taler_system.sh b/src/testing/initialize_taler_system.sh index 6a263968..2b74683b 100755 --- a/src/testing/initialize_taler_system.sh +++ b/src/testing/initialize_taler_system.sh @@ -78,7 +78,7 @@ export get_bankaccount_transactions # Exchange configuration file will be edited, so we create one # from the template. -TMP_DIR=$(mktemp -t -d taler-merchant-test-XXXXXX) +TMP_DIR=$(mktemp -p "${TMPDIR:-/tmp}" -d taler-merchant-test-XXXXXX) echo "Writing test log files to $TMP_DIR" CONF="$TMP_DIR/test_template.conf" cp test_template.conf "$CONF" diff --git a/src/testing/setup.sh b/src/testing/setup.sh index 2af15494..77c2258e 100755 --- a/src/testing/setup.sh +++ b/src/testing/setup.sh @@ -28,7 +28,7 @@ function setup() { echo "Starting test system ..." >&2 # Create a named pipe in a temp directory we own. - FIFO_DIR=$(mktemp -d fifo-XXXXXX) + FIFO_DIR=$(mktemp -p "${TMPDIR:-/tmp}" -d fifo-XXXXXX) FIFO_OUT=$(echo "$FIFO_DIR/out") mkfifo "$FIFO_OUT" # Open pipe as FD 3 (RW) and FD 4 (RO) diff --git a/src/testing/test_key_rotation.sh b/src/testing/test_key_rotation.sh index cf270b3c..cf9b8353 100755 --- a/src/testing/test_key_rotation.sh +++ b/src/testing/test_key_rotation.sh @@ -49,21 +49,21 @@ function exit_fail() { # Cleanup to run whenever we exit function cleanup() { - for n in `jobs -p` + for n in $(jobs -p) do - kill $n 2> /dev/null || true + kill "$n" 2> /dev/null || true done - rm -rf $CONF $WALLET_DB $TMP_DIR + rm -rf "$CONF" "$WALLET_DB" "$TMP_DIR" wait } # Exchange configuration file will be edited, so we create one # from the template. -CONF=`mktemp test_template.conf-XXXXXX` +CONF=$(mktemp -p "${TMPDIR:-/tmp}" test_template.conf-XXXXXX) cp test_key_rotation.conf $CONF -TMP_DIR=`mktemp -d keys-tmp-XXXXXX` -WALLET_DB=`mktemp test_wallet.json-XXXXXX` +TMP_DIR=$(mktemp -p "${TMPDIR:-/tmp}" -d keys-tmp-XXXXXX) +WALLET_DB=$(mktemp -p "${TMPDIR:-/tmp}" test_wallet.json-XXXXXX) # Install cleanup handler (except for kill -9) trap cleanup EXIT diff --git a/src/testing/test_merchant_instance_auth.sh b/src/testing/test_merchant_instance_auth.sh index 8c031e1d..5cc4de92 100755 --- a/src/testing/test_merchant_instance_auth.sh +++ b/src/testing/test_merchant_instance_auth.sh @@ -36,7 +36,7 @@ function my_cleanup() # Launch only the merchant. setup -c test_template.conf -m CONF="test_template.conf.edited" -LAST_RESPONSE=$(mktemp test_response.conf-XXXXXX) +LAST_RESPONSE=$(mktemp -p "${TMPDIR:-/tmp}" test_response.conf-XXXXXX) echo -n "Configuring 'default' instance ..." >&2 diff --git a/src/testing/test_merchant_kyc.sh b/src/testing/test_merchant_kyc.sh index c093d698..2b3bb188 100755 --- a/src/testing/test_merchant_kyc.sh +++ b/src/testing/test_merchant_kyc.sh @@ -22,7 +22,7 @@ set -eu # Launch system. setup -c "test_template.conf" -m -u "exchange-account-1" -LAST_RESPONSE=$(mktemp test_response.conf-XXXXXX) +LAST_RESPONSE=$(mktemp -p "${TMPDIR:-/tmp}" test_response.conf-XXXXXX) echo -n "Configuring a merchant instance before configuring the default instance ..." diff --git a/src/testing/test_merchant_order_autocleanup.sh b/src/testing/test_merchant_order_autocleanup.sh index a5678ecf..08655d18 100755 --- a/src/testing/test_merchant_order_autocleanup.sh +++ b/src/testing/test_merchant_order_autocleanup.sh @@ -3,18 +3,29 @@ set -eu -echo "Re-initializing database (needed for current libeufin)" # FIXME-MS: enable idempotency AND db-reset! -dropdb talercheck || true -createdb talercheck - +# Replace with 0 for nexus... +USE_FAKEBANK=1 +if [ 1 = "$USE_FAKEBANK" ] +then + ACCOUNT="exchange-account-2" + WIRE_METHOD="x-taler-bank" + BANK_FLAGS="-f -d $WIRE_METHOD -u $ACCOUNT" + BANK_URL="http://localhost:8082/taler-bank-access/" +else + ACCOUNT="exchange-account-1" + WIRE_METHOD="iban" + BANK_FLAGS="-ns -d $WIRE_METHOD -u $ACCOUNT" + BANK_URL="http://localhost:18082/demobanks/default/access-api/" +fi . setup.sh # Launch exchange, merchant and bank. -setup -c "test_template.conf" -enms -u "exchange-account-1" -d "iban" -LAST_RESPONSE=$(mktemp test_response.conf-XXXXXX) +setup -c "test_template.conf" \ + -em \ + $BANK_FLAGS +LAST_RESPONSE=$(mktemp -p "${TMPDIR:-/tmp}" test_response.conf-XXXXXX) CONF="test_template.conf.edited" -WALLET_DB=$(mktemp test_wallet.json-XXXXXX) -BANK_URL="http://localhost:18082/demobanks/default/" +WALLET_DB=$(mktemp -p "${TMPDIR:-/tmp}" test_wallet.json-XXXXXX) EXCHANGE_URL="http://localhost:8081/" @@ -31,22 +42,33 @@ taler-wallet-cli \ bankAccessApiBaseUrl: $BANK_URL, exchangeBaseUrl: $EXCHANGE_URL }' \ - --arg BANK_URL "${BANK_URL}access-api/" \ + --arg BANK_URL "${BANK_URL}" \ --arg EXCHANGE_URL "$EXCHANGE_URL" )" 2>wallet-withdraw-1.err >wallet-withdraw-1.out echo -n "." -sleep 10 +if [ 1 = "$USE_FAKEBANK" ] +then + # Fakebank is instant... + sleep 0 +else + sleep 10 + # NOTE: once libeufin can do long-polling, we should + # be able to reduce the delay here and run wirewatch + # always in the background via setup +fi echo -n "." -# NOTE: once libeufin can do long-polling, we should -# be able to reduce the delay here and run wirewatch -# always in the background via setup -taler-exchange-wirewatch -L "INFO" -c "$CONF" -t &> taler-exchange-wirewatch.out +taler-exchange-wirewatch \ + -L "INFO" \ + -c "$CONF" \ + -t \ + &> taler-exchange-wirewatch.out echo -n "." taler-wallet-cli \ --wallet-db="$WALLET_DB" \ run-until-done \ - 2>wallet-withdraw-finish-1.err >wallet-withdraw-finish-1.out + 2>wallet-withdraw-finish-1.err \ + >wallet-withdraw-finish-1.out echo " OK" # @@ -54,7 +76,12 @@ echo " OK" # echo -n "Configuring merchant instance ..." -FORTYTHREE=$(get_payto_uri fortythree x) +if [ 1 = "$USE_FAKEBANK" ] +then + FORTYTHREE="payto://x-taler-bank/localhost/fortythree?receiver-name=fortythree" +else + FORTYTHREE=$(get_payto_uri fortythree x) +fi # create with 2 address STATUS=$(curl -H "Content-Type: application/json" -X POST \ diff --git a/src/testing/test_merchant_order_creation.sh b/src/testing/test_merchant_order_creation.sh index 99b1c674..1461c005 100755 --- a/src/testing/test_merchant_order_creation.sh +++ b/src/testing/test_merchant_order_creation.sh @@ -9,18 +9,27 @@ function clean_wallet() { } -echo "Re-initializing database (needed for current libeufin)" # FIXME-MS: enable idempotency AND db-reset! -dropdb talercheck || true -createdb talercheck - +# Replace with 0 for nexus... +USE_FAKEBANK=1 +if [ 1 = "$USE_FAKEBANK" ] +then + ACCOUNT="exchange-account-2" + BANK_FLAGS="-f -d x-taler-bank -u $ACCOUNT" + BANK_URL="http://localhost:8082/taler-bank-access/" +else + ACCOUNT="exchange-account-1" + BANK_FLAGS="-ns -d iban -u $ACCOUNT" + BANK_URL="http://localhost:18082/demobanks/default/access-api/" +fi . setup.sh # Launch exchange, merchant and bank. -setup -c "test_template.conf" -enms -u "exchange-account-1" -d "iban" -LAST_RESPONSE=$(mktemp test_response.conf-XXXXXX) +setup -c "test_template.conf" \ + -em \ + $BANK_FLAGS +LAST_RESPONSE=$(mktemp -p "${TMPDIR:-/tmp}" test_response.conf-XXXXXX) CONF="test_template.conf.edited" -WALLET_DB=$(mktemp test_wallet.json-XXXXXX) -BANK_URL="http://localhost:18082/demobanks/default/" +WALLET_DB=$(mktemp -p "${TMPDIR:-/tmp}" test_wallet.json-XXXXXX) EXCHANGE_URL="http://localhost:8081/" # Install cleanup handler (except for kill -9) @@ -28,26 +37,38 @@ trap clean_wallet EXIT echo -n "First prepare wallet with coins ..." rm -f "$WALLET_DB" -taler-wallet-cli --no-throttle --wallet-db="$WALLET_DB" api --expect-success 'withdrawTestBalance' \ +taler-wallet-cli \ + --no-throttle \ + --wallet-db="$WALLET_DB" \ + api \ + --expect-success 'withdrawTestBalance' \ "$(jq -n ' { amount: "TESTKUDOS:99", bankAccessApiBaseUrl: $BANK_URL, exchangeBaseUrl: $EXCHANGE_URL }' \ - --arg BANK_URL "${BANK_URL}access-api/" \ + --arg BANK_URL "${BANK_URL}" \ --arg EXCHANGE_URL "$EXCHANGE_URL" )" 2>wallet-withdraw-1.err >wallet-withdraw-1.out -# FIXME-MS: add logic to have nexus check immediately here. echo -n "." -sleep 10 +# FIXME-MS: add logic to have nexus check immediately here. +# sleep 10 echo -n "." # NOTE: once libeufin can do long-polling, we should # be able to reduce the delay here and run wirewatch # always in the background via setup -taler-exchange-wirewatch -L "INFO" -c "$CONF" -t &> taler-exchange-wirewatch.out +taler-exchange-wirewatch \ + -a "$ACCOUNT" \ + -L "INFO" \ + -c "$CONF" \ + -t &> taler-exchange-wirewatch.out echo -n "." -taler-wallet-cli --wallet-db="$WALLET_DB" run-until-done 2>wallet-withdraw-finish-1.err >wallet-withdraw-finish-1.out +taler-wallet-cli \ + --wallet-db="$WALLET_DB" \ + run-until-done \ + 2>wallet-withdraw-finish-1.err \ + >wallet-withdraw-finish-1.out echo " OK" CURRENCY_COUNT=$(taler-wallet-cli --wallet-db="$WALLET_DB" balance | jq '.balances|length') @@ -62,8 +83,13 @@ fi echo -n "Configuring merchant instance ..." -# create with 2 address -FORTYTHREE=$(get_payto_uri fortythree x) +if [ 1 = "$USE_FAKEBANK" ] +then + FORTYTHREE="payto://x-taler-bank/localhost/fortythree?receiver-name=fortythree" +else + FORTYTHREE=$(get_payto_uri fortythree x) +fi +# create with 2 bank account addresses STATUS=$(curl -H "Content-Type: application/json" -X POST \ -H 'Authorization: Bearer secret-token:super_secret' \ http://localhost:9966/management/instances \ @@ -74,7 +100,7 @@ if [ "$STATUS" != "204" ] then exit_fail "Expected '204 No content' response. Got instead $STATUS" fi - +echo -n "." # remove one account address STATUS=$(curl -H "Content-Type: application/json" -X PATCH \ @@ -355,18 +381,28 @@ sleep 3 echo " DONE" echo -n "Obtaining wire transfer details from bank..." -# Emulating the previous pybank-based logic of getting -# the wire transfer information _via the exchange_ bank -# account. NOTE: grabbing tx == 0, since the latest -# transaction appear first in the bank's history. -BANKDATA=$(get_bankaccount_transactions exchange x | jq '.transactions[0]') -SUBJECT=$(echo "$BANKDATA" | jq -r .subject) -WTID=$(echo "$SUBJECT" | awk '{print $1}') -WURL=$(echo "$SUBJECT" | awk '{print $2}') -CREDIT_AMOUNT="$(echo "$BANKDATA" | jq -r .currency):$(echo "$BANKDATA" | jq -r .amount)" -TARGET=$(echo "$BANKDATA" | jq -r .creditorIban) -# 'TARGET' is now the IBAN. -TARGET_PAYTO="payto://iban/SANDBOXX/$TARGET?receiver-name=Forty+Three" + +if [ 1 = "$USE_FAKEBANK" ] +then + BANKDATA="$(curl 'http://localhost:8082/exchange/history/outgoing?delta=1' -s)" + WTID=$(echo "$BANKDATA" | jq -r .outgoing_transactions[0].wtid) + WURL=$(echo "$BANKDATA" | jq -r .outgoing_transactions[0].exchange_base_url) + CREDIT_AMOUNT=$(echo "$BANKDATA" | jq -r .outgoing_transactions[0].amount) + TARGET_PAYTO=$(echo "$BANKDATA" | jq -r .outgoing_transactions[0].credit_account) +else + # Emulating the previous pybank-based logic of getting + # the wire transfer information _via the exchange_ bank + # account. NOTE: grabbing tx == 0, since the latest + # transaction appear first in the bank's history. + BANKDATA=$(get_bankaccount_transactions exchange x | jq '.transactions[0]') + SUBJECT=$(echo "$BANKDATA" | jq -r .subject) + WTID=$(echo "$SUBJECT" | awk '{print $1}') + WURL=$(echo "$SUBJECT" | awk '{print $2}') + CREDIT_AMOUNT="$(echo "$BANKDATA" | jq -r .currency):$(echo "$BANKDATA" | jq -r .amount)" + TARGET=$(echo "$BANKDATA" | jq -r .creditorIban) + # 'TARGET' is now the IBAN. + TARGET_PAYTO="payto://iban/SANDBOXX/$TARGET?receiver-name=Forty+Three" +fi if [ "$EXCHANGE_URL" != "$WURL" ] then @@ -377,12 +413,6 @@ echo " OK" set +e -export TARGET_PAYTO -export WURL -export WTID -export CREDIT_AMOUNT -export LAST_RESPONSE - echo -n "Notifying merchant of bogus wire transfer ..." STATUS=$(curl 'http://localhost:9966/instances/default/private/transfers' \ @@ -512,26 +542,44 @@ then fi echo " OK" -ACCOUNT_PASSWORD="fortythree:x" -BANK_HOST="localhost:18082" - -# Can be replaced by the libeufin-cli way. -STATUS=$(curl "http://$ACCOUNT_PASSWORD@$BANK_HOST/demobanks/default/access-api/accounts/fortythree" \ - -w "%{http_code}" -s -o "$LAST_RESPONSE") -if [ "$STATUS" != "200" ] -then - jq . < "$LAST_RESPONSE" - exit_fail "Expected response 200 Ok, getting account status. Got: $STATUS" -fi -BALANCE=$(jq -r .balance.amount < "$LAST_RESPONSE") -if [ "$BALANCE" == "TESTKUDOS:0" ] -then - jq . < "$LAST_RESPONSE" - exit_fail "Wire transfer did not happen. Got: $BALANCE" +echo -n "Checking bank account status ..." +if [ 1 = "$USE_FAKEBANK" ] +then + STATUS=$(curl "http://localhost:8082/taler-bank-access/accounts/fortythree" \ + -w "%{http_code}" \ + -s \ + -o "$LAST_RESPONSE") + if [ "$STATUS" != "200" ] + then + jq . < "$LAST_RESPONSE" + exit_fail "Expected response 200 Ok, getting account status. Got: $STATUS" + fi + BALANCE=$(jq -r .balance.amount < "$LAST_RESPONSE") + if [ "$BALANCE" == "TESTKUDOS:0" ] + then + jq . < "$LAST_RESPONSE" + exit_fail "Wire transfer did not happen. Got: $BALANCE" + fi +else + ACCOUNT_PASSWORD="fortythree:x" + BANK_HOST="localhost:18082" + # Can be replaced by the libeufin-cli way. + STATUS=$(curl "http://$ACCOUNT_PASSWORD@$BANK_HOST/demobanks/default/access-api/accounts/fortythree" \ + -w "%{http_code}" -s -o "$LAST_RESPONSE") + if [ "$STATUS" != "200" ] + then + jq . < "$LAST_RESPONSE" + exit_fail "Expected response 200 Ok, getting account status. Got: $STATUS" + fi + BALANCE=$(jq -r .balance.amount < "$LAST_RESPONSE") + if [ "$BALANCE" == "TESTKUDOS:0" ] + then + jq . < "$LAST_RESPONSE" + exit_fail "Wire transfer did not happen. Got: $BALANCE" + fi fi echo " OK" - echo -n "Getting information about kyc ..." STATUS=$(curl -H "Content-Type: application/json" -X GET \ http://localhost:9966/instances/default/private/kyc \ diff --git a/src/testing/test_merchant_product_creation.sh b/src/testing/test_merchant_product_creation.sh index 1da57a04..dd3a60b5 100755 --- a/src/testing/test_merchant_product_creation.sh +++ b/src/testing/test_merchant_product_creation.sh @@ -19,21 +19,36 @@ set -eu - -echo "Re-initializing database (needed for current libeufin)" # FIXME-MS: enable idempotency AND db-reset! -dropdb talercheck || true -createdb talercheck - +# Replace with 0 for nexus... +USE_FAKEBANK=1 +if [ 1 = "$USE_FAKEBANK" ] +then + ACCOUNT="exchange-account-2" + WIRE_METHOD="x-taler-bank" + BANK_FLAGS="-f -d $WIRE_METHOD -u $ACCOUNT" + BANK_URL="http://localhost:8082/taler-bank-access/" +else + ACCOUNT="exchange-account-1" + WIRE_METHOD="iban" + BANK_FLAGS="-ns -d $WIRE_METHOD -u $ACCOUNT" + BANK_URL="http://localhost:18082/demobanks/default/access-api/" +fi . setup.sh # Launch system. -setup -c "test_template.conf" -enms -u "exchange-account-1" -d "iban" -LAST_RESPONSE=$(mktemp test_response.conf-XXXXXX) -WALLET_DB=$(mktemp test_wallet.json-XXXXXX) +setup -c "test_template.conf" \ + -em \ + $BANK_FLAGS +LAST_RESPONSE=$(mktemp -p "${TMPDIR:-/tmp}" test_response.conf-XXXXXX) +WALLET_DB=$(mktemp -p "${TMPDIR:-/tmp}" test_wallet.json-XXXXXX) CONF="test_template.conf.edited" -BANK_URL="http://localhost:18082/demobanks/default/" -FORTYTHREE=$(get_payto_uri fortythree x) +if [ 1 = "$USE_FAKEBANK" ] +then + FORTYTHREE="payto://x-taler-bank/localhost/fortythree?receiver-name=fortythree" +else + FORTYTHREE=$(get_payto_uri fortythree x) +fi EXCHANGE_URL="http://localhost:8081/" echo -n "Configuring merchant instance ..." @@ -189,14 +204,20 @@ taler-wallet-cli \ bankAccessApiBaseUrl: $BANK_URL, exchangeBaseUrl: $EXCHANGE_URL }' \ - --arg BANK_URL "$BANK_URL/access-api/" \ + --arg BANK_URL "$BANK_URL" \ --arg EXCHANGE_URL "$EXCHANGE_URL" )" 2>wallet-withdraw-1.err >wallet-withdraw-1.out echo -n "." -sleep 10 -# NOTE: once libeufin can do long-polling, we should -# be able to reduce the delay here and run wirewatch -# always in the background via setup +if [ 1 = "$USE_FAKEBANK" ] +then + # Fakebank is instant... + sleep 0 +else + sleep 10 + # NOTE: once libeufin can do long-polling, we should + # be able to reduce the delay here and run wirewatch + # always in the background via setup +fi echo -n "." taler-exchange-wirewatch -L "INFO" -c "$CONF" -t &> taler-exchange-wirewatch.out echo -n "." diff --git a/src/testing/test_merchant_reserve_creation.sh b/src/testing/test_merchant_reserve_creation.sh index a1a076a4..e7ebf615 100755 --- a/src/testing/test_merchant_reserve_creation.sh +++ b/src/testing/test_merchant_reserve_creation.sh @@ -19,15 +19,27 @@ set -eu -echo "Re-initializing database (needed for current libeufin)" # FIXME-MS: enable idempotency AND db-reset! -dropdb talercheck || true -createdb talercheck - +# Replace with 0 for nexus... +USE_FAKEBANK=1 +if [ 1 = "$USE_FAKEBANK" ] +then + ACCOUNT="exchange-account-2" + WIRE_METHOD="x-taler-bank" + BANK_FLAGS="-f -d $WIRE_METHOD -u $ACCOUNT" + BANK_URL="http://localhost:8082/taler-bank-access/" +else + ACCOUNT="exchange-account-1" + WIRE_METHOD="iban" + BANK_FLAGS="-ns -d $WIRE_METHOD -u $ACCOUNT" + BANK_URL="http://localhost:18082/demobanks/default/access-api/" +fi . setup.sh # Launch exchange, merchant and bank. -setup -c "test_template.conf" -enms -u "exchange-account-1" -d "iban" -LAST_RESPONSE=$(mktemp test_response.conf-XXXXXX) +setup -c "test_template.conf" \ + -em \ + $BANK_FLAGS +LAST_RESPONSE=$(mktemp -p "${TMPDIR:-/tmp}" test_response.conf-XXXXXX) CONF="test_template.conf.edited" echo -n "Configuring merchant instance ..." @@ -35,7 +47,7 @@ echo -n "Configuring merchant instance ..." STATUS=$(curl -H "Content-Type: application/json" -X POST \ -H 'Authorization: Bearer secret-token:super_secret' \ http://localhost:9966/management/instances \ - -d '{"auth":{"method":"external"},"accounts":[{"payto_uri":"payto://x-taler-bank/localhost:18082/43"}],"id":"default","name":"default","user_type":"business","address":{},"jurisdiction":{},"use_stefan":true,"default_wire_transfer_delay":{"d_us" : 50000000},"default_pay_delay":{"d_us": 60000000}}' \ + -d '{"auth":{"method":"external"},"accounts":[{"payto_uri":"payto://x-taler-bank/localhost:18082/fortythree"}],"id":"default","name":"default","user_type":"business","address":{},"jurisdiction":{},"use_stefan":true,"default_wire_transfer_delay":{"d_us" : 50000000},"default_pay_delay":{"d_us": 60000000}}' \ -w "%{http_code}" -s -o /dev/null) if [ "$STATUS" != "204" ] @@ -48,7 +60,7 @@ echo -n "Creating reserve ..." #bash STATUS=$(curl 'http://localhost:9966/instances/default/private/reserves' \ - -d '{"initial_balance":"TESTKUDOS:2","exchange_url":"http://localhost:8081/","wire_method":"iban"}' \ + -d '{"initial_balance":"TESTKUDOS:2","exchange_url":"http://localhost:8081/","wire_method":"'"$WIRE_METHOD"'"}' \ -w "%{http_code}" -s -o "$LAST_RESPONSE") if [ "$STATUS" != "200" ] @@ -76,32 +88,42 @@ fi echo -n "Wire transferring... " # Exchange wants TESTKUDOS:2 from account 43, under RESERVE_PUB. -EXCHANGE_PAYTO=$(get_payto_uri exchange x) -export LIBEUFIN_SANDBOX_USERNAME=fortythree -export LIBEUFIN_SANDBOX_PASSWORD=x -export LIBEUFIN_SANDBOX_URL="http://localhost:18082/" -libeufin-cli sandbox demobank new-transaction \ - --bank-account "fortythree" \ - --payto-with-subject "$EXCHANGE_PAYTO&message=$RESERVE_PUB" \ - --amount "TESTKUDOS:2" -unset LIBEUFIN_SANDBOX_USERNAME -unset LIBEUFIN_SANDBOX_PASSWORD -unset LIBEUFIN_SANDBOX_URL -echo "OK" -echo -n "Give Nexus time to detect the payment (FIXME)... " -sleep 10 # FIXME-MS: replace with call to Nexus to right now poll the sandbox ... -# This seems to not work (exchange user unknown). Not sure why. -#export LIBEUFIN_NEXUS_USERNAME=exchange -#export LIBEUFIN_NEXUS_PASSWORD=x -#export LIBEUFIN_NEXUS_URL="http://localhost:8082/" -#libeufin-cli \ -# accounts \ -# fetch-transactions \ -# exchange \ -# &> libeufin-transfer-fetch.out -#unset LIBEUFIN_NEXUS_USERNAME -#unset LIBEUFIN_NEXUS_PASSWORD -#unset LIBEUFIN_NEXUS_URL +if [ 1 = "$USE_FAKEBANK" ] +then + BODY='{"reserve_pub":"'"$RESERVE_PUB"'","debit_account":"payto://x-taler-bank/localhost/fortythree","amount":"TESTKUDOS:2"}' + curl -X POST \ + -d "$BODY" \ + -s \ + http://localhost:8082/exchange/admin/add-incoming \ + > /dev/null +else + EXCHANGE_PAYTO=$(get_payto_uri exchange x) + export LIBEUFIN_SANDBOX_USERNAME=fortythree + export LIBEUFIN_SANDBOX_PASSWORD=x + export LIBEUFIN_SANDBOX_URL="http://localhost:18082/" + libeufin-cli sandbox demobank new-transaction \ + --bank-account "fortythree" \ + --payto-with-subject "$EXCHANGE_PAYTO&message=$RESERVE_PUB" \ + --amount "TESTKUDOS:2" + unset LIBEUFIN_SANDBOX_USERNAME + unset LIBEUFIN_SANDBOX_PASSWORD + unset LIBEUFIN_SANDBOX_URL + echo "OK" + echo -n "Give Nexus time to detect the payment (FIXME)... " + sleep 10 # FIXME-MS: replace with call to Nexus to right now poll the sandbox ... + # This seems to not work (exchange user unknown). Not sure why. + #export LIBEUFIN_NEXUS_USERNAME=exchange + #export LIBEUFIN_NEXUS_PASSWORD=x + #export LIBEUFIN_NEXUS_URL="http://localhost:8082/" + #libeufin-cli \ + # accounts \ + # fetch-transactions \ + # exchange \ + # &> libeufin-transfer-fetch.out + #unset LIBEUFIN_NEXUS_USERNAME + #unset LIBEUFIN_NEXUS_PASSWORD + #unset LIBEUFIN_NEXUS_URL +fi echo "OK" echo "Fetch transaction for exchange" diff --git a/src/testing/test_merchant_transfer_tracking.sh b/src/testing/test_merchant_transfer_tracking.sh index 6ac079f3..cba85d12 100755 --- a/src/testing/test_merchant_transfer_tracking.sh +++ b/src/testing/test_merchant_transfer_tracking.sh @@ -20,19 +20,30 @@ set -eu -echo "Re-initializing database (needed for current libeufin)" # FIXME-MS: enable idempotency AND db-reset! -dropdb talercheck || true -createdb talercheck +# Replace with 0 for nexus... +USE_FAKEBANK=1 +if [ 1 = "$USE_FAKEBANK" ] +then + ACCOUNT="exchange-account-2" + WIRE_METHOD="x-taler-bank" + BANK_FLAGS="-f -d $WIRE_METHOD -u $ACCOUNT" + BANK_URL="http://localhost:8082/taler-bank-access/" +else + ACCOUNT="exchange-account-1" + WIRE_METHOD="iban" + BANK_FLAGS="-ns -d $WIRE_METHOD -u $ACCOUNT" + BANK_URL="http://localhost:18082/demobanks/default/access-api/" +fi . setup.sh # Launch system. -setup -c "test_template.conf" -enms -u "exchange-account-1" -d "iban" -LAST_RESPONSE=$(mktemp test_response.conf-XXXXXX) -WALLET_DB=$(mktemp test_wallet.json-XXXXXX) +setup -c "test_template.conf" \ + -em \ + $BANK_FLAGS +LAST_RESPONSE=$(mktemp -p "${TMPDIR:-/tmp}" test_response.conf-XXXXXX) +WALLET_DB=$(mktemp -p "${TMPDIR:-/tmp}" test_wallet.json-XXXXXX) CONF="test_template.conf.edited" -#FORTYTHREE=$(get_payto_uri merchant x) -BANK_URL="http://localhost:18082/demobanks/default/" EXCHANGE_URL="http://localhost:8081/" echo -n "First prepare wallet with coins..." @@ -48,11 +59,20 @@ taler-wallet-cli \ bankAccessApiBaseUrl: $BANK_URL, exchangeBaseUrl: $EXCHANGE_URL }' \ - --arg BANK_URL "${BANK_URL}access-api/" \ + --arg BANK_URL "${BANK_URL}" \ --arg EXCHANGE_URL "$EXCHANGE_URL" )" 2>wallet-withdraw-1.err >wallet-withdraw-1.out echo -n "." -sleep 10 +if [ 1 = "$USE_FAKEBANK" ] +then + # Fakebank is instant... + sleep 0 +else + sleep 10 + # NOTE: once libeufin can do long-polling, we should + # be able to reduce the delay here and run wirewatch + # always in the background via setup +fi echo -n "." # NOTE: once libeufin can do long-polling, we should # be able to reduce the delay here and run wirewatch @@ -71,8 +91,18 @@ echo " OK" # echo -n "Configuring merchant default instance ..." -TOR_PAYTO=$(get_payto_uri tor x) -GNUNET_PAYTO=$(get_payto_uri gnunet x) +if [ 1 = "$USE_FAKEBANK" ] +then + TOR_PAYTO="payto://x-taler-bank/localhost/tor?receiver-name=tor" + GNUNET_PAYTO="payto://x-taler-bank/localhost/gnunet?receiver-name=gnunet" + SURVEY_PAYTO="payto://x-taler-bank/localhost/survey?receiver-name=survey" + TUTORIAL_PAYTO="payto://x-taler-bank/localhost/tutorial?receiver-name=tutorial" +else + TOR_PAYTO=$(get_payto_uri tor x) + GNUNET_PAYTO=$(get_payto_uri gnunet x) + SURVEY_PAYTO=$(get_payto_uri survey x) + TUTORIAL_PAYTO=$(get_payto_uri tutorial x) +fi # create with 2 address STATUS=$(curl -H "Content-Type: application/json" -X POST \ @@ -88,8 +118,6 @@ fi echo "OK" echo -n "Configuring merchant test instance ..." -SURVEY_PAYTO=$(get_payto_uri survey x) -TUTORIAL_PAYTO=$(get_payto_uri tutorial x) # create with 2 address STATUS=$(curl -H "Content-Type: application/json" -X POST \ @@ -180,16 +208,27 @@ sleep 3 echo " DONE" echo -n "Obtaining wire transfer details from bank..." -# Emulating the previous pybank-based logic of getting -# the wire transfer information _via the exchange_ bank -# account. NOTE: grabbing tx == 0, since the latest -# transaction appear first in the bank's history. -BANKDATA=$(get_bankaccount_transactions exchange x | jq '.transactions[0]') -SUBJECT=$(echo "$BANKDATA" | jq -r .subject) -WTID=$(echo "$SUBJECT" | awk '{print $1}') -WURL=$(echo "$SUBJECT" | awk '{print $2}') -CREDIT_AMOUNT=$(echo "$BANKDATA" | jq -r .currency):$(echo "$BANKDATA" | jq -r .amount) -TARGET=$(echo "$BANKDATA" | jq -r .creditorIban) + +if [ 1 = "$USE_FAKEBANK" ] +then + BANKDATA="$(curl 'http://localhost:8082/exchange/history/outgoing?delta=1' -s)" + WTID=$(echo "$BANKDATA" | jq -r .outgoing_transactions[0].wtid) + WURL=$(echo "$BANKDATA" | jq -r .outgoing_transactions[0].exchange_base_url) + CREDIT_AMOUNT=$(echo "$BANKDATA" | jq -r .outgoing_transactions[0].amount) + TARGET_PAYTO=$(echo "$BANKDATA" | jq -r .outgoing_transactions[0].credit_account) + TARGET=$(echo "$TARGET_PAYTO" | awk -F = '{print $2}') +else + # Emulating the previous pybank-based logic of getting + # the wire transfer information _via the exchange_ bank + # account. NOTE: grabbing tx == 0, since the latest + # transaction appear first in the bank's history. + BANKDATA=$(get_bankaccount_transactions exchange x | jq '.transactions[0]') + SUBJECT=$(echo "$BANKDATA" | jq -r .subject) + WTID=$(echo "$SUBJECT" | awk '{print $1}') + WURL=$(echo "$SUBJECT" | awk '{print $2}') + CREDIT_AMOUNT=$(echo "$BANKDATA" | jq -r .currency):$(echo "$BANKDATA" | jq -r .amount) + TARGET=$(echo "$BANKDATA" | jq -r .creditorIban) +fi # Figure out which account got paid, in order to # resort the right (and complete: including the receiver-name) # TARGET_PAYTO @@ -199,22 +238,14 @@ fi if echo "$TUTORIAL_PAYTO" | grep -q "$TARGET" > /dev/null; then TARGET_PAYTO="$TUTORIAL_PAYTO"; fi -echo " DONE" if [ "$EXCHANGE_URL" != "$WURL" ] then exit_fail "Wrong exchange URL in subject '$SUBJECT', expected $EXCHANGE_URL" fi - echo " OK" set +e -export TARGET_PAYTO -export WURL -export WTID -export CREDIT_AMOUNT -export LAST_RESPONSE - echo -n "Notifying merchant of correct wire transfer, but on wrong instance..." #issue 6912 diff --git a/src/testing/test_merchant_wirewatch.sh b/src/testing/test_merchant_wirewatch.sh index 7834c1d0..b8a37f2f 100755 --- a/src/testing/test_merchant_wirewatch.sh +++ b/src/testing/test_merchant_wirewatch.sh @@ -19,109 +19,128 @@ # Testcase for #6363 (WiP) set -eu -echo "Re-initializing database (needed for current libeufin)" # FIXME-MS: enable idempotency AND db-reset! -dropdb talercheck || true -createdb talercheck +# Replace with 0 for nexus... +USE_FAKEBANK=1 +if [ 1 = "$USE_FAKEBANK" ] +then + ACCOUNT="exchange-account-2" + WIRE_METHOD="x-taler-bank" + BANK_FLAGS="-f -d $WIRE_METHOD -u $ACCOUNT" + BANK_URL="http://localhost:8082/taler-bank-access/" +else + ACCOUNT="exchange-account-1" + WIRE_METHOD="iban" + BANK_FLAGS="-ns -d $WIRE_METHOD -u $ACCOUNT" + BANK_URL="http://localhost:18082/demobanks/default/access-api/" +fi . setup.sh # Launch exchange, merchant and bank. -setup -c "test_template.conf" -enms -u "exchange-account-1" -d "iban" -LAST_RESPONSE=$(mktemp test_response.conf-XXXXXX) +setup -c "test_template.conf" \ + -em \ + $BANK_FLAGS +LAST_RESPONSE=$(mktemp -p "${TMPDIR:-/tmp}" test_response.conf-XXXXXX) CONF="test_template.conf.edited" -WALLET_DB=$(mktemp test_wallet.json-XXXXXX) -BANK_URL="http://localhost:18082/demobanks/default/" +WALLET_DB=$(mktemp -p "${TMPDIR:-/tmp}" test_wallet.json-XXXXXX) EXCHANGE_URL="http://localhost:8081/" -export LIBEUFIN_SANDBOX_DB_CONNECTION='postgresql:///talercheck' -export LIBEUFIN_SANDBOX_ADMIN_PASSWORD="secret" -export LIBEUFIN_SANDBOX_URL="http://localhost:18082/" - -export EBICS_HOST="talerebics" -export LIBEUFIN_SANDBOX_USERNAME="admin" -export LIBEUFIN_SANDBOX_PASSWORD="secret" -export EBICS_USER_ID="gnunet_ebics" -export EBICS_PARTNER="GnunetPartner" -export BANK_CONNECTION_NAME="gnunet-connection" -export NEXUS_ACCOUNT_NAME="GnunetCredit" -# The 'gnunet' account is created by -# taler-bank-manage-testing and used for -# the 'default' instance, so this must be used here. -export SANDBOX_ACCOUNT_NAME="gnunet" - -export LIBEUFIN_NEXUS_URL="http://localhost:8082" -# These two are from taler-bank-manage-testing... - -# Define credentials for wirewatch user, will be Merchant client. -CREDIT_USERNAME="merchant-wirewatch" -CREDIT_PASSWORD="merchant-wirewatch-password" - -echo -n "Create credit user (for gnunet-merchant) at Nexus ..." - -export LIBEUFIN_NEXUS_DB_CONNECTION='postgresql:///talercheck' -libeufin-nexus \ - superuser "$CREDIT_USERNAME" \ - --password="$CREDIT_PASSWORD" \ - &> nexus-credit-create.log -echo " OK" -export LIBEUFIN_NEXUS_USERNAME="$CREDIT_USERNAME" -export LIBEUFIN_NEXUS_PASSWORD="$CREDIT_PASSWORD" -export GNUNET_CREDIT_FACADE=facade-gnunet-credit - -libeufin-cli sandbox \ - demobank \ - new-ebicssubscriber \ - --host-id ${EBICS_HOST} \ - --user-id ${NEXUS_ACCOUNT_NAME} \ - --partner-id ${EBICS_PARTNER} \ - --bank-account ${SANDBOX_ACCOUNT_NAME} \ - &> sandbox-subscriber-create.log - -libeufin-cli \ - connections \ - new-ebics-connection \ - --ebics-url="${LIBEUFIN_SANDBOX_URL}ebicsweb" \ - --host-id=${EBICS_HOST} \ - --partner-id=${EBICS_PARTNER} \ - --ebics-user-id=${NEXUS_ACCOUNT_NAME} \ - ${BANK_CONNECTION_NAME} \ - &> nexus-connection-create.log - -libeufin-cli \ - connections \ - connect \ - ${BANK_CONNECTION_NAME} \ - &> nexus-connection-connect.log - -libeufin-cli \ - connections \ - download-bank-accounts \ - ${BANK_CONNECTION_NAME} \ - &> nexus-account-download.log - -libeufin-cli \ - connections \ - import-bank-account \ - --offered-account-id=${SANDBOX_ACCOUNT_NAME} \ - --nexus-bank-account-id=${NEXUS_ACCOUNT_NAME} \ - ${BANK_CONNECTION_NAME} \ - &> nexus-account-import.log - -libeufin-cli \ - facades \ - new-anastasis-facade \ - --currency=TESTKUDOS \ - --facade-name=${GNUNET_CREDIT_FACADE} \ - ${BANK_CONNECTION_NAME} \ - ${NEXUS_ACCOUNT_NAME} \ - &> nexus-new-facade.log - -FACADE_URL=$(libeufin-cli facades list | jq .facades[0].baseUrl | tr -d \") - -# FIXME: is this correct? Strange to use the super-user -# credentials here! -FACADE_USERNAME="${CREDIT_USERNAME}" -FACADE_PASSWORD="${CREDIT_PASSWORD}" +if [ 1 = "$USE_FAKEBANK" ] +then + FACADE_URL="http://localhost:8082/anastasis-api/gnunet/" + FACADE_USERNAME="gnunet" + FACADE_PASSWORD="x" +else + export LIBEUFIN_SANDBOX_DB_CONNECTION='postgresql:///talercheck' + export LIBEUFIN_SANDBOX_ADMIN_PASSWORD="secret" + export LIBEUFIN_SANDBOX_URL="http://localhost:18082/" + + export EBICS_HOST="talerebics" + export LIBEUFIN_SANDBOX_USERNAME="admin" + export LIBEUFIN_SANDBOX_PASSWORD="secret" + export EBICS_USER_ID="gnunet_ebics" + export EBICS_PARTNER="GnunetPartner" + export BANK_CONNECTION_NAME="gnunet-connection" + export NEXUS_ACCOUNT_NAME="GnunetCredit" + # The 'gnunet' account is created by + # taler-bank-manage-testing and used for + # the 'default' instance, so this must be used here. + export SANDBOX_ACCOUNT_NAME="gnunet" + + export LIBEUFIN_NEXUS_URL="http://localhost:8082" + # These two are from taler-bank-manage-testing... + + # Define credentials for wirewatch user, will be Merchant client. + CREDIT_USERNAME="merchant-wirewatch" + CREDIT_PASSWORD="merchant-wirewatch-password" + + echo -n "Create credit user (for gnunet-merchant) at Nexus ..." + + export LIBEUFIN_NEXUS_DB_CONNECTION='postgresql:///talercheck' + libeufin-nexus \ + superuser "$CREDIT_USERNAME" \ + --password="$CREDIT_PASSWORD" \ + &> nexus-credit-create.log + echo " OK" + export LIBEUFIN_NEXUS_USERNAME="$CREDIT_USERNAME" + export LIBEUFIN_NEXUS_PASSWORD="$CREDIT_PASSWORD" + export GNUNET_CREDIT_FACADE=facade-gnunet-credit + + libeufin-cli sandbox \ + demobank \ + new-ebicssubscriber \ + --host-id ${EBICS_HOST} \ + --user-id ${NEXUS_ACCOUNT_NAME} \ + --partner-id ${EBICS_PARTNER} \ + --bank-account ${SANDBOX_ACCOUNT_NAME} \ + &> sandbox-subscriber-create.log + + libeufin-cli \ + connections \ + new-ebics-connection \ + --ebics-url="${LIBEUFIN_SANDBOX_URL}ebicsweb" \ + --host-id=${EBICS_HOST} \ + --partner-id=${EBICS_PARTNER} \ + --ebics-user-id=${NEXUS_ACCOUNT_NAME} \ + ${BANK_CONNECTION_NAME} \ + &> nexus-connection-create.log + + libeufin-cli \ + connections \ + connect \ + ${BANK_CONNECTION_NAME} \ + &> nexus-connection-connect.log + + libeufin-cli \ + connections \ + download-bank-accounts \ + ${BANK_CONNECTION_NAME} \ + &> nexus-account-download.log + + libeufin-cli \ + connections \ + import-bank-account \ + --offered-account-id=${SANDBOX_ACCOUNT_NAME} \ + --nexus-bank-account-id=${NEXUS_ACCOUNT_NAME} \ + ${BANK_CONNECTION_NAME} \ + &> nexus-account-import.log + + libeufin-cli \ + facades \ + new-anastasis-facade \ + --currency=TESTKUDOS \ + --facade-name=${GNUNET_CREDIT_FACADE} \ + ${BANK_CONNECTION_NAME} \ + ${NEXUS_ACCOUNT_NAME} \ + &> nexus-new-facade.log + + FACADE_URL=$(libeufin-cli facades list | jq .facades[0].baseUrl | tr -d \") + + # FIXME: is this correct? Strange to use the super-user + # credentials here! + FACADE_USERNAME="${CREDIT_USERNAME}" + FACADE_PASSWORD="${CREDIT_PASSWORD}" +fi echo -n "First prepare wallet with coins..." rm -f "${WALLET_DB}" @@ -133,21 +152,29 @@ taler-wallet-cli \ "$(jq -n ' { amount: "TESTKUDOS:99", - bankAccessApiBaseUrl: $BANK_ACCESS_API_URL, + bankAccessApiBaseUrl: $BANK_URL, exchangeBaseUrl: $EXCHANGE_URL }' \ - --arg BANK_URL "$BANK_URL/access-api/" \ - --arg BANK_ACCESS_API_URL "$BANK_URL/access-api/" \ + --arg BANK_URL "$BANK_URL" \ --arg EXCHANGE_URL "$EXCHANGE_URL" )" 2>wallet-withdraw-1.err >wallet-withdraw-1.out -# FIXME-MS: add logic to have nexus check immediately here. echo -n "." -sleep 10 -# NOTE: once libeufin can do long-polling, we should -# be able to reduce the delay here and run wirewatch -# always in the background via setup +if [ 1 = "$USE_FAKEBANK" ] +then + # Fakebank is instant... + sleep 0 +else + sleep 10 + # NOTE: once libeufin can do long-polling, we should + # be able to reduce the delay here and run wirewatch + # always in the background via setup +fi echo -n "." -taler-exchange-wirewatch -L "INFO" -c "$CONF" -t &> taler-exchange-wirewatch.out +taler-exchange-wirewatch \ + -L "INFO" \ + -c "$CONF" \ + -t \ + &> taler-exchange-wirewatch.out echo -n "." taler-wallet-cli \ --wallet-db="$WALLET_DB" \ @@ -161,7 +188,12 @@ echo " OK" # echo -n "Configuring merchant default instance ..." -GNUNET_PAYTO=$(get_payto_uri gnunet x) +if [ 1 = "$USE_FAKEBANK" ] +then + GNUNET_PAYTO="payto://x-taler-bank/localhost/gnunet?receiver-name=gnunet" +else + GNUNET_PAYTO=$(get_payto_uri gnunet x) +fi STATUS=$(curl -H "Content-Type: application/json" -X POST \ -H 'Authorization: Bearer secret-token:super_secret' \ http://localhost:9966/management/instances \ @@ -248,14 +280,17 @@ taler-exchange-transfer\ -L INFO &> transfer.log echo " DONE" -echo -n "Waiting for Nexus and Sandbox to settle the payment ..." -sleep 3 # FIXME-MS: replace with call to Nexus to right now poll the sandbox ... -libeufin-cli \ - accounts \ - fetch-transactions \ - ${NEXUS_ACCOUNT_NAME} \ - &> libeufin-transfer-fetch.out -echo " DONE" +if [ 1 != "$USE_FAKEBANK" ] +then + echo -n "Waiting for Nexus and Sandbox to settle the payment ..." + sleep 3 # FIXME-MS: replace with call to Nexus to right now poll the sandbox ... + libeufin-cli \ + accounts \ + fetch-transactions \ + ${NEXUS_ACCOUNT_NAME} \ + &> libeufin-transfer-fetch.out + echo " DONE" +fi echo -n "Obtaining wire transfer details from bank..." taler-merchant-wirewatch \ diff --git a/src/testing/test_template.conf b/src/testing/test_template.conf index 0c3faa23..ccef8c55 100644 --- a/src/testing/test_template.conf +++ b/src/testing/test_template.conf @@ -86,6 +86,15 @@ WIRE_GATEWAY_AUTH_METHOD = basic USERNAME = exchange PASSWORD = x +[exchange-account-2] +PAYTO_URI = "payto://x-taler-bank/localhost/exchange?receiver-name=exchange" +ENABLE_DEBIT = YES +ENABLE_CREDIT = YES + +[exchange-accountcredentials-2] +WIRE_GATEWAY_AUTH_METHOD = none +WIRE_GATEWAY_URL = "http://localhost:8082/exchange/" + [merchant-exchange-default] EXCHANGE_BASE_URL = http://localhost:8081/ CURRENCY = TESTKUDOS -- cgit v1.2.3