aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-wallet-cli
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2021-01-18 23:35:41 +0100
committerFlorian Dold <florian@dold.me>2021-01-18 23:35:41 +0100
commit5f3c02d31a223add55a32b20f4a289210cbb4f15 (patch)
treed91ded55692aea1294c0565328515f120559ab6a /packages/taler-wallet-cli
parentf884193b1adf0861f710c6ab1bb94ea2073ade65 (diff)
implement deposits
Diffstat (limited to 'packages/taler-wallet-cli')
-rw-r--r--packages/taler-wallet-cli/src/index.ts31
-rw-r--r--packages/taler-wallet-cli/src/integrationtests/harness.ts43
-rw-r--r--packages/taler-wallet-cli/src/integrationtests/test-deposit.ts65
-rw-r--r--packages/taler-wallet-cli/src/integrationtests/test-revocation.ts5
-rw-r--r--packages/taler-wallet-cli/src/integrationtests/testrunner.ts2
5 files changed, 127 insertions, 19 deletions
diff --git a/packages/taler-wallet-cli/src/index.ts b/packages/taler-wallet-cli/src/index.ts
index e4f1ccb50..7f32b8446 100644
--- a/packages/taler-wallet-cli/src/index.ts
+++ b/packages/taler-wallet-cli/src/index.ts
@@ -503,6 +503,37 @@ backupCli
});
});
+const depositCli = walletCli.subcommand("depositArgs", "deposit", {
+ help: "Subcommands for depositing money to payto:// accounts",
+});
+
+depositCli
+ .subcommand("createDepositArgs", "create")
+ .requiredArgument("amount", clk.STRING)
+ .requiredArgument("targetPayto", clk.STRING)
+ .action(async (args) => {
+ await withWallet(args, async (wallet) => {
+ const resp = await wallet.createDepositGroup({
+ amount: args.createDepositArgs.amount,
+ depositPaytoUri: args.createDepositArgs.targetPayto,
+ });
+ console.log(`Created deposit ${resp.depositGroupId}`);
+ await wallet.runPending();
+ });
+ });
+
+depositCli
+ .subcommand("trackDepositArgs", "track")
+ .requiredArgument("depositGroupId", clk.STRING)
+ .action(async (args) => {
+ await withWallet(args, async (wallet) => {
+ const resp = await wallet.trackDepositGroup({
+ depositGroupId: args.trackDepositArgs.depositGroupId,
+ });
+ console.log(JSON.stringify(resp, undefined, 2));
+ });
+ });
+
const advancedCli = walletCli.subcommand("advancedArgs", "advanced", {
help:
"Subcommands for advanced operations (only use if you know what you're doing!).",
diff --git a/packages/taler-wallet-cli/src/integrationtests/harness.ts b/packages/taler-wallet-cli/src/integrationtests/harness.ts
index b6b82213d..eb14b32b9 100644
--- a/packages/taler-wallet-cli/src/integrationtests/harness.ts
+++ b/packages/taler-wallet-cli/src/integrationtests/harness.ts
@@ -78,6 +78,10 @@ import {
AbortPayWithRefundRequest,
openPromise,
parsePaytoUri,
+ CreateDepositGroupRequest,
+ CreateDepositGroupResponse,
+ TrackDepositGroupRequest,
+ TrackDepositGroupResponse,
} from "taler-wallet-core";
import { URL } from "url";
import axios, { AxiosError } from "axios";
@@ -873,6 +877,9 @@ export class ExchangeService implements ExchangeServiceInterface {
config.setString("exchangedb-postgres", "config", e.database);
+ config.setString("taler-exchange-secmod-eddsa", "lookahead_sign", "20 s");
+ config.setString("taler-exchange-secmod-rsa", "lookahead_sign", "20 s");
+
const exchangeMasterKey = createEddsaKeyPair();
config.setString(
@@ -1017,13 +1024,7 @@ export class ExchangeService implements ExchangeServiceInterface {
this.globalState,
"exchange-offline",
"taler-exchange-offline",
- [
- "-c",
- this.configFilename,
- "download",
- "sign",
- "upload",
- ],
+ ["-c", this.configFilename, "download", "sign", "upload"],
);
const accounts: string[] = [];
@@ -1049,13 +1050,7 @@ export class ExchangeService implements ExchangeServiceInterface {
this.globalState,
"exchange-offline",
"taler-exchange-offline",
- [
- "-c",
- this.configFilename,
- "enable-account",
- acc,
- "upload",
- ],
+ ["-c", this.configFilename, "enable-account", acc, "upload"],
);
}
@@ -1615,6 +1610,16 @@ export class WalletCli {
throw new OperationFailedError(resp.error);
}
+ async createDepositGroup(
+ req: CreateDepositGroupRequest,
+ ): Promise<CreateDepositGroupResponse> {
+ const resp = await this.apiRequest("createDepositGroup", req);
+ if (resp.type === "response") {
+ return resp.result as CreateDepositGroupResponse;
+ }
+ throw new OperationFailedError(resp.error);
+ }
+
async abortFailedPayWithRefund(
req: AbortPayWithRefundRequest,
): Promise<void> {
@@ -1714,6 +1719,16 @@ export class WalletCli {
throw new OperationFailedError(resp.error);
}
+ async trackDepositGroup(
+ req: TrackDepositGroupRequest,
+ ): Promise<TrackDepositGroupResponse> {
+ const resp = await this.apiRequest("trackDepositGroup", req);
+ if (resp.type === "response") {
+ return resp.result as TrackDepositGroupResponse;
+ }
+ throw new OperationFailedError(resp.error);
+ }
+
async runIntegrationTest(args: IntegrationTestArgs): Promise<void> {
const resp = await this.apiRequest("runIntegrationTest", args);
if (resp.type === "response") {
diff --git a/packages/taler-wallet-cli/src/integrationtests/test-deposit.ts b/packages/taler-wallet-cli/src/integrationtests/test-deposit.ts
new file mode 100644
index 000000000..3e59a6cce
--- /dev/null
+++ b/packages/taler-wallet-cli/src/integrationtests/test-deposit.ts
@@ -0,0 +1,65 @@
+/*
+ This file is part of GNU Taler
+ (C) 2020 Taler Systems S.A.
+
+ GNU Taler is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+
+/**
+ * Imports.
+ */
+import { GlobalTestState } from "./harness";
+import {
+ createSimpleTestkudosEnvironment,
+ withdrawViaBank,
+} from "./helpers";
+
+/**
+ * Run test for basic, bank-integrated withdrawal and payment.
+ */
+export async function runDepositTest(t: GlobalTestState) {
+ // Set up test environment
+
+ const {
+ wallet,
+ bank,
+ exchange,
+ merchant,
+ } = await createSimpleTestkudosEnvironment(t);
+
+ // Withdraw digital cash into the wallet.
+
+ await withdrawViaBank(t, { wallet, bank, exchange, amount: "TESTKUDOS:20" });
+
+ await wallet.runUntilDone();
+
+ const { depositGroupId } = await wallet.createDepositGroup({
+ amount: "TESTKUDOS:10",
+ depositPaytoUri: "payto://x-taler-bank/localhost/foo",
+ });
+
+ await wallet.runUntilDone();
+
+ const transactions = await wallet.getTransactions();
+ console.log("transactions", JSON.stringify(transactions, undefined, 2));
+ t.assertDeepEqual(transactions.transactions[0].type, "withdrawal");
+ t.assertDeepEqual(transactions.transactions[1].type, "deposit");
+ // The raw amount is what ends up on the bank account, which includes
+ // deposit and wire fees.
+ t.assertDeepEqual(transactions.transactions[1].amountRaw, "TESTKUDOS:9.79");
+
+ const trackResult = wallet.trackDepositGroup({
+ depositGroupId,
+ })
+
+ console.log(JSON.stringify(trackResult, undefined, 2));
+}
diff --git a/packages/taler-wallet-cli/src/integrationtests/test-revocation.ts b/packages/taler-wallet-cli/src/integrationtests/test-revocation.ts
index 052045302..a77797314 100644
--- a/packages/taler-wallet-cli/src/integrationtests/test-revocation.ts
+++ b/packages/taler-wallet-cli/src/integrationtests/test-revocation.ts
@@ -82,11 +82,6 @@ async function createTestEnvironment(
database: db.connStr,
});
- exchange.changeConfig((config) => {
- config.setString("taler-exchange-secmod-eddsa", "lookahead_sign", "20 s");
- config.setString("taler-exchange-secmod-rsa", "lookahead_sign", "20 s");
- });
-
const exchangeBankAccount = await bank.createExchangeAccount(
"MyExchange",
"x",
diff --git a/packages/taler-wallet-cli/src/integrationtests/testrunner.ts b/packages/taler-wallet-cli/src/integrationtests/testrunner.ts
index 04e803b74..d20bf1895 100644
--- a/packages/taler-wallet-cli/src/integrationtests/testrunner.ts
+++ b/packages/taler-wallet-cli/src/integrationtests/testrunner.ts
@@ -49,6 +49,7 @@ import { runWithdrawalBankIntegratedTest } from "./test-withdrawal-bank-integrat
import M from "minimatch";
import { runMerchantExchangeConfusionTest } from "./test-merchant-exchange-confusion";
import { runLibeufinBasicTest } from "./test-libeufin-basic";
+import { runDepositTest } from "./test-deposit";
/**
* Test runner.
@@ -64,6 +65,7 @@ interface TestMainFunction {
const allTests: TestMainFunction[] = [
runBankApiTest,
runClaimLoopTest,
+ runDepositTest,
runExchangeManagementTest,
runFeeRegressionTest,
runLibeufinBasicTest,