From 1392dc47c6489fca1b3a4c036852873495190c36 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Wed, 10 Mar 2021 17:11:59 +0100 Subject: finish first complete end-to-end backup/sync test --- .../src/integrationtests/harness.ts | 18 +++++++ .../taler-wallet-cli/src/integrationtests/sync.ts | 3 +- .../integrationtests/test-wallet-backup-basic.ts | 60 ++++++++++++++++++++-- 3 files changed, 76 insertions(+), 5 deletions(-) (limited to 'packages/taler-wallet-cli/src/integrationtests') diff --git a/packages/taler-wallet-cli/src/integrationtests/harness.ts b/packages/taler-wallet-cli/src/integrationtests/harness.ts index 835eb7a08..31f9131a3 100644 --- a/packages/taler-wallet-cli/src/integrationtests/harness.ts +++ b/packages/taler-wallet-cli/src/integrationtests/harness.ts @@ -82,6 +82,7 @@ import { CreateDepositGroupResponse, TrackDepositGroupRequest, TrackDepositGroupResponse, + RecoveryLoadRequest, } from "@gnu-taler/taler-wallet-core"; import { URL } from "url"; import axios, { AxiosError } from "axios"; @@ -102,6 +103,7 @@ import { CoinConfig } from "./denomStructures"; import { AddBackupProviderRequest, BackupInfo, + BackupRecovery, } from "@gnu-taler/taler-wallet-core/src/operations/backup"; const exec = util.promisify(require("child_process").exec); @@ -1887,6 +1889,22 @@ export class WalletCli { throw new OperationFailedError(resp.error); } + async exportBackupRecovery(): Promise { + const resp = await this.apiRequest("exportBackupRecovery", {}); + if (resp.type === "response") { + return resp.result as BackupRecovery; + } + throw new OperationFailedError(resp.error); + } + + async importBackupRecovery(req: RecoveryLoadRequest): Promise { + const resp = await this.apiRequest("importBackupRecovery", req); + if (resp.type === "response") { + return; + } + throw new OperationFailedError(resp.error); + } + async runBackupCycle(): Promise { const resp = await this.apiRequest("runBackupCycle", {}); if (resp.type === "response") { diff --git a/packages/taler-wallet-cli/src/integrationtests/sync.ts b/packages/taler-wallet-cli/src/integrationtests/sync.ts index 7aa4b2893..83024ec79 100644 --- a/packages/taler-wallet-cli/src/integrationtests/sync.ts +++ b/packages/taler-wallet-cli/src/integrationtests/sync.ts @@ -19,7 +19,6 @@ */ import axios from "axios"; import { Configuration, URL } from "@gnu-taler/taler-wallet-core"; -import { getRandomIban, getRandomString } from "./helpers"; import * as fs from "fs"; import * as util from "util"; import { @@ -87,6 +86,8 @@ export class SyncService { config.setString("sync", "port", `${sc.httpPort}`); config.setString("sync", "db", "postgres"); config.setString("syncdb-postgres", "config", sc.database); + config.setString("sync", "payment_backend_url", sc.paymentBackendUrl); + config.setString("sync", "upload_limit_mb", `${sc.uploadLimitMb}`); config.write(cfgFilename); return new SyncService(gc, sc, cfgFilename); diff --git a/packages/taler-wallet-cli/src/integrationtests/test-wallet-backup-basic.ts b/packages/taler-wallet-cli/src/integrationtests/test-wallet-backup-basic.ts index 9804f7ab2..2ed16fe19 100644 --- a/packages/taler-wallet-cli/src/integrationtests/test-wallet-backup-basic.ts +++ b/packages/taler-wallet-cli/src/integrationtests/test-wallet-backup-basic.ts @@ -17,9 +17,12 @@ /** * Imports. */ -import { GlobalTestState, BankApi, BankAccessApi } from "./harness"; -import { createSimpleTestkudosEnvironment } from "./helpers"; -import { codecForBalancesResponse } from "@gnu-taler/taler-wallet-core"; +import { GlobalTestState, BankApi, BankAccessApi, WalletCli } from "./harness"; +import { + createSimpleTestkudosEnvironment, + makeTestPayment, + withdrawViaBank, +} from "./helpers"; import { SyncService } from "./sync"; /** @@ -28,7 +31,13 @@ import { SyncService } from "./sync"; export async function runWalletBackupBasicTest(t: GlobalTestState) { // Set up test environment - const { commonDb, merchant, wallet, bank, exchange } = await createSimpleTestkudosEnvironment(t); + const { + commonDb, + merchant, + wallet, + bank, + exchange, + } = await createSimpleTestkudosEnvironment(t); const sync = await SyncService.create(t, { currency: "TESTKUDOS", @@ -69,5 +78,48 @@ export async function runWalletBackupBasicTest(t: GlobalTestState) { { const bi = await wallet.getBackupInfo(); console.log(bi); + t.assertDeepEqual( + bi.providers[0].paymentStatus.type, + "insufficient-balance", + ); + } + + await withdrawViaBank(t, { wallet, bank, exchange, amount: "TESTKUDOS:10" }); + + await wallet.runBackupCycle(); + + { + const bi = await wallet.getBackupInfo(); + console.log(bi); + } + + await withdrawViaBank(t, { wallet, bank, exchange, amount: "TESTKUDOS:5" }); + + await wallet.runBackupCycle(); + + { + const bi = await wallet.getBackupInfo(); + console.log(bi); + } + + const backupRecovery = await wallet.exportBackupRecovery(); + + const wallet2 = new WalletCli(t, "wallet2"); + + // Check that the second wallet is a fresh wallet. + { + const bal = await wallet2.getBalances(); + t.assertTrue(bal.balances.length === 0); + } + + await wallet2.importBackupRecovery({ recovery: backupRecovery }); + + await wallet2.runBackupCycle(); + + // Check that now the old balance is available! + { + const bal = await wallet2.getBalances(); + t.assertTrue(bal.balances.length === 1); + console.log(bal); } } -- cgit v1.2.3