#!/bin/bash # This file is part of TALER # Copyright (C) 2014-2023 Taler Systems SA # # TALER is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as # published by the Free Software Foundation; either version 3, or # (at your option) any later version. # # TALER is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public # License along with TALER; see the file COPYING. If not, see # # # Testcase for #6363 (WiP) . initialize_taler_system.sh # NEXUS_PORT is from the initialize_taler_systems.sh script export NEXUS_PORT # 'talerebics' is used in taler-bank-manage-testing export EBICS_HOST="talerebics" # These are also from taler-bank-manage-testing export LIBEUFIN_SANDBOX_DB_CONNECTION="jdbc:sqlite:${TALER_DB}" export LIBEUFIN_SANDBOX_ADMIN_PASSWORD="secret" export LIBEUFIN_SANDBOX_URL="http://localhost:1${NEXUS_PORT}/" 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:${NEXUS_PORT}" # These two are from taler-bank-manage-testing... # Make credit user, will be Merchant client. CREDIT_USERNAME=$(taler-config -c "$CONF" \ -s "taler-merchant-wirewatch" \ -o "USERNAME") CREDIT_PASSWORD=$(taler-config -c "$CONF" \ -s "taler-merchant-wirewatch" \ -o "PASSWORD") echo -n "Create credit user (for gnunet-merchant) at Nexus ..." export LIBEUFIN_NEXUS_DB_CONNECTION="jdbc:sqlite:${TALER_DB}" 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="${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 \") echo -n "Setting FACADE URL in configuration..." taler-config -c "$CONF" \ -s "taler-merchant-wirewatch" \ -o "WIRE_GATEWAY_URL" \ -V "${FACADE_URL}" echo " OK" echo -n "First prepare wallet with coins..." rm -f "${WALLET_DB}" taler-wallet-cli \ --no-throttle \ --wallet-db="$WALLET_DB" \ api \ --expect-success 'withdrawTestBalance' \ "$(jq -n ' { amount: "TESTKUDOS:99", bankAccessApiBaseUrl: $BANK_ACCESS_API_URL, exchangeBaseUrl: $EXCHANGE_URL }' \ --arg BANK_URL "$BANK_URL/access-api/" \ --arg BANK_ACCESS_API_URL "$BANK_URL/access-api/" \ --arg EXCHANGE_URL "$EXCHANGE_URL" )" 2>wallet-withdraw-1.err >wallet-withdraw-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" # # CREATE INSTANCE FOR TESTING # echo -n "Configuring merchant default instance ..." TOR_PAYTO=$(get_payto_uri tor x) GNUNET_PAYTO=$(get_payto_uri gnunet x) # create with 2 address 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":"'"$GNUNET_PAYTO"'"}],"id":"default","name":"default","user_type":"business","address":{},"jurisdiction":{},"default_max_wire_fee":"TESTKUDOS:1", "default_max_deposit_fee":"TESTKUDOS:1","default_wire_fee_amortization":1,"default_wire_transfer_delay":{"d_us" : 50000000},"default_pay_delay":{"d_us": 60000000}}' \ -w "%{http_code}" -s -o /dev/null) if [ "$STATUS" != "204" ] then exit_fail "Expected 204 no content. Got: $STATUS" fi echo "OK" # CREATE ORDER AND SELL IT echo -n "Creating order to be paid..." STATUS=$(curl 'http://localhost:9966/instances/default/private/orders' \ -d '{"order":{"amount":"TESTKUDOS:1","summary":"payme"}}' \ -w "%{http_code}" \ -s \ -o "$LAST_RESPONSE") if [ "$STATUS" != "200" ] then exit_fail "Expected 200 OK. Got: $STATUS " "$(cat "$LAST_RESPONSE")" fi ORDER_ID=$(jq -e -r .order_id < "$LAST_RESPONSE") STATUS=$(curl "http://localhost:9966/instances/default/private/orders/${ORDER_ID}" \ -w "%{http_code}" \ -s \ -o "$LAST_RESPONSE") if [ "$STATUS" != "200" ] then exit_fail "Expected 200 ok. Got: $STATUS" "$(cat "$LAST_RESPONSE")" fi PAY_URL=$(jq -e -r .taler_pay_uri < "$LAST_RESPONSE") echo OK NOW=$(date +%s) echo -n "Pay first order ..." taler-wallet-cli \ --no-throttle \ --wallet-db="$WALLET_DB" \ handle-uri "${PAY_URL}" \ -y 2> wallet-pay1.err > wallet-pay1.log NOW2=$(date +%s) echo "OK. Took $(( NOW2 - NOW))s." STATUS=$(curl "http://localhost:9966/instances/default/private/orders/${ORDER_ID}" \ -w "%{http_code}" \ -s \ -o "$LAST_RESPONSE") if [ "$STATUS" != "200" ] then exit_fail "Expected 200 Ok. Got: $STATUS" "$(cat "$LAST_RESPONSE")" fi ORDER_STATUS=$(jq -r .order_status < "$LAST_RESPONSE") if [ "$ORDER_STATUS" != "paid" ] then exit_fail "Expected order status 'paid'. Got: $ORDER_STATUS" "$(cat "$LAST_RESPONSE")" fi # # WIRE TRANSFER TO MERCHANT AND NOTIFY BACKEND # WIRE_DEADLINE=$(jq -r .contract_terms.wire_transfer_deadline.t_s < "$LAST_RESPONSE") NOW=$(date +%s) TO_SLEEP="$(( 1 + WIRE_DEADLINE - NOW ))" echo -n "Perform wire transfers (with ${TO_SLEEP}s timeshift) ..." taler-exchange-aggregator \ -y \ -c "$CONF" \ -T "${TO_SLEEP}000000" \ -t \ -L INFO &> aggregator.log taler-exchange-transfer\ -c "$CONF" \ -t \ -L INFO &> transfer.log echo " DONE" echo -n "Waiting for Nexus and Sandbox to settle the payment ..." sleep 3 libeufin-cli \ accounts \ fetch-transactions \ ${NEXUS_ACCOUNT_NAME} \ &> libeufin-transfer-fetch.out echo " DONE" echo -n "Obtaining wire transfer details from bank..." taler-merchant-wirewatch \ -c "$CONF" \ -t \ -L INFO &> merchant-wirewatch.log echo " OK" echo -n "Fetching wire transfers of DEFAULT instance ..." STATUS=$(curl 'http://localhost:9966/instances/default/private/transfers' \ -w "%{http_code}" \ -s \ -o "$LAST_RESPONSE") if [ "$STATUS" != "200" ] then exit_fail "Expected response 200 Ok. Got: $STATUS" "$(jq . < "$LAST_RESPONSE")" fi TRANSFERS_LIST_SIZE=$(jq -r '.transfers | length' < "$LAST_RESPONSE") if [ "$TRANSFERS_LIST_SIZE" != "1" ] then exit_fail "Expected one transfer. Got: $TRANSFERS_LIST_SIZE" "$(jq . < "$LAST_RESPONSE")" fi echo " OK" echo -n "Checking order status ..." STATUS=$(curl "http://localhost:9966/instances/default/private/orders/${ORDER_ID}?transfer=YES" \ -w "%{http_code}" \ -s \ -o "$LAST_RESPONSE") if [ "$STATUS" != "200" ] then jq . < "$LAST_RESPONSE" exit_fail "Expected 200 ok. got: $STATUS" "$(cat "$LAST_RESPONSE")" fi WAS_WIRED=$(jq -r .wired < "$LAST_RESPONSE") if [ "$WAS_WIRED" != "true" ] then jq . < "$LAST_RESPONSE" exit_fail "Got .wired 'false', expected 'true'" fi echo " OK" exit 0