config files WIP

This commit is contained in:
Florian Dold 2020-03-23 17:00:01 +05:30
parent b6d081b6c7
commit eabbbd339b
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
4 changed files with 179 additions and 5 deletions

View File

@ -0,0 +1,10 @@
[integrationtest]
walletdb = testwalletdb.json
bank_base_url = https://bank.test.taler.net/
exchange_base_url = https://exchange.test.taler.net/
merchant_base_url = https://backend.test.taler.net/
merchant_api_key = sandbox
[integrationtest-basic]
amount_withdraw = TESTKUDOS:10
amount_spend = TESTKUDOS:5

View File

@ -24,6 +24,7 @@ import { Logger } from "../util/logging";
import { NodeHttpLib } from "./NodeHttpLib"; import { NodeHttpLib } from "./NodeHttpLib";
import * as Amounts from "../util/amounts"; import * as Amounts from "../util/amounts";
import { Wallet } from "../wallet"; import { Wallet } from "../wallet";
import { Configuration } from "../util/talerconfig";
const logger = new Logger("integrationtest.ts"); const logger = new Logger("integrationtest.ts");
@ -189,5 +190,143 @@ export async function runIntegrationTest(args: IntegrationTestArgs) {
const history = await myWallet.getHistory({ verboseDetails: true }); const history = await myWallet.getHistory({ verboseDetails: true });
console.log("history after integration test:", JSON.stringify(history, undefined, 2)); console.log(
"history after integration test:",
JSON.stringify(history, undefined, 2),
);
}
export async function runIntegrationTestBasic(cfg: Configuration) {
const walletDbPath = cfg.getString("integrationtest", "walletdb").required();
const bankBaseUrl = cfg
.getString("integrationtest", "bank_base_url")
.required();
const exchangeBaseUrl = cfg
.getString("integrationtest", "exchange_base_url")
.required();
const merchantBaseUrl = cfg
.getString("integrationtest", "merchant_base_url")
.required();
const merchantApiKey = cfg
.getString("integrationtest", "merchant_api_key")
.required();
const parsedWithdrawAmount = cfg
.getAmount("integrationtest-basic", "amount_withdraw")
.required();
const parsedSpendAmount = cfg
.getAmount("integrationtest-basic", "amount_spend")
.required();
const currency = parsedSpendAmount.currency;
const myHttpLib = new NodeHttpLib();
myHttpLib.setThrottling(false);
const myWallet = await getDefaultNodeWallet({
httpLib: myHttpLib,
persistentStoragePath: walletDbPath,
});
myWallet.runRetryLoop().catch(e => {
console.error("exception during retry loop:", e);
});
logger.info("withdrawing test balance");
await withdrawTestBalance(
myWallet,
Amounts.toString(parsedWithdrawAmount),
bankBaseUrl,
exchangeBaseUrl,
);
logger.info("done withdrawing test balance");
const balance = await myWallet.getBalances();
console.log(JSON.stringify(balance, null, 2));
const myMerchant = new MerchantBackendConnection(
merchantBaseUrl,
merchantApiKey,
);
await makePayment(myWallet, myMerchant, Amounts.toString(parsedSpendAmount), "hello world");
// Wait until the refresh is done
await myWallet.runUntilDone();
console.log("withdrawing test balance for refund");
const withdrawAmountTwo: Amounts.AmountJson = {
currency,
value: 18,
fraction: 0,
};
const spendAmountTwo: Amounts.AmountJson = {
currency,
value: 7,
fraction: 0,
};
const refundAmount: Amounts.AmountJson = {
currency,
value: 6,
fraction: 0,
};
const spendAmountThree: Amounts.AmountJson = {
currency,
value: 3,
fraction: 0,
};
await withdrawTestBalance(
myWallet,
Amounts.toString(withdrawAmountTwo),
bankBaseUrl,
exchangeBaseUrl,
);
// Wait until the withdraw is done
await myWallet.runUntilDone();
let { orderId: refundOrderId } = await makePayment(
myWallet,
myMerchant,
Amounts.toString(spendAmountTwo),
"order that will be refunded",
);
const refundUri = await myMerchant.refund(
refundOrderId,
"test refund",
Amounts.toString(refundAmount),
);
console.log("refund URI", refundUri);
await myWallet.applyRefund(refundUri);
// Wait until the refund is done
await myWallet.runUntilDone();
await makePayment(
myWallet,
myMerchant,
Amounts.toString(spendAmountThree),
"payment after refund",
);
await myWallet.runUntilDone();
const history = await myWallet.getHistory({ verboseDetails: true });
console.log(
"history after integration test:",
JSON.stringify(history, undefined, 2),
);
} }

View File

@ -18,7 +18,7 @@ import os = require("os");
import fs = require("fs"); import fs = require("fs");
import { getDefaultNodeWallet, withdrawTestBalance } from "./helpers"; import { getDefaultNodeWallet, withdrawTestBalance } from "./helpers";
import { MerchantBackendConnection } from "./merchant"; import { MerchantBackendConnection } from "./merchant";
import { runIntegrationTest } from "./integrationtest"; import { runIntegrationTest, runIntegrationTestBasic } from "./integrationtest";
import { Wallet } from "../wallet"; import { Wallet } from "../wallet";
import qrcodeGenerator = require("qrcode-generator"); import qrcodeGenerator = require("qrcode-generator");
import * as clk from "./clk"; import * as clk from "./clk";
@ -30,6 +30,7 @@ import { OperationFailedAndReportedError } from "../operations/errors";
import { Bank } from "./bank"; import { Bank } from "./bank";
import { classifyTalerUri, TalerUriType } from "../util/taleruri"; import { classifyTalerUri, TalerUriType } from "../util/taleruri";
import util = require("util"); import util = require("util");
import { Configuration } from "../util/talerconfig";
// Backwards compatibility with nodejs<0.11, where TextEncoder and TextDecoder // Backwards compatibility with nodejs<0.11, where TextEncoder and TextDecoder
// are not globals yet. // are not globals yet.
@ -38,7 +39,7 @@ import util = require("util");
const logger = new Logger("taler-wallet-cli.ts"); const logger = new Logger("taler-wallet-cli.ts");
const walletDbPath = os.homedir + "/" + ".talerwalletdb.json"; const defaultWalletDbPath = os.homedir + "/" + ".talerwalletdb.json";
function assertUnreachable(x: never): never { function assertUnreachable(x: never): never {
throw new Error("Didn't expect to get here"); throw new Error("Didn't expect to get here");
@ -115,6 +116,9 @@ const walletCli = clk
.program("wallet", { .program("wallet", {
help: "Command line interface for the GNU Taler wallet.", help: "Command line interface for the GNU Taler wallet.",
}) })
.maybeOption("walletDbFile", ["--wallet-db"], clk.STRING, {
help: "location of the wallet database file"
})
.maybeOption("inhibit", ["--inhibit"], clk.STRING, { .maybeOption("inhibit", ["--inhibit"], clk.STRING, {
help: help:
"Inhibit running certain operations, useful for debugging and testing.", "Inhibit running certain operations, useful for debugging and testing.",
@ -132,8 +136,9 @@ async function withWallet<T>(
walletCliArgs: WalletCliArgsType, walletCliArgs: WalletCliArgsType,
f: (w: Wallet) => Promise<T>, f: (w: Wallet) => Promise<T>,
): Promise<T> { ): Promise<T> {
const dbPath = walletCliArgs.wallet.walletDbFile ?? defaultWalletDbPath;
const wallet = await getDefaultNodeWallet({ const wallet = await getDefaultNodeWallet({
persistentStoragePath: walletDbPath, persistentStoragePath: dbPath,
}); });
applyVerbose(walletCliArgs.wallet.verbose); applyVerbose(walletCliArgs.wallet.verbose);
try { try {
@ -189,7 +194,9 @@ walletCli
} else { } else {
for (const h of history.history) { for (const h of history.history) {
console.log( console.log(
`event at ${new Date(h.timestamp.t_ms).toISOString()} with type ${h.type}:`, `event at ${new Date(h.timestamp.t_ms).toISOString()} with type ${
h.type
}:`,
); );
console.log(JSON.stringify(h, undefined, 2)); console.log(JSON.stringify(h, undefined, 2));
console.log(); console.log();
@ -402,6 +409,23 @@ const testCli = walletCli.subcommand("testingArgs", "testing", {
help: "Subcommands for testing GNU Taler deployments.", help: "Subcommands for testing GNU Taler deployments.",
}); });
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 testCli
.subcommand("testPayCmd", "test-pay", { help: "create contract and pay" }) .subcommand("testPayCmd", "test-pay", { help: "create contract and pay" })
.requiredOption("amount", ["-a", "--amount"], clk.STRING) .requiredOption("amount", ["-a", "--amount"], clk.STRING)

View File

@ -86,6 +86,7 @@
"src/util/payto.ts", "src/util/payto.ts",
"src/util/promiseUtils.ts", "src/util/promiseUtils.ts",
"src/util/query.ts", "src/util/query.ts",
"src/util/talerconfig.ts",
"src/util/taleruri-test.ts", "src/util/taleruri-test.ts",
"src/util/taleruri.ts", "src/util/taleruri.ts",
"src/util/time.ts", "src/util/time.ts",