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/test_merchant_order_creation.sh | 152 ++++++++++++++++++---------- 1 file changed, 100 insertions(+), 52 deletions(-) (limited to 'src/testing/test_merchant_order_creation.sh') 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 \ -- cgit v1.2.3