tests/taler: init basic test

Test build and services start, but libeufin-bank fails when trying to
access the database to change the admin's password.

We need to execute the command as the libeufin-bank user.

tests/taler: add master private key

tests/taler: rewrite `register_bank_account` to Nix

tests/taler: rename libeufin node to bank

tests/taler: use xtaler wire_type instead of iban

tests/taler: remove redundant data from conf files

tests/taler: enable exchange account

tests/taler: remove unused talerConfig

tests/taler: add client node and attempt a withdrawal

tests/taler: systemd_run optional user and group args

tests/taler: refactor and make a withdrawal

tests/taler: refactor tasks into subtests

tests/taler: properly read and test balance

tests/taler: refactor commands and add comments

nixos/taler: rename private key

tests/taler: enable nexus service in bank node

tests/taler: nexus fake incoming payment test

tests/taler: use correct path for nexus client keys

tests/taler: add merchant node

tests/taler: merchant register instance

tests/taler: init pay for order merchant

tests/taler: fix payto uri

tests/taler: withdraw smaller amount

This makes the test faster

tests/taler: verify balance

tests/nixos: debugging merchant payment, cleanup

tests/taler: fix libeufin command, use curl to register accounts

tests/taler: add basic online test

tests/taler: move nodes into separate directory

tests/taler: fix insufficient balance error

Turns out that the exchange wire fees need to be set up (even if they're
0) in order for the CLI wallet to deposit coins into the merchant's bank
account.

tests/taler: improve node importing, port forwarding

tests/taler: import scripts from a separate file

tests/taler: move tests into a sub-directory

tests/taler: manually start services, cleanup

This results in less overhead and conflict since components will not try
to prematurely connect to the ones that haven't finished their set up.

tests/taler: remove online test

This was used to debug the insufficient balance problem, but it's not
really that useful by itself.

tests/taler: add nexus keys

tests/taler: use bank initalAccounts option

taler/tests: use initialAccount

tests/taler: make nexus work

tests/taler: don't run nexus test if there is no internet

tests/taler: use openFirewall, remove manual package install

fix(test): evaluation errors

fix(test): create nexus role by enabling createLocalDatabase
This commit is contained in:
eljamm 2024-07-23 18:20:41 +01:00 committed by Valentin Gagarin
parent 6f35a68586
commit f70b3a2afa
11 changed files with 709 additions and 0 deletions

View file

@ -1064,6 +1064,7 @@ in {
systemd-userdbd = handleTest ./systemd-userdbd.nix {};
systemd-homed = handleTest ./systemd-homed.nix {};
systemtap = handleTest ./systemtap.nix {};
taler = handleTest ./taler {};
tandoor-recipes = handleTest ./tandoor-recipes.nix {};
tandoor-recipes-script-name = handleTest ./tandoor-recipes-script-name.nix {};
tang = handleTest ./tang.nix {};

View file

@ -0,0 +1,200 @@
{ lib, ... }:
let
# Forward SSH and WebUI ports to host machine
#
# Connect with: ssh root@localhost -p <hostPort>
# Access WebUI from: http://localhost:<hostPort>
#
# NOTE: This is only accessible from an interactive test, for example:
# $ eval $(nix-build -A nixosTests.taler.basic.driver)/bin/nixos-test-driver
mkNode =
{
sshPort ? 0,
webuiPort ? 0,
nodeSettings ? { },
}:
lib.recursiveUpdate {
services.openssh = {
enable = true;
settings = {
PermitRootLogin = "yes";
PermitEmptyPasswords = "yes";
};
};
security.pam.services.sshd.allowNullPassword = true;
virtualisation.forwardPorts =
(lib.optionals (sshPort != 0) [
{
from = "host";
host.port = sshPort;
guest.port = 22;
}
])
++ (lib.optionals (webuiPort != 0) [
{
from = "host";
host.port = webuiPort;
guest.port = webuiPort;
}
]);
} nodeSettings;
in
rec {
CURRENCY = "KUDOS";
FIAT_CURRENCY = "CHF";
nodes = {
exchange =
{ config, lib, ... }:
mkNode {
sshPort = 1111;
webuiPort = 8081;
nodeSettings = {
services.taler = {
settings = {
taler.CURRENCY = CURRENCY;
};
includes = [ ../conf/taler-accounts.conf ];
exchange = {
enable = true;
debug = true;
openFirewall = true;
denominationConfig = lib.readFile ../conf/taler-denominations.conf;
settings = {
exchange = {
MASTER_PUBLIC_KEY = "2TQSTPFZBC2MC4E52NHPA050YXYG02VC3AB50QESM6JX1QJEYVQ0";
BASE_URL = "http://exchange:8081/";
};
exchange-offline = {
MASTER_PRIV_FILE = "${../conf/private.key}";
};
};
};
};
};
};
bank =
{ config, ... }:
mkNode {
sshPort = 2222;
webuiPort = 8082;
nodeSettings = {
services.libeufin.bank = {
enable = true;
debug = true;
openFirewall = true;
createLocalDatabase = true;
initialAccounts = [
{
username = "exchange";
password = "exchange";
name = "Exchange";
}
];
settings = {
libeufin-bank = {
WIRE_TYPE = "x-taler-bank";
# WIRE_TYPE = "iban";
X_TALER_BANK_PAYTO_HOSTNAME = "bank:8082";
# IBAN_PAYTO_BIC = "SANDBOXX";
BASE_URL = "bank:8082";
# Allow creating new accounts
ALLOW_REGISTRATION = "yes";
# A registration bonus makes withdrawals easier since the
# bank account balance is not empty
REGISTRATION_BONUS_ENABLED = "yes";
REGISTRATION_BONUS = "${CURRENCY}:100";
DEFAULT_DEBT_LIMIT = "${CURRENCY}:500";
# NOTE: The exchange's bank account must be initialised before
# the main bank service starts, else it doesn't work.
# The `services.libeufin.bank.initialAccounts` option can be used to do this.
ALLOW_CONVERSION = "yes";
ALLOW_EDIT_CASHOUT_PAYTO_URI = "yes";
SUGGESTED_WITHDRAWAL_EXCHANGE = "http://exchange:8081/";
inherit CURRENCY FIAT_CURRENCY;
};
};
};
services.libeufin.nexus = {
enable = true;
debug = true;
openFirewall = true;
createLocalDatabase = true;
settings = {
# https://docs.taler.net/libeufin/setup-ebics-at-postfinance.html
nexus-ebics = {
# == Mandatory ==
CURRENCY = FIAT_CURRENCY;
# Bank
HOST_BASE_URL = "https://isotest.postfinance.ch/ebicsweb/ebicsweb";
BANK_DIALECT = "postfinance";
# EBICS IDs
HOST_ID = "PFEBICS";
USER_ID = "PFC00639";
PARTNER_ID = "PFC00639";
# Account information
IBAN = "CH4740123RW4167362694";
BIC = "BIC";
NAME = "nixosTest nixosTest";
# == Optional ==
CLIENT_PRIVATE_KEYS_FILE = "${../conf/client-ebics-keys.json}";
BANK_PUBLIC_KEYS_FILE = "${../conf/bank-ebics-keys.json}";
};
};
};
};
};
merchant =
{ config, ... }:
mkNode {
sshPort = 3333;
webuiPort = 8083;
nodeSettings = {
services.taler = {
settings = {
taler.CURRENCY = CURRENCY;
};
merchant = {
enable = true;
debug = true;
openFirewall = true;
settings.merchant-exchange-test = {
EXCHANGE_BASE_URL = "http://exchange:8081/";
MASTER_KEY = "2TQSTPFZBC2MC4E52NHPA050YXYG02VC3AB50QESM6JX1QJEYVQ0";
inherit CURRENCY;
};
};
};
};
};
client =
{ pkgs, ... }:
mkNode {
sshPort = 4444;
nodeSettings = {
environment.systemPackages = [ pkgs.taler-wallet-core ];
};
};
};
}

View file

@ -0,0 +1,107 @@
{
lib,
pkgs,
nodes,
...
}:
let
cfgNodes = pkgs.callPackage ./nodes.nix { inherit lib; };
bankConfig = nodes.bank.config.environment.etc."libeufin/libeufin.conf".source;
inherit (cfgNodes) CURRENCY FIAT_CURRENCY;
in
{
commonScripts =
# python
''
def succeed(machine, commands):
"""A more convenient `machine.succeed` that supports multi-line inputs"""
flattened_commands = [c.replace("\n", "") for c in commands] # flatten multi-line
return machine.succeed(" ".join(flattened_commands))
def systemd_run(machine, cmd, user="nobody", group="nobody"):
"""Execute command as a systemd DynamicUser"""
machine.log(f"Executing command (via systemd-run): \"{cmd}\"")
(status, out) = machine.execute( " ".join([
"systemd-run",
"--service-type=exec",
"--quiet",
"--wait",
"-E PATH=\"$PATH\"",
"-p StandardOutput=journal",
"-p StandardError=journal",
"-p DynamicUser=yes",
f"-p Group={group}" if group != "nobody" else "",
f"-p User={user}" if user != "nobody" else "",
f"$SHELL -c '{cmd}'"
]) )
if status != 0:
raise Exception(f"systemd_run failed (status {status})")
machine.log("systemd-run finished successfully")
def register_bank_account(username, password, name, is_exchange=False):
"""Register Libeufin bank account for the x-taler-bank wire method"""
return systemd_run(bank, " ".join([
'libeufin-bank',
'create-account',
'-c ${bankConfig}',
f'--username {username}',
f'--password {password}',
f'--name {name}',
f'--payto_uri="payto://x-taler-bank/bank:8082/{username}?receiver-name={name}"',
'--exchange' if (is_exchange or username.lower()=="exchange") else ' '
]),
user="libeufin-bank")
def wallet_cli(command):
"""Wrapper for the Taler CLI wallet"""
return client.succeed(
"taler-wallet-cli "
"--no-throttle " # don't do any request throttling
+ command
)
def verify_balance(balanceWanted: str):
"""Compare Taler CLI wallet balance with expected amount"""
balance = wallet_cli("balance --json")
try:
balanceGot = json.loads(balance)["balances"][0]["available"]
except:
balanceGot = "${CURRENCY}:0"
# Compare balance with expected value
if balanceGot != balanceWanted:
client.fail(f'echo Wanted balance: "{balanceWanted}", got: "{balanceGot}"')
else:
client.succeed(f"echo Withdraw successfully made. New balance: {balanceWanted}")
def verify_conversion(regionalWanted: str):
"""Compare converted Libeufin Nexus funds with expected regional currency"""
# Get transaction details
response = json.loads(
succeed(bank, [
"curl -sSfL",
# TODO: get exchange from config?
"-u exchange:exchange",
"http://bank:8082/accounts/exchange/transactions"
])
)
amount = response["transactions"][0]["amount"].split(":") # CURRENCY:VALUE
currencyGot, regionalGot = amount
# Check conversion (1:1 ratio)
if (regionalGot != regionalWanted) or (currencyGot != "${CURRENCY}"):
client.fail(f'echo Wanted "${CURRENCY}:{regionalWanted}", got: "{currencyGot}:{regionalGot}"')
else:
client.succeed(f'echo Conversion successfully made: "${FIAT_CURRENCY}:{regionalWanted}" -> "{currencyGot}:{regionalGot}"')
'';
}

View file

@ -0,0 +1 @@
{"bank_encryption_public_key":"621028HG1M30JAM6923FE381040GA003G80GY01GG80GM0M2040G1EACATA11EF5SVKNBNBYF1S3WSKQ2A2R9VZ7RW2HRX00293JPZ7VQ780RFRVYTQKKDDNJAQGBH4659GT9QYBMJCG1RKZEH1WDJ0GAAY7B7NBMW6FWXCKFYRMZQME0WBGZ1AAMY2VBQ5XAFV8216EFNF2EPG6M5ZGHG9RG6EGED56TK9JESQ02Q7AAVBRAAARVBN9NHCN64KQ3SRRHYXB8RWRK4TSSC93XG8RWMQH4ZDJSBYDCEXFY6G3AWTZ0EZNCJJAYB98T4GNFWZMN81AVYCQHXT1APX81AXCAYNK7J9XETF5CN1J1WV0BVA2BYG4VAMAW123REPN67JF1TNWPTADBMHS17N2V1GFYT8JRWX4TGM2996NXTEPMA8C2CDDE0CRY2A6HT8C5H2D6C62YGRSCF820C0G008","bank_authentication_public_key":"621028HG1M30JAM6923FE381040GA003G80GY01GG80GM0M2040G1EACATA11EF5SVKNBNBYF1S3WSKQ2A2R9VZ7RW2HRX00293JPZ7VQ780RFRVYTQKKDDNJAQGBH4659GT9QYBMJCG1RKZEH1WDJ0GAAY7B7NBMW6FWXCKFYRMZQME0WBGZ1AAMY2VBQ5XAFV8216EFNF2EPG6M5ZGHG9RG6EGED56TK9JESQ02Q7AAVBRAAARVBN9NHCN64KQ3SRRHYXB8RWRK4TSSC93XG8RWMQH4ZDJSBYDCEXFY6G3AWTZ0EZNCJJAYB98T4GNFWZMN81AVYCQHXT1APX81AXCAYNK7J9XETF5CN1J1WV0BVA2BYG4VAMAW123REPN67JF1TNWPTADBMHS17N2V1GFYT8JRWX4TGM2996NXTEPMA8C2CDDE0CRY2A6HT8C5H2D6C62YGRSCF820C0G008","accepted":true}

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,16 @@
[
{
"operation": "exchange-enable-wire-0",
"arguments": {
"payto_uri": "payto://x-taler-bank/bank:8082/exchange?receiver-name=Exchange",
"debit_restrictions": [],
"credit_restrictions": [],
"priority": 0,
"validity_start": {
"t_s": 1725886541
},
"master_sig_add": "68WDT3JX1S5GQ9D3RZWXQVZK9AHFZ46YY5DA993720YA3SCBR4SW3X09NH5DECTXGWBKSN0MGKE1ANA9QZ95SKSNYPS9T9G46PCJC20",
"master_sig_wire": "39CEN9007DEXXMSDFZX1R2YYNANZYAFHX4EZC4ZX3C8DQEYT83JNVCVYMWYDGWEX6S891ZPXD6QHJE9J41YV9EN703Q0NM0MVE4FP18"
}
}
]

View file

@ -0,0 +1 @@
<EFBFBD>Ř'v&©<>űľ˘¶ßH{VWýr<C3BD>¶CjÜ

View file

@ -0,0 +1,10 @@
[exchange-account-test]
PAYTO_URI = payto://x-taler-bank/bank:8082/exchange?receiver-name=Exchange
ENABLE_DEBIT = YES
ENABLE_CREDIT = YES
[exchange-accountcredentials-test]
WIRE_GATEWAY_URL = http://bank:8082/accounts/exchange/taler-wire-gateway/
WIRE_GATEWAY_AUTH_METHOD = BASIC
USERNAME = exchange
PASSWORD = exchange

View file

@ -0,0 +1,95 @@
[COIN-KUDOS-n1-t1726827661]
VALUE = KUDOS:0.1
DURATION_WITHDRAW = 7 days
DURATION_SPEND = 2 years
DURATION_LEGAL = 6 years
FEE_WITHDRAW = KUDOS:0
FEE_DEPOSIT = KUDOS:0
FEE_REFRESH = KUDOS:0
FEE_REFUND = KUDOS:0
RSA_KEYSIZE = 2048
CIPHER = RSA
[COIN-KUDOS-n2-t1726827661]
VALUE = KUDOS:0.2
DURATION_WITHDRAW = 7 days
DURATION_SPEND = 2 years
DURATION_LEGAL = 6 years
FEE_WITHDRAW = KUDOS:0
FEE_DEPOSIT = KUDOS:0
FEE_REFRESH = KUDOS:0
FEE_REFUND = KUDOS:0
RSA_KEYSIZE = 2048
CIPHER = RSA
[COIN-KUDOS-n3-t1726827661]
VALUE = KUDOS:0.4
DURATION_WITHDRAW = 7 days
DURATION_SPEND = 2 years
DURATION_LEGAL = 6 years
FEE_WITHDRAW = KUDOS:0
FEE_DEPOSIT = KUDOS:0
FEE_REFRESH = KUDOS:0
FEE_REFUND = KUDOS:0
RSA_KEYSIZE = 2048
CIPHER = RSA
[COIN-KUDOS-n4-t1726827661]
VALUE = KUDOS:0.8
DURATION_WITHDRAW = 7 days
DURATION_SPEND = 2 years
DURATION_LEGAL = 6 years
FEE_WITHDRAW = KUDOS:0
FEE_DEPOSIT = KUDOS:0
FEE_REFRESH = KUDOS:0
FEE_REFUND = KUDOS:0
RSA_KEYSIZE = 2048
CIPHER = RSA
[COIN-KUDOS-n5-t1726827661]
VALUE = KUDOS:1.6
DURATION_WITHDRAW = 7 days
DURATION_SPEND = 2 years
DURATION_LEGAL = 6 years
FEE_WITHDRAW = KUDOS:0
FEE_DEPOSIT = KUDOS:0
FEE_REFRESH = KUDOS:0
FEE_REFUND = KUDOS:0
RSA_KEYSIZE = 2048
CIPHER = RSA
[COIN-KUDOS-n6-t1726827661]
VALUE = KUDOS:3.2
DURATION_WITHDRAW = 7 days
DURATION_SPEND = 2 years
DURATION_LEGAL = 6 years
FEE_WITHDRAW = KUDOS:0
FEE_DEPOSIT = KUDOS:0
FEE_REFRESH = KUDOS:0
FEE_REFUND = KUDOS:0
RSA_KEYSIZE = 2048
CIPHER = RSA
[COIN-KUDOS-n7-t1726827661]
VALUE = KUDOS:6.4
DURATION_WITHDRAW = 7 days
DURATION_SPEND = 2 years
DURATION_LEGAL = 6 years
FEE_WITHDRAW = KUDOS:0
FEE_DEPOSIT = KUDOS:0
FEE_REFRESH = KUDOS:0
FEE_REFUND = KUDOS:0
RSA_KEYSIZE = 2048
CIPHER = RSA
[COIN-KUDOS-n8-t1726827661]
VALUE = KUDOS:12.8
DURATION_WITHDRAW = 7 days
DURATION_SPEND = 2 years
DURATION_LEGAL = 6 years
FEE_WITHDRAW = KUDOS:0
FEE_DEPOSIT = KUDOS:0
FEE_REFRESH = KUDOS:0
FEE_REFUND = KUDOS:0
RSA_KEYSIZE = 2048
CIPHER = RSA

View file

@ -0,0 +1,7 @@
{
system ? builtins.currentSystem,
pkgs ? import ../../.. { inherit system; },
}:
{
basic = import ./tests/basic.nix { inherit system pkgs; };
}

View file

@ -0,0 +1,270 @@
import ../../make-test-python.nix (
{ pkgs, lib, ... }:
let
cfgNodes = pkgs.callPackage ../common/nodes.nix { inherit lib; };
in
{
# NOTE: The Nexus conversion subtest requires internet access, so to run it
# you must run the test with:
# - nix run .#nixosTests.taler.basic.driver
# or interactively:
# - nix run .#nixosTests.taler.basic.driverInteractive
# - run_tests()
name = "GNU Taler Basic Test";
meta = {
maintainers = lib.teams.ngi.members;
};
# Taler components virtual-machine nodes
nodes = {
inherit (cfgNodes.nodes)
bank
client
exchange
merchant
;
};
# TODO: make tests for each component?
testScript =
{ nodes, ... }:
let
cfgScripts = pkgs.callPackage ../common/scripts.nix { inherit lib pkgs nodes; };
inherit (cfgNodes) CURRENCY FIAT_CURRENCY;
inherit (cfgScripts) commonScripts;
bankConfig = nodes.bank.config.environment.etc."libeufin/libeufin.conf".source;
bankSettings = nodes.bank.services.libeufin.settings.libeufin-bank;
nexusSettings = nodes.bank.services.libeufin.nexus.settings;
# Bank admin account credentials
AUSER = "admin";
APASS = "admin";
TUSER = "testUser";
TPASS = "testUser";
exchangeAccount = ../conf/exchange-account.json;
in
# python
''
import json
# import common scripts
${commonScripts}
# NOTE: start components up individually so they don't conflict before their setup is done
bank.start()
client.start()
bank.wait_for_open_port(8082)
with subtest("Set up Libeufin bank"):
# Modify admin account password, increase debit threshold
systemd_run(bank, 'libeufin-bank passwd -c "${bankConfig}" "${AUSER}" "${APASS}"', "libeufin-bank")
systemd_run(bank, 'libeufin-bank edit-account -c ${bankConfig} --debit_threshold="${bankSettings.CURRENCY}:1000000" ${AUSER}', "libeufin-bank")
# NOTE: the exchange is enabled before the bank starts using the `initialAccounts` option
# TODO: just use that option instead of this?
with subtest("Register bank accounts"):
# username, password, name
register_bank_account("testUser", "testUser", "User")
register_bank_account("merchant", "merchant", "Merchant")
exchange.start()
exchange.wait_for_open_port(8081)
with subtest("Set up exchange"):
exchange.wait_until_succeeds("taler-exchange-offline download sign upload")
# Enable exchange wire account
exchange.succeed('taler-exchange-offline upload < ${exchangeAccount}')
# NOTE: cannot deposit coins/pay merchant if wire fees are not set up
exchange.succeed('taler-exchange-offline wire-fee now x-taler-bank "${CURRENCY}:0" "${CURRENCY}:0" upload')
exchange.succeed('taler-exchange-offline global-fee now "${CURRENCY}:0" "${CURRENCY}:0" "${CURRENCY}:0" 1h 6a 0 upload')
# Verify that exchange keys exist
bank.succeed("curl -s http://exchange:8081/keys")
merchant.start()
merchant.wait_for_open_port(8083)
with subtest("Set up merchant"):
# Create default instance (similar to admin)
succeed(merchant, [
"curl -X POST",
"-H 'Authorization: Bearer secret-token:super_secret'",
"""
--data '{
"auth": { "method": "external" },
"id": "default",
"name": "default",
"user_type": "business",
"address": {},
"jurisdiction": {},
"use_stefan": true,
"default_wire_transfer_delay": { "d_us": 3600000000 },
"default_pay_delay": { "d_us": 3600000000 }
}'
""",
"-sSfL 'http://merchant:8083/management/instances'"
])
# Register bank account address
succeed(merchant, [
"curl -X POST",
"-H 'Content-Type: application/json'",
"""
--data '{
"payto_uri": "payto://x-taler-bank/bank:8082/merchant?receiver-name=Merchant",
"credit_facade_url": "http://bank:8082/accounts/merchant/taler-revenue/",
"credit_facade_credentials":{"type":"basic","username":"merchant","password":"merchant"}
}'
""",
"-sSfL 'http://merchant:8083/private/accounts'"
])
# Register a new product to be ordered
succeed(merchant, [
"curl -X POST",
"-H 'Content-Type: application/json'",
"""
--data '{
"product_id": "1",
"description": "Product with id 1 and price 1",
"price": "${CURRENCY}:1",
"total_stock": 20,
"unit": "packages",
"next_restock": { "t_s": "never" }
}'
""",
"-sSfL 'http://merchant:8083/private/products'"
])
client.succeed("curl -s http://exchange:8081/")
# Make a withdrawal from the CLI wallet
with subtest("Make a withdrawal from the CLI wallet"):
balanceWanted = "${CURRENCY}:10"
# Register exchange
with subtest("Register exchange"):
wallet_cli("exchanges add http://exchange:8081/")
wallet_cli("exchanges accept-tos http://exchange:8081/")
# Request withdrawal from the bank
withdrawal = json.loads(
succeed(client, [
"curl -X POST",
"-u ${TUSER}:${TPASS}",
"-H 'Content-Type: application/json'",
f"""--data '{{"amount": "{balanceWanted}"}}'""", # double brackets escapes them
"-sSfL 'http://bank:8082/accounts/${TUSER}/withdrawals'"
])
)
# Accept & confirm withdrawal
with subtest("Accept & confirm withdrawal"):
wallet_cli(f"withdraw accept-uri {withdrawal["taler_withdraw_uri"]} --exchange http://exchange:8081/")
succeed(client, [
"curl -X POST",
"-u ${TUSER}:${TPASS}",
"-H 'Content-Type: application/json'",
f"-sSfL 'http://bank:8082/accounts/${TUSER}/withdrawals/{withdrawal["withdrawal_id"]}/confirm'"
])
# Process transactions
wallet_cli("run-until-done")
verify_balance(balanceWanted)
with subtest("Pay for an order"):
balanceWanted = "${CURRENCY}:9" # after paying
# Create an order to be paid
response = json.loads(
succeed(merchant, [
"curl -X POST",
"-H 'Content-Type: application/json'",
"""
--data '{
"order": { "amount": "${CURRENCY}:1", "summary": "Test Order" },
"inventory_products": [{ "product_id": "1", "quantity": 1 }]
}'
""",
"-sSfL 'http://merchant:8083/private/orders'"
])
)
order_id = response["order_id"]
token = response["token"]
# Get order pay URI
response = json.loads(
succeed(merchant, [
"curl -sSfL",
f"http://merchant:8083/private/orders/{order_id}"
])
)
wallet_cli("run-until-done")
# Process transaction
wallet_cli(f"""handle-uri -y '{response["taler_pay_uri"]}'""")
wallet_cli("run-until-done")
verify_balance(balanceWanted)
# Only run Nexus conversion test if ebics server is available
(status, out) = bank.execute('curl -sSfL "${nexusSettings.nexus-ebics.HOST_BASE_URL}"')
if status != 0:
bank.log("Can't connect to ebics server. Skipping Nexus conversion subtest.")
else:
with subtest("Libeufin Nexus currency conversion"):
regionalWanted = "20"
# Setup Nexus ebics keys
systemd_run(bank, "libeufin-nexus ebics-setup -L debug -c /etc/libeufin/libeufin.conf", "libeufin-nexus")
# Set currency conversion rates (1:1)
succeed(bank, [
"curl -X POST",
"-H 'Content-Type: application/json'",
"-u ${AUSER}:${APASS}",
"""
--data '{
"cashin_ratio": "1",
"cashin_fee": "${CURRENCY}:0",
"cashin_tiny_amount": "${CURRENCY}:0.01",
"cashin_rounding_mode": "nearest",
"cashin_min_amount": "${FIAT_CURRENCY}:1",
"cashout_ratio": "1",
"cashout_fee": "${FIAT_CURRENCY}:0",
"cashout_tiny_amount": "${FIAT_CURRENCY}:0.01",
"cashout_rounding_mode": "nearest",
"cashout_min_amount": "${CURRENCY}:1"
}'
""",
"-sSfL 'http://bank:8082/conversion-info/conversion-rate'"
])
# Make fake transaction (we only need reservePub)
response = wallet_cli("""api 'acceptManualWithdrawal' '{ "exchangeBaseUrl":"http://exchange:8081/", "amount":"${CURRENCY}:5" }'""")
reservePub = json.loads(response)["result"]["reservePub"]
# Convert fiat currency to regional
systemd_run(bank, f"""libeufin-nexus testing fake-incoming -c ${bankConfig} --amount="${FIAT_CURRENCY}:{regionalWanted}" --subject="{reservePub}" "payto://iban/CH4740123RW4167362694" """, "libeufin-nexus")
wallet_cli("run-until-done")
verify_conversion(regionalWanted)
'';
}
)