wallet: fix withdrawal in timetravel test

This commit is contained in:
Florian Dold 2022-03-07 23:57:25 +01:00
parent 6df9202935
commit 3aa0b812f4
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
2 changed files with 39 additions and 35 deletions

View File

@ -23,36 +23,36 @@
/** /**
* Imports * Imports
*/ */
import {
AmountString,
ConfirmPayResultType,
ContractTerms,
Duration,
PreparePayResultType,
} from "@gnu-taler/taler-util";
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
import { CoinConfig, defaultCoinConfig } from "./denomStructures.js";
import { import {
FaultInjectedExchangeService, FaultInjectedExchangeService,
FaultInjectedMerchantService, FaultInjectedMerchantService,
} from "./faultInjection"; } from "./faultInjection.js";
import { CoinConfig, defaultCoinConfig } from "./denomStructures";
import { import {
AmountString,
Duration,
ContractTerms,
PreparePayResultType,
ConfirmPayResultType,
} from "@gnu-taler/taler-util";
import {
DbInfo,
BankService,
ExchangeService,
MerchantService,
WalletCli,
GlobalTestState,
setupDb,
ExchangeServiceInterface,
BankApi,
BankAccessApi, BankAccessApi,
MerchantServiceInterface, BankApi,
MerchantPrivateApi, BankService,
HarnessExchangeBankAccount, DbInfo,
WithAuthorization, ExchangeService,
ExchangeServiceInterface,
getPayto, getPayto,
GlobalTestState,
HarnessExchangeBankAccount,
MerchantPrivateApi,
MerchantService,
MerchantServiceInterface,
setupDb,
WalletCli,
WithAuthorization,
} from "./harness.js"; } from "./harness.js";
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
export interface SimpleTestEnvironment { export interface SimpleTestEnvironment {
commonDb: DbInfo; commonDb: DbInfo;
@ -242,7 +242,9 @@ export async function createFaultInjectedMerchantTestkudosEnvironment(
} }
/** /**
* Withdraw balance. * Start withdrawing into the wallet.
*
* Only starts the operation, does not wait for it to finish.
*/ */
export async function startWithdrawViaBank( export async function startWithdrawViaBank(
t: GlobalTestState, t: GlobalTestState,
@ -277,8 +279,8 @@ export async function startWithdrawViaBank(
await BankApi.confirmWithdrawalOperation(bank, user, wop); await BankApi.confirmWithdrawalOperation(bank, user, wop);
await wallet.runPending(); // We do *not* call runPending / runUntilDone on the wallet here.
await wallet.runUntilDone(); // Some tests rely on the final withdraw failing.
} }
/** /**

View File

@ -17,14 +17,14 @@
/** /**
* Imports. * Imports.
*/ */
import { Duration, TransactionType } from "@gnu-taler/taler-util";
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
import { GlobalTestState } from "../harness/harness.js"; import { GlobalTestState } from "../harness/harness.js";
import { import {
createSimpleTestkudosEnvironment, createSimpleTestkudosEnvironment,
withdrawViaBank,
startWithdrawViaBank, startWithdrawViaBank,
withdrawViaBank,
} from "../harness/helpers.js"; } from "../harness/helpers.js";
import { Duration, TransactionType } from "@gnu-taler/taler-util";
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
/** /**
* Basic time travel test. * Basic time travel test.
@ -32,12 +32,8 @@ import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
export async function runTimetravelWithdrawTest(t: GlobalTestState) { export async function runTimetravelWithdrawTest(t: GlobalTestState) {
// Set up test environment // Set up test environment
const { const { wallet, bank, exchange, merchant } =
wallet, await createSimpleTestkudosEnvironment(t);
bank,
exchange,
merchant,
} = await createSimpleTestkudosEnvironment(t);
// Withdraw digital cash into the wallet. // Withdraw digital cash into the wallet.
@ -61,6 +57,8 @@ export async function runTimetravelWithdrawTest(t: GlobalTestState) {
await merchant.start(); await merchant.start();
await merchant.pingUntilAvailable(); await merchant.pingUntilAvailable();
console.log("starting withdrawal via bank");
// This should fail, as the wallet didn't time travel yet. // This should fail, as the wallet didn't time travel yet.
await startWithdrawViaBank(t, { await startWithdrawViaBank(t, {
wallet, wallet,
@ -69,9 +67,13 @@ export async function runTimetravelWithdrawTest(t: GlobalTestState) {
amount: "TESTKUDOS:20", amount: "TESTKUDOS:20",
}); });
console.log("starting withdrawal done");
// Check that transactions are correct for the failed withdrawal // Check that transactions are correct for the failed withdrawal
{ {
console.log("running until done (should run into maxRetries limit)");
await wallet.runUntilDone({ maxRetries: 5 }); await wallet.runUntilDone({ maxRetries: 5 });
console.log("wallet done running");
const transactions = await wallet.client.call( const transactions = await wallet.client.call(
WalletApiOperation.GetTransactions, WalletApiOperation.GetTransactions,
{}, {},