From e35c2f581b49f6441b6f75bb9ce0a1677d5fb46f Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Tue, 22 Jun 2021 13:52:28 +0200 Subject: simplify task loop, test coin suspension --- packages/taler-wallet-cli/src/index.ts | 8 +-- .../src/integrationtests/test-wallettesting.ts | 64 +++++++++++++++++++++- 2 files changed, 63 insertions(+), 9 deletions(-) (limited to 'packages/taler-wallet-cli') diff --git a/packages/taler-wallet-cli/src/index.ts b/packages/taler-wallet-cli/src/index.ts index d4e5bbe46..2fac85a7e 100644 --- a/packages/taler-wallet-cli/src/index.ts +++ b/packages/taler-wallet-cli/src/index.ts @@ -33,7 +33,6 @@ import { codecForList, codecForString, Logger, - WithdrawalType, } from "@gnu-taler/taler-util"; import { NodeHttpLib, @@ -45,10 +44,6 @@ import { NodeThreadCryptoWorkerFactory, CryptoApi, walletCoreDebugFlags, - handleCoreApiRequest, - runPending, - runUntilDone, - getClientFromWalletState, WalletApiOperation, WalletCoreApiClient, Wallet, @@ -314,8 +309,9 @@ walletCli .maybeOption("maxRetries", ["--max-retries"], clk.INT) .action(async (args) => { await withWallet(args, async (wallet) => { - await wallet.ws.runUntilDone({ + await wallet.ws.runTaskLoop({ maxRetries: args.finishPendingOpt.maxRetries, + stopWhenDone: true, }); wallet.ws.stop(); }); diff --git a/packages/taler-wallet-cli/src/integrationtests/test-wallettesting.ts b/packages/taler-wallet-cli/src/integrationtests/test-wallettesting.ts index 5fb017edd..2499e65a0 100644 --- a/packages/taler-wallet-cli/src/integrationtests/test-wallettesting.ts +++ b/packages/taler-wallet-cli/src/integrationtests/test-wallettesting.ts @@ -22,8 +22,9 @@ /** * Imports. */ +import { Amounts } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; -import { CoinConfig, defaultCoinConfig } from "./denomStructures"; +import { CoinConfig, defaultCoinConfig } from "./denomStructures.js"; import { BankService, ExchangeService, @@ -31,8 +32,8 @@ import { MerchantService, setupDb, WalletCli, -} from "./harness"; -import { SimpleTestEnvironment } from "./helpers"; +} from "./harness.js"; +import { SimpleTestEnvironment } from "./helpers.js"; const merchantAuthToken = "secret-token:sandbox"; @@ -162,6 +163,63 @@ export async function runWallettestingTest(t: GlobalTestState) { t.assertDeepEqual(txTypes, ["withdrawal", "payment"]); + wallet.deleteDatabase(); + + await wallet.client.call(WalletApiOperation.WithdrawTestBalance, { + amount: "TESTKUDOS:10", + bankBaseUrl: bank.baseUrl, + exchangeBaseUrl: exchange.baseUrl, + }); + + await wallet.runUntilDone(); + + const coinDump = await wallet.client.call(WalletApiOperation.DumpCoins, {}); + + console.log("coin dump:", JSON.stringify(coinDump, undefined, 2)); + + let susp: string | undefined; + { + for (const c of coinDump.coins) { + if (0 === Amounts.cmp(c.remaining_value, "TESTKUDOS:8")) { + susp = c.coin_pub; + } + } + } + + t.assertTrue(susp !== undefined); + + console.log("suspending coin"); + + await wallet.client.call(WalletApiOperation.SetCoinSuspended, { + coinPub: susp, + suspended: true, + }); + + // This should fail, as we've suspended a coin that we need + // to pay. + await t.assertThrowsAsync(async () => { + await wallet.client.call(WalletApiOperation.TestPay, { + amount: "TESTKUDOS:5", + merchantAuthToken: merchantAuthToken, + merchantBaseUrl: merchant.makeInstanceBaseUrl(), + summary: "foo", + }); + }); + + console.log("unsuspending coin"); + + await wallet.client.call(WalletApiOperation.SetCoinSuspended, { + coinPub: susp, + suspended: false, + }); + + await wallet.client.call(WalletApiOperation.TestPay, { + amount: "TESTKUDOS:5", + merchantAuthToken: merchantAuthToken, + merchantBaseUrl: merchant.makeInstanceBaseUrl(), + summary: "foo", + }); + await t.shutdown(); } -- cgit v1.2.3