mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-06-12 20:55:31 +03:00

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
107 lines
3.8 KiB
Nix
107 lines
3.8 KiB
Nix
{
|
|
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}"')
|
|
'';
|
|
}
|