diff options
author | Florian Dold <florian.dold@gmail.com> | 2020-08-01 13:52:08 +0530 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2020-08-01 13:52:46 +0530 |
commit | aa481e42675fb7c4dcbbeec0ba1c61e1953b9596 (patch) | |
tree | b1283f27713b9ff8619773a96b775a263e4aea18 /src/headless/taler-wallet-cli.ts | |
parent | b37c98346d407c749a5cd971f798428c42b248c3 (diff) |
use wallet's http lib for test balance withdrawal, remove redundant integration tests
Diffstat (limited to 'src/headless/taler-wallet-cli.ts')
-rw-r--r-- | src/headless/taler-wallet-cli.ts | 286 |
1 files changed, 1 insertions, 285 deletions
diff --git a/src/headless/taler-wallet-cli.ts b/src/headless/taler-wallet-cli.ts index ba629537e..a7f306ec3 100644 --- a/src/headless/taler-wallet-cli.ts +++ b/src/headless/taler-wallet-cli.ts @@ -16,9 +16,7 @@ import os from "os"; import fs from "fs"; -import { getDefaultNodeWallet, withdrawTestBalance } from "./helpers"; -import { MerchantBackendConnection } from "./merchant"; -import { runIntegrationTest, runIntegrationTestBasic } from "./integrationtest"; +import { getDefaultNodeWallet } from "./helpers"; import { Wallet } from "../wallet"; import qrcodeGenerator from "qrcode-generator"; import * as clk from "./clk"; @@ -34,7 +32,6 @@ import { OperationFailedAndReportedError, OperationFailedError, } from "../operations/errors"; -import { Bank } from "./bank"; import { classifyTalerUri, TalerUriType } from "../util/taleruri"; import { Configuration } from "../util/talerconfig"; import { setDangerousTimetravel } from "../util/time"; @@ -658,285 +655,4 @@ testCli.subcommand("vectors", "vectors").action(async (args) => { console.log(` (out) coin pub: ${encodeCrock(p.coinPub)}`); }); -testCli - .subcommand("integrationtestBasic", "integrationtest-basic") - .requiredArgument("cfgfile", clk.STRING) - .action(async (args) => { - const cfgStr = fs.readFileSync(args.integrationtestBasic.cfgfile, "utf8"); - const cfg = new Configuration(); - cfg.loadFromString(cfgStr); - try { - await runIntegrationTestBasic(cfg); - } catch (e) { - console.log("integration test failed"); - console.log(e); - process.exit(1); - } - process.exit(0); - }); - -testCli - .subcommand("testPayCmd", "test-pay", { help: "Create contract and pay." }) - .requiredOption("merchant", ["-m", "--mechant-url"], clk.STRING) - .requiredOption("apikey", ["-k", "--mechant-api-key"], clk.STRING) - .requiredOption("amount", ["-a", "--amount"], clk.STRING) - .requiredOption("summary", ["-s", "--summary"], clk.STRING, { - default: "Test Payment", - }) - .action(async (args) => { - const cmdArgs = args.testPayCmd; - console.log("creating order"); - const merchantBackend = new MerchantBackendConnection( - args.testPayCmd.merchant, - args.testPayCmd.apikey, - ); - const orderResp = await merchantBackend.createOrder( - cmdArgs.amount, - cmdArgs.summary, - "", - ); - console.log("created new order with order ID", orderResp.orderId); - const checkPayResp = await merchantBackend.checkPayment(orderResp.orderId); - const talerPayUri = checkPayResp.taler_pay_uri; - if (!talerPayUri) { - console.error("fatal: no taler pay URI received from backend"); - process.exit(1); - return; - } - console.log("taler pay URI:", talerPayUri); - await withWallet(args, async (wallet) => { - await doPay(wallet, talerPayUri, { alwaysYes: true }); - }); - }); - -testCli - .subcommand("integrationtestCmd", "integrationtest", { - help: "Run integration test with bank, exchange and merchant.", - }) - .requiredOption("exchange", ["-e", "--exchange"], clk.STRING, { - default: "https://exchange.test.taler.net/", - }) - .requiredOption("merchant", ["-m", "--merchant"], clk.STRING, { - default: "https://backend.test.taler.net/", - }) - .requiredOption("merchantApiKey", ["-k", "--merchant-api-key"], clk.STRING, { - default: "sandbox", - }) - .requiredOption("bank", ["-b", "--bank"], clk.STRING, { - default: "https://bank.test.taler.net/", - }) - .requiredOption("withdrawAmount", ["-w", "--amount"], clk.STRING, { - default: "TESTKUDOS:10", - }) - .requiredOption("spendAmount", ["-s", "--spend-amount"], clk.STRING, { - default: "TESTKUDOS:4", - }) - .action(async (args) => { - applyVerbose(args.wallet.verbose); - const cmdObj = args.integrationtestCmd; - - try { - await runIntegrationTest({ - amountToSpend: cmdObj.spendAmount, - amountToWithdraw: cmdObj.withdrawAmount, - bankBaseUrl: cmdObj.bank, - exchangeBaseUrl: cmdObj.exchange, - merchantApiKey: cmdObj.merchantApiKey, - merchantBaseUrl: cmdObj.merchant, - }).catch((err) => { - console.error("Integration test failed with exception:"); - console.error(err); - process.exit(1); - }); - process.exit(0); - } catch (e) { - console.error(e); - process.exit(1); - } - }); - -testCli - .subcommand("genTipUri", "gen-tip-uri", { - help: "Generate a taler://tip URI.", - }) - .requiredOption("amount", ["-a", "--amount"], clk.STRING, { - default: "TESTKUDOS:10", - }) - .maybeOption("merchant", ["-m", "--merchant"], clk.STRING, { - default: "https://backend.test.taler.net/", - }) - .maybeOption("merchantApiKey", ["-k", "--merchant-api-key"], clk.STRING, { - default: "sandbox", - }) - .action(async (args) => { - const merchantBackend = new MerchantBackendConnection( - args.genTipUri.merchant ?? "https://backend.test.taler.net/", - args.genTipUri.merchantApiKey ?? "sandbox", - ); - const tipUri = await merchantBackend.authorizeTip( - args.genTipUri.amount, - "test", - ); - console.log(tipUri); - }); - -testCli - .subcommand("genWithdrawUri", "gen-withdraw-uri", { - help: "Generate a taler://withdraw URI.", - }) - .requiredOption("amount", ["-a", "--amount"], clk.STRING, { - default: "TESTKUDOS:20", - }) - .requiredOption("bank", ["-b", "--bank"], clk.STRING, { - default: "https://bank.test.taler.net/", - }) - .action(async (args) => { - const b = new Bank(args.genWithdrawUri.bank); - const user = await b.registerRandomUser(); - const url = await b.generateWithdrawUri(user, args.genWithdrawUri.amount); - console.log(url); - }); - -testCli - .subcommand("genRefundUri", "gen-refund-uri", { - help: "Generate a taler://refund URI.", - }) - .requiredOption("amount", ["-a", "--amount"], clk.STRING, { - default: "TESTKUDOS:5", - }) - .requiredOption("refundAmount", ["-r", "--refund"], clk.STRING, { - default: "TESTKUDOS:3", - }) - .requiredOption("summary", ["-s", "--summary"], clk.STRING, { - default: "Test Payment (for refund)", - }) - .maybeOption("merchant", ["-m", "--merchant"], clk.STRING, { - default: "https://backend.test.taler.net/", - }) - .maybeOption("merchantApiKey", ["-k", "--merchant-api-key"], clk.STRING, { - default: "sandbox", - }) - .action(async (args) => { - const cmdArgs = args.genRefundUri; - const merchantBackend = new MerchantBackendConnection( - cmdArgs.merchant ?? "https://backend.test.taler.net/", - cmdArgs.merchantApiKey ?? "sandbox", - ); - const orderResp = await merchantBackend.createOrder( - cmdArgs.amount, - cmdArgs.summary, - "", - ); - console.log("created new order with order ID", orderResp.orderId); - const checkPayResp = await merchantBackend.checkPayment(orderResp.orderId); - const talerPayUri = checkPayResp.taler_pay_uri; - if (!talerPayUri) { - console.error("fatal: no taler pay URI received from backend"); - process.exit(1); - return; - } - await withWallet(args, async (wallet) => { - await doPay(wallet, talerPayUri, { alwaysYes: true }); - }); - const refundUri = await merchantBackend.refund( - orderResp.orderId, - "test refund", - cmdArgs.refundAmount, - ); - console.log(refundUri); - }); - -testCli - .subcommand("genPayUri", "gen-pay-uri", { - help: "Generate a taler://pay URI.", - }) - .flag("qrcode", ["--qr"], { - help: "Show a QR code with the taler://pay URI", - }) - .flag("wait", ["--wait"], { - help: "Wait until payment has completed", - }) - .requiredOption("amount", ["-a", "--amount"], clk.STRING, { - default: "TESTKUDOS:1", - }) - .requiredOption("summary", ["-s", "--summary"], clk.STRING, { - default: "Test Payment", - }) - .requiredOption("merchant", ["-m", "--merchant"], clk.STRING, { - default: "https://backend.test.taler.net/", - }) - .requiredOption("merchantApiKey", ["-k", "--merchant-api-key"], clk.STRING, { - default: "sandbox", - }) - .action(async (args) => { - const cmdArgs = args.genPayUri; - console.log("creating order"); - const merchantBackend = new MerchantBackendConnection( - cmdArgs.merchant, - cmdArgs.merchantApiKey, - ); - const orderResp = await merchantBackend.createOrder( - cmdArgs.amount, - cmdArgs.summary, - "", - ); - console.log("created new order with order ID", orderResp.orderId); - const checkPayResp = await merchantBackend.checkPayment(orderResp.orderId); - const talerPayUri = checkPayResp.taler_pay_uri; - if (!talerPayUri) { - console.error("fatal: no taler pay URI received from backend"); - process.exit(1); - return; - } - console.log("taler pay URI:", talerPayUri); - if (cmdArgs.qrcode) { - const qrcode = qrcodeGenerator(0, "M"); - qrcode.addData(talerPayUri); - qrcode.make(); - console.log(qrcode.createASCII()); - } - if (cmdArgs.wait) { - console.log("waiting for payment ..."); - while (1) { - await asyncSleep(500); - const checkPayResp2 = await merchantBackend.checkPayment( - orderResp.orderId, - ); - if (checkPayResp2.order_status === "paid") { - console.log("payment successfully received!"); - break; - } - } - } - }); - -testCli - .subcommand("withdrawArgs", "withdraw", { - help: "Withdraw from a test bank (must support test registrations).", - }) - .requiredOption("amount", ["-a", "--amount"], clk.STRING, { - default: "TESTKUDOS:10", - help: "Amount to withdraw.", - }) - .requiredOption("exchange", ["-e", "--exchange"], clk.STRING, { - default: "https://exchange.test.taler.net/", - help: "Exchange base URL.", - }) - .requiredOption("bank", ["-b", "--bank"], clk.STRING, { - default: "https://bank.test.taler.net/", - help: "Bank base URL", - }) - .action(async (args) => { - await withWallet(args, async (wallet) => { - await wallet.updateExchangeFromUrl(args.withdrawArgs.exchange, true); - await withdrawTestBalance( - wallet, - args.withdrawArgs.amount, - args.withdrawArgs.bank, - args.withdrawArgs.exchange, - ); - logger.info("Withdraw done"); - }); - }); - walletCli.run(); |