use the new wallet core API interface in all tests

This commit is contained in:
Florian Dold 2021-06-17 13:34:59 +02:00
parent 0b4976601f
commit 5df7ddba97
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
35 changed files with 462 additions and 504 deletions

View File

@ -51,6 +51,8 @@ import {
getRandomBytes, getRandomBytes,
openPromise, openPromise,
OperationFailedError, OperationFailedError,
WalletApiOperation,
WalletCoreApiClient,
} from "@gnu-taler/taler-wallet-core"; } from "@gnu-taler/taler-wallet-core";
import { import {
AmountJson, AmountJson,
@ -1624,6 +1626,7 @@ function shellWrap(s: string) {
export class WalletCli { export class WalletCli {
private currentTimetravel: Duration | undefined; private currentTimetravel: Duration | undefined;
private _client: WalletCoreApiClient;
setTimetravel(d: Duration | undefined) { setTimetravel(d: Duration | undefined) {
this.currentTimetravel = d; this.currentTimetravel = d;
@ -1640,7 +1643,29 @@ export class WalletCli {
constructor( constructor(
private globalTestState: GlobalTestState, private globalTestState: GlobalTestState,
private name: string = "default", private name: string = "default",
) {} ) {
const self = this;
this._client = {
async call(op: any, payload: any): Promise<any> {
const resp = await sh(
self.globalTestState,
`wallet-${self.name}`,
`taler-wallet-cli ${
self.timetravelArg ?? ""
} --no-throttle --wallet-db '${self.dbfile}' api '${op}' ${shellWrap(
JSON.stringify(payload),
)}`,
);
console.log(resp);
const ar = JSON.parse(resp) as CoreApiResponse;
if (ar.type === "error") {
throw new OperationFailedError(ar.error);
} else {
return ar.result;
}
},
};
}
get dbfile(): string { get dbfile(): string {
return this.globalTestState.testDir + `/walletdb-${this.name}.json`; return this.globalTestState.testDir + `/walletdb-${this.name}.json`;
@ -1658,21 +1683,8 @@ export class WalletCli {
return []; return [];
} }
async apiRequest( get client(): WalletCoreApiClient {
request: string, return this._client;
payload: unknown,
): Promise<CoreApiResponse> {
const resp = await sh(
this.globalTestState,
`wallet-${this.name}`,
`taler-wallet-cli ${
this.timetravelArg ?? ""
} --no-throttle --wallet-db '${this.dbfile}' api '${request}' ${shellWrap(
JSON.stringify(payload),
)}`,
);
console.log(resp);
return JSON.parse(resp) as CoreApiResponse;
} }
async runUntilDone(args: { maxRetries?: number } = {}): Promise<void> { async runUntilDone(args: { maxRetries?: number } = {}): Promise<void> {
@ -1705,216 +1717,4 @@ export class WalletCli {
], ],
); );
} }
async applyRefund(req: ApplyRefundRequest): Promise<ApplyRefundResponse> {
const resp = await this.apiRequest("applyRefund", req);
if (resp.type === "response") {
return codecForApplyRefundResponse().decode(resp.result);
}
throw new OperationFailedError(resp.error);
}
async preparePay(req: PreparePayRequest): Promise<PreparePayResult> {
const resp = await this.apiRequest("preparePay", req);
if (resp.type === "response") {
return codecForPreparePayResult().decode(resp.result);
}
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> {
const resp = await this.apiRequest("abortFailedPayWithRefund", req);
if (resp.type === "response") {
return;
}
throw new OperationFailedError(resp.error);
}
async confirmPay(req: ConfirmPayRequest): Promise<ConfirmPayResult> {
const resp = await this.apiRequest("confirmPay", req);
if (resp.type === "response") {
return codecForConfirmPayResult().decode(resp.result);
}
throw new OperationFailedError(resp.error);
}
async prepareTip(req: PrepareTipRequest): Promise<PrepareTipResult> {
const resp = await this.apiRequest("prepareTip", req);
if (resp.type === "response") {
return codecForPrepareTipResult().decode(resp.result);
}
throw new OperationFailedError(resp.error);
}
async acceptTip(req: AcceptTipRequest): Promise<void> {
const resp = await this.apiRequest("acceptTip", req);
if (resp.type === "response") {
return;
}
throw new OperationFailedError(resp.error);
}
async dumpCoins(): Promise<CoinDumpJson> {
const resp = await this.apiRequest("dumpCoins", {});
if (resp.type === "response") {
return codecForAny().decode(resp.result);
}
throw new OperationFailedError(resp.error);
}
async addExchange(req: AddExchangeRequest): Promise<void> {
const resp = await this.apiRequest("addExchange", req);
if (resp.type === "response") {
return;
}
throw new OperationFailedError(resp.error);
}
async forceUpdateExchange(req: ForceExchangeUpdateRequest): Promise<void> {
const resp = await this.apiRequest("addExchange", {
exchangeBaseUrl: req.exchangeBaseUrl,
forceUpdate: true,
});
if (resp.type === "response") {
return;
}
throw new OperationFailedError(resp.error);
}
async forceRefresh(req: ForceRefreshRequest): Promise<void> {
const resp = await this.apiRequest("forceRefresh", req);
if (resp.type === "response") {
return;
}
throw new OperationFailedError(resp.error);
}
async listExchanges(): Promise<ExchangesListRespose> {
const resp = await this.apiRequest("listExchanges", {});
if (resp.type === "response") {
return codecForExchangesListResponse().decode(resp.result);
}
throw new OperationFailedError(resp.error);
}
async getBalances(): Promise<BalancesResponse> {
const resp = await this.apiRequest("getBalances", {});
if (resp.type === "response") {
return codecForBalancesResponse().decode(resp.result);
}
throw new OperationFailedError(resp.error);
}
async getPendingOperations(): Promise<PendingOperationsResponse> {
const resp = await this.apiRequest("getPendingOperations", {});
if (resp.type === "response") {
// FIXME: validate properly!
return codecForAny().decode(resp.result);
}
throw new OperationFailedError(resp.error);
}
async getTransactions(): Promise<TransactionsResponse> {
const resp = await this.apiRequest("getTransactions", {});
if (resp.type === "response") {
return codecForTransactionsResponse().decode(resp.result);
}
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") {
return;
}
throw new OperationFailedError(resp.error);
}
async testPay(args: TestPayArgs): Promise<void> {
const resp = await this.apiRequest("testPay", args);
if (resp.type === "response") {
return;
}
throw new OperationFailedError(resp.error);
}
async withdrawTestBalance(args: WithdrawTestBalanceRequest): Promise<void> {
const resp = await this.apiRequest("withdrawTestBalance", args);
if (resp.type === "response") {
return;
}
throw new OperationFailedError(resp.error);
}
async getWithdrawalDetailsForUri(
req: GetWithdrawalDetailsForUriRequest,
): Promise<WithdrawUriInfoResponse> {
const resp = await this.apiRequest("getWithdrawalDetailsForUri", req);
if (resp.type === "response") {
return codecForWithdrawUriInfoResponse().decode(resp.result);
}
throw new OperationFailedError(resp.error);
}
async addBackupProvider(req: AddBackupProviderRequest): Promise<void> {
const resp = await this.apiRequest("addBackupProvider", req);
if (resp.type === "response") {
return;
}
throw new OperationFailedError(resp.error);
}
async getBackupInfo(): Promise<BackupInfo> {
const resp = await this.apiRequest("getBackupInfo", {});
if (resp.type === "response") {
return resp.result as BackupInfo;
}
throw new OperationFailedError(resp.error);
}
async exportBackupRecovery(): Promise<BackupRecovery> {
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<void> {
const resp = await this.apiRequest("importBackupRecovery", req);
if (resp.type === "response") {
return;
}
throw new OperationFailedError(resp.error);
}
async runBackupCycle(): Promise<void> {
const resp = await this.apiRequest("runBackupCycle", {});
if (resp.type === "response") {
return;
}
throw new OperationFailedError(resp.error);
}
} }

View File

@ -50,6 +50,7 @@ import {
MerchantPrivateApi, MerchantPrivateApi,
HarnessExchangeBankAccount, HarnessExchangeBankAccount,
} from "./harness.js"; } from "./harness.js";
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
export interface SimpleTestEnvironment { export interface SimpleTestEnvironment {
commonDb: DbInfo; commonDb: DbInfo;
@ -265,10 +266,9 @@ export async function startWithdrawViaBank(
// Hand it to the wallet // Hand it to the wallet
const r1 = await wallet.apiRequest("getWithdrawalDetailsForUri", { await wallet.client.call(WalletApiOperation.GetWithdrawalDetailsForUri, {
talerWithdrawUri: wop.taler_withdraw_uri, talerWithdrawUri: wop.taler_withdraw_uri,
}); });
t.assertTrue(r1.type === "response");
await wallet.runPending(); await wallet.runPending();
@ -278,11 +278,10 @@ export async function startWithdrawViaBank(
// Withdraw // Withdraw
const r2 = await wallet.apiRequest("acceptBankIntegratedWithdrawal", { await wallet.client.call(WalletApiOperation.AcceptBankIntegratedWithdrawal, {
exchangeBaseUrl: exchange.baseUrl, exchangeBaseUrl: exchange.baseUrl,
talerWithdrawUri: wop.taler_withdraw_uri, talerWithdrawUri: wop.taler_withdraw_uri,
}); });
t.assertTrue(r2.type === "response");
} }
/** /**
@ -305,8 +304,7 @@ export async function withdrawViaBank(
// Check balance // Check balance
const balApiResp = await wallet.apiRequest("getBalances", {}); await wallet.client.call(WalletApiOperation.GetBalances, {});
t.assertTrue(balApiResp.type === "response");
} }
export async function applyTimeTravel( export async function applyTimeTravel(
@ -365,15 +363,18 @@ export async function makeTestPayment(
// Make wallet pay for the order // Make wallet pay for the order
const preparePayResult = await wallet.preparePay({ const preparePayResult = await wallet.client.call(
WalletApiOperation.PreparePayForUri,
{
talerPayUri: orderStatus.taler_pay_uri, talerPayUri: orderStatus.taler_pay_uri,
}); },
);
t.assertTrue( t.assertTrue(
preparePayResult.status === PreparePayResultType.PaymentPossible, preparePayResult.status === PreparePayResultType.PaymentPossible,
); );
const r2 = await wallet.confirmPay({ const r2 = await wallet.client.call(WalletApiOperation.ConfirmPay, {
proposalId: preparePayResult.proposalId, proposalId: preparePayResult.proposalId,
}); });

View File

@ -20,6 +20,7 @@
import { GlobalTestState, MerchantPrivateApi } from "./harness"; import { GlobalTestState, MerchantPrivateApi } from "./harness";
import { createSimpleTestkudosEnvironment, withdrawViaBank } from "./helpers"; import { createSimpleTestkudosEnvironment, withdrawViaBank } from "./helpers";
import { URL } from "url"; import { URL } from "url";
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
/** /**
* Run test for the merchant's order lifecycle. * Run test for the merchant's order lifecycle.
@ -61,7 +62,7 @@ export async function runClaimLoopTest(t: GlobalTestState) {
// Make wallet claim the unpaid order. // Make wallet claim the unpaid order.
t.assertTrue(orderStatusBefore.order_status === "unpaid"); t.assertTrue(orderStatusBefore.order_status === "unpaid");
const talerPayUri = orderStatusBefore.taler_pay_uri; const talerPayUri = orderStatusBefore.taler_pay_uri;
const y = await wallet.preparePay({ await wallet.client.call(WalletApiOperation.PreparePayForUri, {
talerPayUri, talerPayUri,
}); });

View File

@ -17,6 +17,7 @@
/** /**
* Imports. * Imports.
*/ */
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
import { GlobalTestState } from "./harness"; import { GlobalTestState } from "./harness";
import { createSimpleTestkudosEnvironment, withdrawViaBank } from "./helpers"; import { createSimpleTestkudosEnvironment, withdrawViaBank } from "./helpers";
@ -39,14 +40,20 @@ export async function runDepositTest(t: GlobalTestState) {
await wallet.runUntilDone(); await wallet.runUntilDone();
const { depositGroupId } = await wallet.createDepositGroup({ const { depositGroupId } = await wallet.client.call(
WalletApiOperation.CreateDepositGroup,
{
amount: "TESTKUDOS:10", amount: "TESTKUDOS:10",
depositPaytoUri: "payto://x-taler-bank/localhost/foo", depositPaytoUri: "payto://x-taler-bank/localhost/foo",
}); },
);
await wallet.runUntilDone(); await wallet.runUntilDone();
const transactions = await wallet.getTransactions(); const transactions = await wallet.client.call(
WalletApiOperation.GetTransactions,
{},
);
console.log("transactions", JSON.stringify(transactions, undefined, 2)); console.log("transactions", JSON.stringify(transactions, undefined, 2));
t.assertDeepEqual(transactions.transactions[0].type, "withdrawal"); t.assertDeepEqual(transactions.transactions[0].type, "withdrawal");
t.assertDeepEqual(transactions.transactions[1].type, "deposit"); t.assertDeepEqual(transactions.transactions[1].type, "deposit");
@ -54,7 +61,7 @@ export async function runDepositTest(t: GlobalTestState) {
// deposit and wire fees. // deposit and wire fees.
t.assertDeepEqual(transactions.transactions[1].amountRaw, "TESTKUDOS:9.79"); t.assertDeepEqual(transactions.transactions[1].amountRaw, "TESTKUDOS:9.79");
const trackResult = wallet.trackDepositGroup({ const trackResult = wallet.client.call(WalletApiOperation.TrackDepositGroup, {
depositGroupId, depositGroupId,
}); });

View File

@ -27,7 +27,7 @@ import {
BankApi, BankApi,
BankAccessApi, BankAccessApi,
} from "./harness"; } from "./harness";
import { URL } from "@gnu-taler/taler-wallet-core"; import { URL, WalletApiOperation } from "@gnu-taler/taler-wallet-core";
import { ExchangesListRespose, TalerErrorCode } from "@gnu-taler/taler-util"; import { ExchangesListRespose, TalerErrorCode } from "@gnu-taler/taler-util";
import { import {
FaultInjectedExchangeService, FaultInjectedExchangeService,
@ -116,24 +116,33 @@ export async function runExchangeManagementTest(t: GlobalTestState) {
let exchangesList: ExchangesListRespose; let exchangesList: ExchangesListRespose;
exchangesList = await wallet.listExchanges(); exchangesList = await wallet.client.call(
WalletApiOperation.ListExchanges,
{},
);
t.assertTrue(exchangesList.exchanges.length === 0); t.assertTrue(exchangesList.exchanges.length === 0);
// Try before fault is injected // Try before fault is injected
await wallet.addExchange({ await wallet.client.call(WalletApiOperation.AddExchange, {
exchangeBaseUrl: faultyExchange.baseUrl, exchangeBaseUrl: faultyExchange.baseUrl,
}); });
exchangesList = await wallet.listExchanges(); exchangesList = await wallet.client.call(
WalletApiOperation.ListExchanges,
{},
);
t.assertTrue(exchangesList.exchanges.length === 1); t.assertTrue(exchangesList.exchanges.length === 1);
await wallet.addExchange({ await wallet.client.call(WalletApiOperation.ListExchanges, {
exchangeBaseUrl: faultyExchange.baseUrl, exchangeBaseUrl: faultyExchange.baseUrl,
}); });
console.log("listing exchanges"); console.log("listing exchanges");
exchangesList = await wallet.listExchanges(); exchangesList = await wallet.client.call(
WalletApiOperation.ListExchanges,
{},
);
t.assertTrue(exchangesList.exchanges.length === 1); t.assertTrue(exchangesList.exchanges.length === 1);
console.log("got list", exchangesList); console.log("got list", exchangesList);
@ -147,7 +156,10 @@ export async function runExchangeManagementTest(t: GlobalTestState) {
wallet.deleteDatabase(); wallet.deleteDatabase();
exchangesList = await wallet.listExchanges(); exchangesList = await wallet.client.call(
WalletApiOperation.ListExchanges,
{},
);
t.assertTrue(exchangesList.exchanges.length === 0); t.assertTrue(exchangesList.exchanges.length === 0);
faultyExchange.faultProxy.addFault({ faultyExchange.faultProxy.addFault({
@ -163,7 +175,7 @@ export async function runExchangeManagementTest(t: GlobalTestState) {
}); });
const err1 = await t.assertThrowsOperationErrorAsync(async () => { const err1 = await t.assertThrowsOperationErrorAsync(async () => {
await wallet.addExchange({ await wallet.client.call(WalletApiOperation.AddExchange, {
exchangeBaseUrl: faultyExchange.baseUrl, exchangeBaseUrl: faultyExchange.baseUrl,
}); });
}); });
@ -175,7 +187,10 @@ export async function runExchangeManagementTest(t: GlobalTestState) {
TalerErrorCode.WALLET_RECEIVED_MALFORMED_RESPONSE, TalerErrorCode.WALLET_RECEIVED_MALFORMED_RESPONSE,
); );
exchangesList = await wallet.listExchanges(); exchangesList = await wallet.client.call(
WalletApiOperation.ListExchanges,
{},
);
t.assertTrue(exchangesList.exchanges.length === 0); t.assertTrue(exchangesList.exchanges.length === 0);
/* /*
@ -202,7 +217,7 @@ export async function runExchangeManagementTest(t: GlobalTestState) {
}); });
const err2 = await t.assertThrowsOperationErrorAsync(async () => { const err2 = await t.assertThrowsOperationErrorAsync(async () => {
await wallet.addExchange({ await wallet.client.call(WalletApiOperation.AddExchange, {
exchangeBaseUrl: faultyExchange.baseUrl, exchangeBaseUrl: faultyExchange.baseUrl,
}); });
}); });
@ -212,7 +227,10 @@ export async function runExchangeManagementTest(t: GlobalTestState) {
TalerErrorCode.WALLET_EXCHANGE_PROTOCOL_VERSION_INCOMPATIBLE, TalerErrorCode.WALLET_EXCHANGE_PROTOCOL_VERSION_INCOMPATIBLE,
); );
exchangesList = await wallet.listExchanges(); exchangesList = await wallet.client.call(
WalletApiOperation.ListExchanges,
{},
);
t.assertTrue(exchangesList.exchanges.length === 0); t.assertTrue(exchangesList.exchanges.length === 0);
/* /*
@ -236,9 +254,12 @@ export async function runExchangeManagementTest(t: GlobalTestState) {
// Hand it to the wallet // Hand it to the wallet
const wd = await wallet.getWithdrawalDetailsForUri({ const wd = await wallet.client.call(
WalletApiOperation.GetWithdrawalDetailsForUri,
{
talerWithdrawUri: wop.taler_withdraw_uri, talerWithdrawUri: wop.taler_withdraw_uri,
}); },
);
// Make sure the faulty exchange isn't used for the suggestion. // Make sure the faulty exchange isn't used for the suggestion.
t.assertTrue(wd.possibleExchanges.length === 0); t.assertTrue(wd.possibleExchanges.length === 0);

View File

@ -17,6 +17,7 @@
/** /**
* Imports. * Imports.
*/ */
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
import { import {
GlobalTestState, GlobalTestState,
BankService, BankService,
@ -183,7 +184,7 @@ export async function runFeeRegressionTest(t: GlobalTestState) {
amount: "TESTKUDOS:1.92", amount: "TESTKUDOS:1.92",
}); });
const coins = await wallet.dumpCoins(); const coins = await wallet.client.call(WalletApiOperation.DumpCoins, {});
// Make sure we really withdraw one 0.64 and one 1.28 coin. // Make sure we really withdraw one 0.64 and one 1.28 coin.
t.assertTrue(coins.coins.length === 2); t.assertTrue(coins.coins.length === 2);
@ -198,7 +199,7 @@ export async function runFeeRegressionTest(t: GlobalTestState) {
await wallet.runUntilDone(); await wallet.runUntilDone();
const txs = await wallet.getTransactions(); const txs = await wallet.client.call(WalletApiOperation.GetTransactions, {});
t.assertAmountEquals(txs.transactions[1].amountEffective, "TESTKUDOS:1.30"); t.assertAmountEquals(txs.transactions[1].amountEffective, "TESTKUDOS:1.30");
console.log(txs); console.log(txs);
} }

View File

@ -18,6 +18,7 @@
* Imports. * Imports.
*/ */
import { CoreApiResponse } from "@gnu-taler/taler-util"; import { CoreApiResponse } from "@gnu-taler/taler-util";
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
import { CoinConfig, defaultCoinConfig } from "./denomStructures"; import { CoinConfig, defaultCoinConfig } from "./denomStructures";
import { import {
DbInfo, DbInfo,
@ -237,24 +238,19 @@ export async function runLibeufinBasicTest(t: GlobalTestState) {
libeufinNexus, libeufinNexus,
} = await createLibeufinTestEnvironment(t); } = await createLibeufinTestEnvironment(t);
let wresp: CoreApiResponse; await wallet.client.call(WalletApiOperation.AddExchange, {
// FIXME: add nicer api in the harness wallet for this.
wresp = await wallet.apiRequest("addExchange", {
exchangeBaseUrl: exchange.baseUrl, exchangeBaseUrl: exchange.baseUrl,
}); });
t.assertTrue(wresp.type === "response"); const wr = await wallet.client.call(
WalletApiOperation.AcceptManualWithdrawal,
// FIXME: add nicer api in the harness wallet for this. {
wresp = await wallet.apiRequest("acceptManualWithdrawal", {
exchangeBaseUrl: exchange.baseUrl, exchangeBaseUrl: exchange.baseUrl,
amount: "EUR:10", amount: "EUR:10",
}); },
);
t.assertTrue(wresp.type === "response"); const reservePub: string = wr.reservePub;
const reservePub: string = (wresp.result as any).reservePub;
await LibeufinSandboxApi.simulateIncomingTransaction( await LibeufinSandboxApi.simulateIncomingTransaction(
libeufinSandbox, libeufinSandbox,
@ -275,7 +271,7 @@ export async function runLibeufinBasicTest(t: GlobalTestState) {
await wallet.runUntilDone(); await wallet.runUntilDone();
const bal = await wallet.getBalances(); const bal = await wallet.client.call(WalletApiOperation.GetBalances, {});
console.log("balances", JSON.stringify(bal, undefined, 2)); console.log("balances", JSON.stringify(bal, undefined, 2));
t.assertAmountEquals(bal.balances[0].available, "EUR:14.7"); t.assertAmountEquals(bal.balances[0].available, "EUR:14.7");

View File

@ -43,6 +43,7 @@ import {
FaultInjectionRequestContext, FaultInjectionRequestContext,
} from "./faultInjection"; } from "./faultInjection";
import { defaultCoinConfig } from "./denomStructures"; import { defaultCoinConfig } from "./denomStructures";
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
/** /**
* Run a test case with a simple TESTKUDOS Taler environment, consisting * Run a test case with a simple TESTKUDOS Taler environment, consisting
@ -199,9 +200,12 @@ export async function runMerchantExchangeConfusionTest(t: GlobalTestState) {
console.log(pubUnpaidStatus); console.log(pubUnpaidStatus);
let preparePayResp = await wallet.preparePay({ let preparePayResp = await wallet.client.call(
WalletApiOperation.PreparePayForUri,
{
talerPayUri: pubUnpaidStatus.taler_pay_uri, talerPayUri: pubUnpaidStatus.taler_pay_uri,
}); },
);
t.assertTrue(preparePayResp.status === PreparePayResultType.PaymentPossible); t.assertTrue(preparePayResp.status === PreparePayResultType.PaymentPossible);
@ -221,9 +225,12 @@ export async function runMerchantExchangeConfusionTest(t: GlobalTestState) {
publicOrderStatusResp.data, publicOrderStatusResp.data,
); );
const confirmPayRes = await wallet.confirmPay({ const confirmPayRes = await wallet.client.call(
WalletApiOperation.ConfirmPay,
{
proposalId: proposalId, proposalId: proposalId,
}); },
);
t.assertTrue(confirmPayRes.type === ConfirmPayResultType.Done); t.assertTrue(confirmPayRes.type === ConfirmPayResultType.Done);
} }

View File

@ -25,7 +25,7 @@ import {
ConfirmPayResultType, ConfirmPayResultType,
} from "@gnu-taler/taler-util"; } from "@gnu-taler/taler-util";
import axios from "axios"; import axios from "axios";
import { URL } from "@gnu-taler/taler-wallet-core"; import { URL, WalletApiOperation } from "@gnu-taler/taler-wallet-core";
/** /**
* Run test for basic, bank-integrated withdrawal. * Run test for basic, bank-integrated withdrawal.
@ -104,9 +104,12 @@ export async function runMerchantLongpollingTest(t: GlobalTestState) {
validateStatus: () => true, validateStatus: () => true,
}); });
let preparePayResp = await wallet.preparePay({ let preparePayResp = await wallet.client.call(
WalletApiOperation.PreparePayForUri,
{
talerPayUri: pubUnpaidStatus.taler_pay_uri, talerPayUri: pubUnpaidStatus.taler_pay_uri,
}); },
);
t.assertTrue(preparePayResp.status === PreparePayResultType.PaymentPossible); t.assertTrue(preparePayResp.status === PreparePayResultType.PaymentPossible);
@ -124,9 +127,12 @@ export async function runMerchantLongpollingTest(t: GlobalTestState) {
publicOrderStatusResp.data, publicOrderStatusResp.data,
); );
const confirmPayRes = await wallet.confirmPay({ const confirmPayRes = await wallet.client.call(
WalletApiOperation.ConfirmPay,
{
proposalId: proposalId, proposalId: proposalId,
}); },
);
t.assertTrue(confirmPayRes.type === ConfirmPayResultType.Done); t.assertTrue(confirmPayRes.type === ConfirmPayResultType.Done);
} }

View File

@ -32,7 +32,7 @@ import {
} from "./helpers"; } from "./helpers";
import { durationFromSpec, PreparePayResultType } from "@gnu-taler/taler-util"; import { durationFromSpec, PreparePayResultType } from "@gnu-taler/taler-util";
import axios from "axios"; import axios from "axios";
import { URL } from "@gnu-taler/taler-wallet-core"; import { URL, WalletApiOperation } from "@gnu-taler/taler-wallet-core";
async function testRefundApiWithFulfillmentUrl( async function testRefundApiWithFulfillmentUrl(
t: GlobalTestState, t: GlobalTestState,
@ -66,18 +66,20 @@ async function testRefundApiWithFulfillmentUrl(
// Make wallet pay for the order // Make wallet pay for the order
let preparePayResult = await wallet.preparePay({ let preparePayResult = await wallet.client.call(
WalletApiOperation.PreparePayForUri,
{
talerPayUri, talerPayUri,
}); },
);
t.assertTrue( t.assertTrue(
preparePayResult.status === PreparePayResultType.PaymentPossible, preparePayResult.status === PreparePayResultType.PaymentPossible,
); );
const r2 = await wallet.apiRequest("confirmPay", { await wallet.client.call(WalletApiOperation.ConfirmPay, {
proposalId: preparePayResult.proposalId, proposalId: preparePayResult.proposalId,
}); });
t.assertTrue(r2.type === "response");
// Check if payment was successful. // Check if payment was successful.
@ -87,9 +89,12 @@ async function testRefundApiWithFulfillmentUrl(
t.assertTrue(orderStatus.order_status === "paid"); t.assertTrue(orderStatus.order_status === "paid");
preparePayResult = await wallet.preparePay({ preparePayResult = await wallet.client.call(
WalletApiOperation.PreparePayForUri,
{
talerPayUri, talerPayUri,
}); },
);
t.assertTrue( t.assertTrue(
preparePayResult.status === PreparePayResultType.AlreadyConfirmed, preparePayResult.status === PreparePayResultType.AlreadyConfirmed,
@ -176,18 +181,20 @@ async function testRefundApiWithFulfillmentMessage(
// Make wallet pay for the order // Make wallet pay for the order
let preparePayResult = await wallet.preparePay({ let preparePayResult = await wallet.client.call(
WalletApiOperation.PreparePayForUri,
{
talerPayUri, talerPayUri,
}); },
);
t.assertTrue( t.assertTrue(
preparePayResult.status === PreparePayResultType.PaymentPossible, preparePayResult.status === PreparePayResultType.PaymentPossible,
); );
const r2 = await wallet.apiRequest("confirmPay", { await wallet.client.call(WalletApiOperation.ConfirmPay, {
proposalId: preparePayResult.proposalId, proposalId: preparePayResult.proposalId,
}); });
t.assertTrue(r2.type === "response");
// Check if payment was successful. // Check if payment was successful.
@ -197,9 +204,12 @@ async function testRefundApiWithFulfillmentMessage(
t.assertTrue(orderStatus.order_status === "paid"); t.assertTrue(orderStatus.order_status === "paid");
preparePayResult = await wallet.preparePay({ preparePayResult = await wallet.client.call(
WalletApiOperation.PreparePayForUri,
{
talerPayUri, talerPayUri,
}); },
);
t.assertTrue( t.assertTrue(
preparePayResult.status === PreparePayResultType.AlreadyConfirmed, preparePayResult.status === PreparePayResultType.AlreadyConfirmed,

View File

@ -23,7 +23,7 @@
* Imports. * Imports.
*/ */
import { PreparePayResultType, TalerErrorCode } from "@gnu-taler/taler-util"; import { PreparePayResultType, TalerErrorCode } from "@gnu-taler/taler-util";
import { URL } from "@gnu-taler/taler-wallet-core"; import { URL, WalletApiOperation } from "@gnu-taler/taler-wallet-core";
import { import {
FaultInjectionRequestContext, FaultInjectionRequestContext,
FaultInjectionResponseContext, FaultInjectionResponseContext,
@ -76,9 +76,12 @@ export async function runPayAbortTest(t: GlobalTestState) {
// Make wallet pay for the order // Make wallet pay for the order
const preparePayResult = await wallet.preparePay({ const preparePayResult = await wallet.client.call(
WalletApiOperation.PreparePayForUri,
{
talerPayUri: orderStatus.taler_pay_uri, talerPayUri: orderStatus.taler_pay_uri,
}); },
);
t.assertTrue( t.assertTrue(
preparePayResult.status === PreparePayResultType.PaymentPossible, preparePayResult.status === PreparePayResultType.PaymentPossible,
@ -121,12 +124,12 @@ export async function runPayAbortTest(t: GlobalTestState) {
}); });
await t.assertThrowsOperationErrorAsync(async () => { await t.assertThrowsOperationErrorAsync(async () => {
await wallet.confirmPay({ await wallet.client.call(WalletApiOperation.ConfirmPay, {
proposalId: preparePayResult.proposalId, proposalId: preparePayResult.proposalId,
}); });
}); });
let txr = await wallet.getTransactions(); let txr = await wallet.client.call(WalletApiOperation.GetTransactions, {});
console.log(JSON.stringify(txr, undefined, 2)); console.log(JSON.stringify(txr, undefined, 2));
t.assertDeepEqual(txr.transactions[1].type, "payment"); t.assertDeepEqual(txr.transactions[1].type, "payment");
@ -136,13 +139,13 @@ export async function runPayAbortTest(t: GlobalTestState) {
TalerErrorCode.WALLET_RECEIVED_MALFORMED_RESPONSE, TalerErrorCode.WALLET_RECEIVED_MALFORMED_RESPONSE,
); );
await wallet.abortFailedPayWithRefund({ await wallet.client.call(WalletApiOperation.AbortFailedPayWithRefund, {
proposalId: preparePayResult.proposalId, proposalId: preparePayResult.proposalId,
}); });
await wallet.runUntilDone(); await wallet.runUntilDone();
txr = await wallet.getTransactions(); txr = await wallet.client.call(WalletApiOperation.GetTransactions, {});
console.log(JSON.stringify(txr, undefined, 2)); console.log(JSON.stringify(txr, undefined, 2));
const txTypes = txr.transactions.map((x) => x.type); const txTypes = txr.transactions.map((x) => x.type);

View File

@ -29,7 +29,7 @@ import {
} from "@gnu-taler/taler-util"; } from "@gnu-taler/taler-util";
import axios from "axios"; import axios from "axios";
import { FaultInjectionRequestContext } from "./faultInjection"; import { FaultInjectionRequestContext } from "./faultInjection";
import { URL } from "@gnu-taler/taler-wallet-core"; import { URL, WalletApiOperation } from "@gnu-taler/taler-wallet-core";
/** /**
* Run test for the wallets repurchase detection mechanism * Run test for the wallets repurchase detection mechanism
@ -103,9 +103,12 @@ export async function runPayPaidTest(t: GlobalTestState) {
console.log(pubUnpaidStatus); console.log(pubUnpaidStatus);
let preparePayResp = await wallet.preparePay({ let preparePayResp = await wallet.client.call(
WalletApiOperation.PreparePayForUri,
{
talerPayUri: pubUnpaidStatus.taler_pay_uri, talerPayUri: pubUnpaidStatus.taler_pay_uri,
}); },
);
t.assertTrue(preparePayResp.status === PreparePayResultType.PaymentPossible); t.assertTrue(preparePayResp.status === PreparePayResultType.PaymentPossible);
@ -125,9 +128,12 @@ export async function runPayPaidTest(t: GlobalTestState) {
publicOrderStatusResp.data, publicOrderStatusResp.data,
); );
const confirmPayRes = await wallet.confirmPay({ const confirmPayRes = await wallet.client.call(
WalletApiOperation.ConfirmPay,
{
proposalId: proposalId, proposalId: proposalId,
}); },
);
t.assertTrue(confirmPayRes.type === ConfirmPayResultType.Done); t.assertTrue(confirmPayRes.type === ConfirmPayResultType.Done);
@ -198,9 +204,12 @@ export async function runPayPaidTest(t: GlobalTestState) {
// Pay with new taler://pay URI, which should // Pay with new taler://pay URI, which should
// have the new session ID! // have the new session ID!
// Wallet should now automatically re-play payment. // Wallet should now automatically re-play payment.
preparePayResp = await wallet.preparePay({ preparePayResp = await wallet.client.call(
WalletApiOperation.PreparePayForUri,
{
talerPayUri: orderStatusTwo.taler_pay_uri, talerPayUri: orderStatusTwo.taler_pay_uri,
}); },
);
t.assertTrue(preparePayResp.status === PreparePayResultType.AlreadyConfirmed); t.assertTrue(preparePayResp.status === PreparePayResultType.AlreadyConfirmed);
t.assertTrue(preparePayResp.paid); t.assertTrue(preparePayResp.paid);

View File

@ -21,6 +21,7 @@ import { GlobalTestState, MerchantPrivateApi, WalletCli } from "./harness";
import { createSimpleTestkudosEnvironment, withdrawViaBank } from "./helpers"; import { createSimpleTestkudosEnvironment, withdrawViaBank } from "./helpers";
import { PreparePayResultType } from "@gnu-taler/taler-util"; import { PreparePayResultType } from "@gnu-taler/taler-util";
import { TalerErrorCode } from "@gnu-taler/taler-util"; import { TalerErrorCode } from "@gnu-taler/taler-util";
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
/** /**
* Run test for basic, bank-integrated withdrawal. * Run test for basic, bank-integrated withdrawal.
@ -61,25 +62,26 @@ export async function runPaymentClaimTest(t: GlobalTestState) {
// Make wallet pay for the order // Make wallet pay for the order
const preparePayResult = await wallet.preparePay({ const preparePayResult = await wallet.client.call(
WalletApiOperation.PreparePayForUri,
{
talerPayUri, talerPayUri,
}); },
);
t.assertTrue( t.assertTrue(
preparePayResult.status === PreparePayResultType.PaymentPossible, preparePayResult.status === PreparePayResultType.PaymentPossible,
); );
t.assertThrowsOperationErrorAsync(async () => { t.assertThrowsOperationErrorAsync(async () => {
await walletTwo.preparePay({ await walletTwo.client.call(WalletApiOperation.PreparePayForUri, {
talerPayUri, talerPayUri,
}); });
}); });
const r2 = await wallet.apiRequest("confirmPay", { await wallet.client.call(WalletApiOperation.ConfirmPay, {
// FIXME: should be validated, don't cast!
proposalId: preparePayResult.proposalId, proposalId: preparePayResult.proposalId,
}); });
t.assertTrue(r2.type === "response");
// Check if payment was successful. // Check if payment was successful.
@ -92,7 +94,7 @@ export async function runPaymentClaimTest(t: GlobalTestState) {
walletTwo.deleteDatabase(); walletTwo.deleteDatabase();
const err = await t.assertThrowsOperationErrorAsync(async () => { const err = await t.assertThrowsOperationErrorAsync(async () => {
await walletTwo.preparePay({ await walletTwo.client.call(WalletApiOperation.PreparePayForUri, {
talerPayUri, talerPayUri,
}); });
}); });

View File

@ -39,6 +39,7 @@ import {
} from "./faultInjection"; } from "./faultInjection";
import { CoreApiResponse } from "@gnu-taler/taler-util"; import { CoreApiResponse } from "@gnu-taler/taler-util";
import { defaultCoinConfig } from "./denomStructures"; import { defaultCoinConfig } from "./denomStructures";
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
/** /**
* Run test for basic, bank-integrated withdrawal. * Run test for basic, bank-integrated withdrawal.
@ -124,10 +125,9 @@ export async function runPaymentFaultTest(t: GlobalTestState) {
// Hand it to the wallet // Hand it to the wallet
const r1 = await wallet.apiRequest("getWithdrawalDetailsForUri", { await wallet.client.call(WalletApiOperation.GetWithdrawalDetailsForUri, {
talerWithdrawUri: wop.taler_withdraw_uri, talerWithdrawUri: wop.taler_withdraw_uri,
}); });
t.assertTrue(r1.type === "response");
await wallet.runPending(); await wallet.runPending();
@ -137,16 +137,15 @@ export async function runPaymentFaultTest(t: GlobalTestState) {
// Withdraw // Withdraw
const r2 = await wallet.apiRequest("acceptBankIntegratedWithdrawal", { await wallet.client.call(WalletApiOperation.AcceptBankIntegratedWithdrawal, {
exchangeBaseUrl: faultyExchange.baseUrl, exchangeBaseUrl: faultyExchange.baseUrl,
talerWithdrawUri: wop.taler_withdraw_uri, talerWithdrawUri: wop.taler_withdraw_uri,
}); });
t.assertTrue(r2.type === "response");
await wallet.runUntilDone(); await wallet.runUntilDone();
// Check balance // Check balance
await wallet.getBalances(); await wallet.client.call(WalletApiOperation.GetBalances, {});
// Set up order. // Set up order.
@ -168,12 +167,14 @@ export async function runPaymentFaultTest(t: GlobalTestState) {
let apiResp: CoreApiResponse; let apiResp: CoreApiResponse;
apiResp = await wallet.apiRequest("preparePay", { const prepResp = await wallet.client.call(
WalletApiOperation.PreparePayForUri,
{
talerPayUri: orderStatus.taler_pay_uri, talerPayUri: orderStatus.taler_pay_uri,
}); },
t.assertTrue(apiResp.type === "response"); );
const proposalId = (apiResp.result as any).proposalId; const proposalId = prepResp.proposalId;
await wallet.runPending(); await wallet.runPending();
@ -196,7 +197,7 @@ export async function runPaymentFaultTest(t: GlobalTestState) {
// confirmPay won't work, as the exchange is unreachable // confirmPay won't work, as the exchange is unreachable
apiResp = await wallet.apiRequest("confirmPay", { await wallet.client.call(WalletApiOperation.ConfirmPay, {
// FIXME: should be validated, don't cast! // FIXME: should be validated, don't cast!
proposalId: proposalId, proposalId: proposalId,
}); });

View File

@ -78,4 +78,4 @@ export async function runPaymentForgettableTest(t: GlobalTestState) {
await wallet.runUntilDone(); await wallet.runUntilDone();
} }
runPaymentForgettableTest.suites = ["wallet"]; runPaymentForgettableTest.suites = ["wallet", "merchant"];

View File

@ -20,6 +20,7 @@
import { GlobalTestState, MerchantPrivateApi } from "./harness"; import { GlobalTestState, MerchantPrivateApi } from "./harness";
import { createSimpleTestkudosEnvironment, withdrawViaBank } from "./helpers"; import { createSimpleTestkudosEnvironment, withdrawViaBank } from "./helpers";
import { PreparePayResultType } from "@gnu-taler/taler-util"; import { PreparePayResultType } from "@gnu-taler/taler-util";
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
/** /**
* Test the wallet-core payment API, especially that repeated operations * Test the wallet-core payment API, especially that repeated operations
@ -59,13 +60,19 @@ export async function runPaymentIdempotencyTest(t: GlobalTestState) {
// Make wallet pay for the order // Make wallet pay for the order
const preparePayResult = await wallet.preparePay({ const preparePayResult = await wallet.client.call(
WalletApiOperation.PreparePayForUri,
{
talerPayUri: orderStatus.taler_pay_uri, talerPayUri: orderStatus.taler_pay_uri,
}); },
);
const preparePayResultRep = await wallet.preparePay({ const preparePayResultRep = await wallet.client.call(
WalletApiOperation.PreparePayForUri,
{
talerPayUri: orderStatus.taler_pay_uri, talerPayUri: orderStatus.taler_pay_uri,
}); },
);
t.assertTrue( t.assertTrue(
preparePayResult.status === PreparePayResultType.PaymentPossible, preparePayResult.status === PreparePayResultType.PaymentPossible,
@ -76,11 +83,10 @@ export async function runPaymentIdempotencyTest(t: GlobalTestState) {
const proposalId = preparePayResult.proposalId; const proposalId = preparePayResult.proposalId;
const r2 = await wallet.apiRequest("confirmPay", { await wallet.client.call(WalletApiOperation.ConfirmPay, {
// FIXME: should be validated, don't cast! // FIXME: should be validated, don't cast!
proposalId: proposalId, proposalId: proposalId,
}); });
t.assertTrue(r2.type === "response");
// Check if payment was successful. // Check if payment was successful.
@ -90,9 +96,12 @@ export async function runPaymentIdempotencyTest(t: GlobalTestState) {
t.assertTrue(orderStatus.order_status === "paid"); t.assertTrue(orderStatus.order_status === "paid");
const preparePayResultAfter = await wallet.preparePay({ const preparePayResultAfter = await wallet.client.call(
WalletApiOperation.PreparePayForUri,
{
talerPayUri, talerPayUri,
}); },
);
t.assertTrue( t.assertTrue(
preparePayResultAfter.status === PreparePayResultType.AlreadyConfirmed, preparePayResultAfter.status === PreparePayResultType.AlreadyConfirmed,

View File

@ -28,6 +28,7 @@ import {
} from "./harness"; } from "./harness";
import { withdrawViaBank } from "./helpers"; import { withdrawViaBank } from "./helpers";
import { coin_ct10, coin_u1 } from "./denomStructures"; import { coin_ct10, coin_u1 } from "./denomStructures";
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
async function setupTest( async function setupTest(
t: GlobalTestState, t: GlobalTestState,
@ -137,16 +138,14 @@ export async function runPaymentMultipleTest(t: GlobalTestState) {
// Make wallet pay for the order // Make wallet pay for the order
const r1 = await wallet.apiRequest("preparePay", { const r1 = await wallet.client.call(WalletApiOperation.PreparePayForUri, {
talerPayUri: orderStatus.taler_pay_uri, talerPayUri: orderStatus.taler_pay_uri,
}); });
t.assertTrue(r1.type === "response");
const r2 = await wallet.apiRequest("confirmPay", { await wallet.client.call(WalletApiOperation.ConfirmPay, {
// FIXME: should be validated, don't cast! // FIXME: should be validated, don't cast!
proposalId: (r1.result as any).proposalId, proposalId: r1.proposalId,
}); });
t.assertTrue(r2.type === "response");
// Check if payment was successful. // Check if payment was successful.
@ -160,3 +159,4 @@ export async function runPaymentMultipleTest(t: GlobalTestState) {
} }
runPaymentMultipleTest.suites = ["wallet"]; runPaymentMultipleTest.suites = ["wallet"];
runPaymentMultipleTest.timeoutMs = 120000;

View File

@ -34,7 +34,7 @@ import {
TalerErrorCode, TalerErrorCode,
TalerErrorDetails, TalerErrorDetails,
} from "@gnu-taler/taler-util"; } from "@gnu-taler/taler-util";
import { URL } from "@gnu-taler/taler-wallet-core"; import { URL, WalletApiOperation } from "@gnu-taler/taler-wallet-core";
/** /**
* Run test for a payment where the merchant has a transient * Run test for a payment where the merchant has a transient
@ -90,9 +90,12 @@ export async function runPaymentTransientTest(t: GlobalTestState) {
console.log(pubUnpaidStatus); console.log(pubUnpaidStatus);
let preparePayResp = await wallet.preparePay({ let preparePayResp = await wallet.client.call(
WalletApiOperation.PreparePayForUri,
{
talerPayUri: pubUnpaidStatus.taler_pay_uri, talerPayUri: pubUnpaidStatus.taler_pay_uri,
}); },
);
t.assertTrue(preparePayResp.status === PreparePayResultType.PaymentPossible); t.assertTrue(preparePayResp.status === PreparePayResultType.PaymentPossible);
@ -139,18 +142,24 @@ export async function runPaymentTransientTest(t: GlobalTestState) {
}, },
}); });
const confirmPayResp = await wallet.confirmPay({ const confirmPayResp = await wallet.client.call(
WalletApiOperation.ConfirmPay,
{
proposalId, proposalId,
}); },
);
console.log(confirmPayResp); console.log(confirmPayResp);
t.assertTrue(confirmPayResp.type === ConfirmPayResultType.Pending); t.assertTrue(confirmPayResp.type === ConfirmPayResultType.Pending);
t.assertTrue(faultInjected); t.assertTrue(faultInjected);
const confirmPayRespTwo = await wallet.confirmPay({ const confirmPayRespTwo = await wallet.client.call(
WalletApiOperation.ConfirmPay,
{
proposalId, proposalId,
}); },
);
t.assertTrue(confirmPayRespTwo.type === ConfirmPayResultType.Done); t.assertTrue(confirmPayRespTwo.type === ConfirmPayResultType.Done);

View File

@ -25,6 +25,7 @@ import {
ConfirmPayResultType, ConfirmPayResultType,
} from "@gnu-taler/taler-util"; } from "@gnu-taler/taler-util";
import axios from "axios"; import axios from "axios";
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
/** /**
* Run test for basic, bank-integrated withdrawal. * Run test for basic, bank-integrated withdrawal.
@ -90,9 +91,12 @@ export async function runPaywallFlowTest(t: GlobalTestState) {
console.log(pubUnpaidStatus); console.log(pubUnpaidStatus);
let preparePayResp = await wallet.preparePay({ let preparePayResp = await wallet.client.call(
WalletApiOperation.PreparePayForUri,
{
talerPayUri: pubUnpaidStatus.taler_pay_uri, talerPayUri: pubUnpaidStatus.taler_pay_uri,
}); },
);
t.assertTrue(preparePayResp.status === PreparePayResultType.PaymentPossible); t.assertTrue(preparePayResp.status === PreparePayResultType.PaymentPossible);
@ -112,9 +116,12 @@ export async function runPaywallFlowTest(t: GlobalTestState) {
publicOrderStatusResp.data, publicOrderStatusResp.data,
); );
const confirmPayRes = await wallet.confirmPay({ const confirmPayRes = await wallet.client.call(
WalletApiOperation.ConfirmPay,
{
proposalId: proposalId, proposalId: proposalId,
}); },
);
t.assertTrue(confirmPayRes.type === ConfirmPayResultType.Done); t.assertTrue(confirmPayRes.type === ConfirmPayResultType.Done);
@ -148,9 +155,12 @@ export async function runPaywallFlowTest(t: GlobalTestState) {
// Pay with new taler://pay URI, which should // Pay with new taler://pay URI, which should
// have the new session ID! // have the new session ID!
// Wallet should now automatically re-play payment. // Wallet should now automatically re-play payment.
preparePayResp = await wallet.preparePay({ preparePayResp = await wallet.client.call(
WalletApiOperation.PreparePayForUri,
{
talerPayUri: talerPayUriOne, talerPayUri: talerPayUriOne,
}); },
);
t.assertTrue(preparePayResp.status === PreparePayResultType.AlreadyConfirmed); t.assertTrue(preparePayResp.status === PreparePayResultType.AlreadyConfirmed);
t.assertTrue(preparePayResp.paid); t.assertTrue(preparePayResp.paid);
@ -185,9 +195,12 @@ export async function runPaywallFlowTest(t: GlobalTestState) {
// Here the re-purchase detection should kick in, // Here the re-purchase detection should kick in,
// and the wallet should re-pay for the old order // and the wallet should re-pay for the old order
// under the new session ID (mysession-three). // under the new session ID (mysession-three).
preparePayResp = await wallet.preparePay({ preparePayResp = await wallet.client.call(
WalletApiOperation.PreparePayForUri,
{
talerPayUri: orderStatus.taler_pay_uri, talerPayUri: orderStatus.taler_pay_uri,
}); },
);
t.assertTrue(preparePayResp.status === PreparePayResultType.AlreadyConfirmed); t.assertTrue(preparePayResp.status === PreparePayResultType.AlreadyConfirmed);
t.assertTrue(preparePayResp.paid); t.assertTrue(preparePayResp.paid);

View File

@ -20,6 +20,7 @@
import { GlobalTestState, MerchantPrivateApi } from "./harness"; import { GlobalTestState, MerchantPrivateApi } from "./harness";
import { createSimpleTestkudosEnvironment, withdrawViaBank } from "./helpers"; import { createSimpleTestkudosEnvironment, withdrawViaBank } from "./helpers";
import { durationFromSpec } from "@gnu-taler/taler-util"; import { durationFromSpec } from "@gnu-taler/taler-util";
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
/** /**
* Run test for basic, bank-integrated withdrawal. * Run test for basic, bank-integrated withdrawal.
@ -59,16 +60,14 @@ export async function runRefundAutoTest(t: GlobalTestState) {
// Make wallet pay for the order // Make wallet pay for the order
const r1 = await wallet.apiRequest("preparePay", { const r1 = await wallet.client.call(WalletApiOperation.PreparePayForUri, {
talerPayUri: orderStatus.taler_pay_uri, talerPayUri: orderStatus.taler_pay_uri,
}); });
t.assertTrue(r1.type === "response");
const r2 = await wallet.apiRequest("confirmPay", { await wallet.client.call(WalletApiOperation.ConfirmPay, {
// FIXME: should be validated, don't cast! // FIXME: should be validated, don't cast!
proposalId: (r1.result as any).proposalId, proposalId: r1.proposalId,
}); });
t.assertTrue(r2.type === "response");
// Check if payment was successful. // Check if payment was successful.
@ -90,7 +89,10 @@ export async function runRefundAutoTest(t: GlobalTestState) {
// The wallet should now automatically pick up the refund. // The wallet should now automatically pick up the refund.
await wallet.runUntilDone(); await wallet.runUntilDone();
const transactions = await wallet.getTransactions(); const transactions = await wallet.client.call(
WalletApiOperation.GetTransactions,
{},
);
console.log(JSON.stringify(transactions, undefined, 2)); console.log(JSON.stringify(transactions, undefined, 2));
const transactionTypes = transactions.transactions.map((x) => x.type); const transactionTypes = transactions.transactions.map((x) => x.type);

View File

@ -29,6 +29,7 @@ import {
getTimestampNow, getTimestampNow,
timestampTruncateToSecond, timestampTruncateToSecond,
} from "@gnu-taler/taler-util"; } from "@gnu-taler/taler-util";
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
/** /**
* Run test for basic, bank-integrated withdrawal. * Run test for basic, bank-integrated withdrawal.
@ -74,16 +75,13 @@ export async function runRefundGoneTest(t: GlobalTestState) {
// Make wallet pay for the order // Make wallet pay for the order
const r1 = await wallet.apiRequest("preparePay", { const r1 = await wallet.client.call(WalletApiOperation.PreparePayForUri, {
talerPayUri: orderStatus.taler_pay_uri, talerPayUri: orderStatus.taler_pay_uri,
}); });
t.assertTrue(r1.type === "response");
const r2 = await wallet.apiRequest("confirmPay", { const r2 = await wallet.client.call(WalletApiOperation.ConfirmPay, {
// FIXME: should be validated, don't cast! proposalId: r1.proposalId,
proposalId: (r1.result as any).proposalId,
}); });
t.assertTrue(r2.type === "response");
// Check if payment was successful. // Check if payment was successful.
@ -108,7 +106,7 @@ export async function runRefundGoneTest(t: GlobalTestState) {
console.log(ref); console.log(ref);
let rr = await wallet.applyRefund({ let rr = await wallet.client.call(WalletApiOperation.ApplyRefund, {
talerRefundUri: ref.talerRefundUri, talerRefundUri: ref.talerRefundUri,
}); });
@ -117,11 +115,11 @@ export async function runRefundGoneTest(t: GlobalTestState) {
await wallet.runUntilDone(); await wallet.runUntilDone();
let r = await wallet.apiRequest("getBalances", {}); let r = await wallet.client.call(WalletApiOperation.GetBalances, {});
console.log(JSON.stringify(r, undefined, 2)); console.log(JSON.stringify(r, undefined, 2));
r = await wallet.apiRequest("getTransactions", {}); const r3 = await wallet.client.call(WalletApiOperation.GetTransactions, {});
console.log(JSON.stringify(r, undefined, 2)); console.log(JSON.stringify(r3, undefined, 2));
await t.shutdown(); await t.shutdown();
} }

View File

@ -24,6 +24,7 @@ import {
Amounts, Amounts,
durationFromSpec, durationFromSpec,
} from "@gnu-taler/taler-util"; } from "@gnu-taler/taler-util";
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
/** /**
* Run test for basic, bank-integrated withdrawal. * Run test for basic, bank-integrated withdrawal.
@ -61,16 +62,13 @@ export async function runRefundIncrementalTest(t: GlobalTestState) {
// Make wallet pay for the order // Make wallet pay for the order
const r1 = await wallet.apiRequest("preparePay", { const r1 = await wallet.client.call(WalletApiOperation.PreparePayForUri, {
talerPayUri: orderStatus.taler_pay_uri, talerPayUri: orderStatus.taler_pay_uri,
}); });
t.assertTrue(r1.type === "response");
const r2 = await wallet.apiRequest("confirmPay", { await wallet.client.call(WalletApiOperation.ConfirmPay, {
// FIXME: should be validated, don't cast! proposalId: r1.proposalId,
proposalId: (r1.result as any).proposalId,
}); });
t.assertTrue(r2.type === "response");
// Check if payment was successful. // Check if payment was successful.
@ -90,11 +88,14 @@ export async function runRefundIncrementalTest(t: GlobalTestState) {
console.log("first refund increase response", ref); console.log("first refund increase response", ref);
{ {
let wr = await wallet.applyRefund({ let wr = await wallet.client.call(WalletApiOperation.ApplyRefund, {
talerRefundUri: ref.talerRefundUri, talerRefundUri: ref.talerRefundUri,
}); });
console.log(wr); console.log(wr);
const txs = await wallet.getTransactions(); const txs = await wallet.client.call(
WalletApiOperation.GetTransactions,
{},
);
console.log( console.log(
"transactions after applying first refund:", "transactions after applying first refund:",
JSON.stringify(txs, undefined, 2), JSON.stringify(txs, undefined, 2),
@ -128,7 +129,7 @@ export async function runRefundIncrementalTest(t: GlobalTestState) {
console.log("third refund increase response", ref); console.log("third refund increase response", ref);
{ {
let wr = await wallet.applyRefund({ let wr = await wallet.client.call(WalletApiOperation.ApplyRefund, {
talerRefundUri: ref.talerRefundUri, talerRefundUri: ref.talerRefundUri,
}); });
console.log(wr); console.log(wr);
@ -146,11 +147,14 @@ export async function runRefundIncrementalTest(t: GlobalTestState) {
await wallet.runUntilDone(); await wallet.runUntilDone();
const bal = await wallet.getBalances(); const bal = await wallet.client.call(WalletApiOperation.GetBalances, {});
console.log(JSON.stringify(bal, undefined, 2)); console.log(JSON.stringify(bal, undefined, 2));
{ {
const txs = await wallet.getTransactions(); const txs = await wallet.client.call(
WalletApiOperation.GetTransactions,
{},
);
console.log(JSON.stringify(txs, undefined, 2)); console.log(JSON.stringify(txs, undefined, 2));
const txTypes = txs.transactions.map((x) => x.type); const txTypes = txs.transactions.map((x) => x.type);

View File

@ -18,6 +18,7 @@
* Imports. * Imports.
*/ */
import { durationFromSpec } from "@gnu-taler/taler-util"; import { durationFromSpec } from "@gnu-taler/taler-util";
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
import { GlobalTestState, MerchantPrivateApi } from "./harness"; import { GlobalTestState, MerchantPrivateApi } from "./harness";
import { createSimpleTestkudosEnvironment, withdrawViaBank } from "./helpers"; import { createSimpleTestkudosEnvironment, withdrawViaBank } from "./helpers";
@ -57,16 +58,13 @@ export async function runRefundTest(t: GlobalTestState) {
// Make wallet pay for the order // Make wallet pay for the order
const r1 = await wallet.apiRequest("preparePay", { const r1 = await wallet.client.call(WalletApiOperation.PreparePayForUri, {
talerPayUri: orderStatus.taler_pay_uri, talerPayUri: orderStatus.taler_pay_uri,
}); });
t.assertTrue(r1.type === "response");
const r2 = await wallet.apiRequest("confirmPay", { await wallet.client.call(WalletApiOperation.ConfirmPay, {
// FIXME: should be validated, don't cast! proposalId: r1.proposalId,
proposalId: (r1.result as any).proposalId,
}); });
t.assertTrue(r2.type === "response");
// Check if payment was successful. // Check if payment was successful.
@ -85,19 +83,21 @@ export async function runRefundTest(t: GlobalTestState) {
console.log(ref); console.log(ref);
let r = await wallet.apiRequest("applyRefund", { let r = await wallet.client.call(WalletApiOperation.ApplyRefund, {
talerRefundUri: ref.talerRefundUri, talerRefundUri: ref.talerRefundUri,
}); });
t.assertTrue(r.type === "response");
console.log(r); console.log(r);
await wallet.runUntilDone(); await wallet.runUntilDone();
r = await wallet.apiRequest("getBalances", {}); {
console.log(JSON.stringify(r, undefined, 2)); const r2 = await wallet.client.call(WalletApiOperation.GetBalances, {});
console.log(JSON.stringify(r2, undefined, 2));
r = await wallet.apiRequest("getTransactions", {}); }
console.log(JSON.stringify(r, undefined, 2)); {
const r2 = await wallet.client.call(WalletApiOperation.GetTransactions, {});
console.log(JSON.stringify(r2, undefined, 2));
}
await t.shutdown(); await t.shutdown();
} }

View File

@ -17,6 +17,7 @@
/** /**
* Imports. * Imports.
*/ */
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
import { CoinConfig } from "./denomStructures"; import { CoinConfig } from "./denomStructures";
import { import {
GlobalTestState, GlobalTestState,
@ -39,7 +40,7 @@ async function revokeAllWalletCoins(req: {
merchant: MerchantService; merchant: MerchantService;
}): Promise<void> { }): Promise<void> {
const { wallet, exchange, merchant } = req; const { wallet, exchange, merchant } = req;
const coinDump = await wallet.dumpCoins(); const coinDump = await wallet.client.call(WalletApiOperation.DumpCoins, {});
console.log(coinDump); console.log(coinDump);
const usedDenomHashes = new Set<string>(); const usedDenomHashes = new Set<string>();
for (const coin of coinDump.coins) { for (const coin of coinDump.coins) {
@ -160,10 +161,13 @@ export async function runRevocationTest(t: GlobalTestState) {
// FIXME: this shouldn't be necessary once https://bugs.taler.net/n/6565 // FIXME: this shouldn't be necessary once https://bugs.taler.net/n/6565
// is implemented. // is implemented.
await wallet.forceUpdateExchange({ exchangeBaseUrl: exchange.baseUrl }); await wallet.client.call(WalletApiOperation.AddExchange, {
exchangeBaseUrl: exchange.baseUrl,
forceUpdate: true,
});
await wallet.runUntilDone(); await wallet.runUntilDone();
await wallet.runUntilDone(); await wallet.runUntilDone();
const bal = await wallet.getBalances(); const bal = await wallet.client.call(WalletApiOperation.GetBalances, {});
console.log("wallet balance", bal); console.log("wallet balance", bal);
const order = { const order = {
@ -177,10 +181,10 @@ export async function runRevocationTest(t: GlobalTestState) {
wallet.deleteDatabase(); wallet.deleteDatabase();
await withdrawViaBank(t, { wallet, bank, exchange, amount: "TESTKUDOS:15" }); await withdrawViaBank(t, { wallet, bank, exchange, amount: "TESTKUDOS:15" });
const coinDump = await wallet.dumpCoins(); const coinDump = await wallet.client.call(WalletApiOperation.DumpCoins, {});
console.log(coinDump); console.log(coinDump);
const coinPubList = coinDump.coins.map((x) => x.coin_pub); const coinPubList = coinDump.coins.map((x) => x.coin_pub);
await wallet.forceRefresh({ await wallet.client.call(WalletApiOperation.ForceRefresh, {
coinPubList, coinPubList,
}); });
await wallet.runUntilDone(); await wallet.runUntilDone();
@ -190,11 +194,14 @@ export async function runRevocationTest(t: GlobalTestState) {
// FIXME: this shouldn't be necessary once https://bugs.taler.net/n/6565 // FIXME: this shouldn't be necessary once https://bugs.taler.net/n/6565
// is implemented. // is implemented.
await wallet.forceUpdateExchange({ exchangeBaseUrl: exchange.baseUrl }); await wallet.client.call(WalletApiOperation.AddExchange, {
exchangeBaseUrl: exchange.baseUrl,
forceUpdate: true,
});
await wallet.runUntilDone(); await wallet.runUntilDone();
await wallet.runUntilDone(); await wallet.runUntilDone();
{ {
const bal = await wallet.getBalances(); const bal = await wallet.client.call(WalletApiOperation.GetBalances, {});
console.log("wallet balance", bal); console.log("wallet balance", bal);
} }

View File

@ -23,7 +23,10 @@ import {
durationFromSpec, durationFromSpec,
PreparePayResultType, PreparePayResultType,
} from "@gnu-taler/taler-util"; } from "@gnu-taler/taler-util";
import { PendingOperationsResponse } from "@gnu-taler/taler-wallet-core"; import {
PendingOperationsResponse,
WalletApiOperation,
} from "@gnu-taler/taler-wallet-core";
import { makeNoFeeCoinConfig } from "./denomStructures"; import { makeNoFeeCoinConfig } from "./denomStructures";
import { import {
BankService, BankService,
@ -145,7 +148,7 @@ export async function runTimetravelAutorefreshTest(t: GlobalTestState) {
await wallet.runUntilDone(); await wallet.runUntilDone();
let p: PendingOperationsResponse; let p: PendingOperationsResponse;
p = await wallet.getPendingOperations(); p = await wallet.client.call(WalletApiOperation.GetPendingOperations, {});
console.log("pending operations after first time travel"); console.log("pending operations after first time travel");
console.log(JSON.stringify(p, undefined, 2)); console.log(JSON.stringify(p, undefined, 2));
@ -191,7 +194,7 @@ export async function runTimetravelAutorefreshTest(t: GlobalTestState) {
t.assertTrue(orderStatus.order_status === "unpaid"); t.assertTrue(orderStatus.order_status === "unpaid");
const r = await wallet.preparePay({ const r = await wallet.client.call(WalletApiOperation.PreparePayForUri, {
talerPayUri: orderStatus.taler_pay_uri, talerPayUri: orderStatus.taler_pay_uri,
}); });
@ -199,7 +202,7 @@ export async function runTimetravelAutorefreshTest(t: GlobalTestState) {
t.assertTrue(r.status === PreparePayResultType.PaymentPossible); t.assertTrue(r.status === PreparePayResultType.PaymentPossible);
const cpr = await wallet.confirmPay({ const cpr = await wallet.client.call(WalletApiOperation.ConfirmPay, {
proposalId: r.proposalId, proposalId: r.proposalId,
}); });

View File

@ -24,6 +24,7 @@ import {
startWithdrawViaBank, startWithdrawViaBank,
} from "./helpers"; } from "./helpers";
import { Duration, TransactionType } from "@gnu-taler/taler-util"; import { Duration, TransactionType } from "@gnu-taler/taler-util";
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
/** /**
* Basic time travel test. * Basic time travel test.
@ -71,7 +72,10 @@ export async function runTimetravelWithdrawTest(t: GlobalTestState) {
// Check that transactions are correct for the failed withdrawal // Check that transactions are correct for the failed withdrawal
{ {
await wallet.runUntilDone({ maxRetries: 5 }); await wallet.runUntilDone({ maxRetries: 5 });
const transactions = await wallet.getTransactions(); const transactions = await wallet.client.call(
WalletApiOperation.GetTransactions,
{},
);
console.log(transactions); console.log(transactions);
const types = transactions.transactions.map((x) => x.type); const types = transactions.transactions.map((x) => x.type);
t.assertDeepEqual(types, ["withdrawal", "withdrawal"]); t.assertDeepEqual(types, ["withdrawal", "withdrawal"]);

View File

@ -17,6 +17,7 @@
/** /**
* Imports. * Imports.
*/ */
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
import { GlobalTestState, MerchantPrivateApi, BankApi } from "./harness"; import { GlobalTestState, MerchantPrivateApi, BankApi } from "./harness";
import { createSimpleTestkudosEnvironment } from "./helpers"; import { createSimpleTestkudosEnvironment } from "./helpers";
@ -83,7 +84,7 @@ export async function runTippingTest(t: GlobalTestState) {
console.log("created tip", tip); console.log("created tip", tip);
const doTip = async (): Promise<void> => { const doTip = async (): Promise<void> => {
const ptr = await wallet.prepareTip({ const ptr = await wallet.client.call(WalletApiOperation.PrepareTip, {
talerTipUri: tip.taler_tip_uri, talerTipUri: tip.taler_tip_uri,
}); });
@ -92,19 +93,22 @@ export async function runTippingTest(t: GlobalTestState) {
t.assertAmountEquals(ptr.tipAmountRaw, "TESTKUDOS:5"); t.assertAmountEquals(ptr.tipAmountRaw, "TESTKUDOS:5");
t.assertAmountEquals(ptr.tipAmountEffective, "TESTKUDOS:4.85"); t.assertAmountEquals(ptr.tipAmountEffective, "TESTKUDOS:4.85");
await wallet.acceptTip({ await wallet.client.call(WalletApiOperation.AcceptTip, {
walletTipId: ptr.walletTipId, walletTipId: ptr.walletTipId,
}); });
await wallet.runUntilDone(); await wallet.runUntilDone();
const bal = await wallet.getBalances(); const bal = await wallet.client.call(WalletApiOperation.GetBalances, {});
console.log(bal); console.log(bal);
t.assertAmountEquals(bal.balances[0].available, "TESTKUDOS:4.85"); t.assertAmountEquals(bal.balances[0].available, "TESTKUDOS:4.85");
const txns = await wallet.getTransactions(); const txns = await wallet.client.call(
WalletApiOperation.GetTransactions,
{},
);
console.log("Transactions:", JSON.stringify(txns, undefined, 2)); console.log("Transactions:", JSON.stringify(txns, undefined, 2));

View File

@ -17,6 +17,7 @@
/** /**
* Imports. * Imports.
*/ */
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
import { GlobalTestState, WalletCli } from "./harness"; import { GlobalTestState, WalletCli } from "./harness";
import { createSimpleTestkudosEnvironment, withdrawViaBank } from "./helpers"; import { createSimpleTestkudosEnvironment, withdrawViaBank } from "./helpers";
import { SyncService } from "./sync"; import { SyncService } from "./sync";
@ -49,30 +50,30 @@ export async function runWalletBackupBasicTest(t: GlobalTestState) {
await sync.start(); await sync.start();
await sync.pingUntilAvailable(); await sync.pingUntilAvailable();
await wallet.addBackupProvider({ await wallet.client.call(WalletApiOperation.AddBackupProvider, {
backupProviderBaseUrl: sync.baseUrl, backupProviderBaseUrl: sync.baseUrl,
activate: false, activate: false,
}); });
{ {
const bi = await wallet.getBackupInfo(); const bi = await wallet.client.call(WalletApiOperation.GetBackupInfo, {});
t.assertDeepEqual(bi.providers[0].active, false); t.assertDeepEqual(bi.providers[0].active, false);
} }
await wallet.addBackupProvider({ await wallet.client.call(WalletApiOperation.AddBackupProvider, {
backupProviderBaseUrl: sync.baseUrl, backupProviderBaseUrl: sync.baseUrl,
activate: true, activate: true,
}); });
{ {
const bi = await wallet.getBackupInfo(); const bi = await wallet.client.call(WalletApiOperation.GetBackupInfo, {});
t.assertDeepEqual(bi.providers[0].active, true); t.assertDeepEqual(bi.providers[0].active, true);
} }
await wallet.runBackupCycle(); await wallet.client.call(WalletApiOperation.RunBackupCycle, {});
{ {
const bi = await wallet.getBackupInfo(); const bi = await wallet.client.call(WalletApiOperation.GetBackupInfo, {});
console.log(bi); console.log(bi);
t.assertDeepEqual( t.assertDeepEqual(
bi.providers[0].paymentStatus.type, bi.providers[0].paymentStatus.type,
@ -82,46 +83,51 @@ export async function runWalletBackupBasicTest(t: GlobalTestState) {
await withdrawViaBank(t, { wallet, bank, exchange, amount: "TESTKUDOS:10" }); await withdrawViaBank(t, { wallet, bank, exchange, amount: "TESTKUDOS:10" });
await wallet.runBackupCycle(); await wallet.client.call(WalletApiOperation.RunBackupCycle, {});
{ {
const bi = await wallet.getBackupInfo(); const bi = await wallet.client.call(WalletApiOperation.GetBackupInfo, {});
console.log(bi); console.log(bi);
} }
await withdrawViaBank(t, { wallet, bank, exchange, amount: "TESTKUDOS:5" }); await withdrawViaBank(t, { wallet, bank, exchange, amount: "TESTKUDOS:5" });
await wallet.runBackupCycle(); await wallet.client.call(WalletApiOperation.RunBackupCycle, {});
{ {
const bi = await wallet.getBackupInfo(); const bi = await wallet.client.call(WalletApiOperation.GetBackupInfo, {});
console.log(bi); console.log(bi);
} }
const backupRecovery = await wallet.exportBackupRecovery(); const backupRecovery = await wallet.client.call(
WalletApiOperation.ExportBackupRecovery,
{},
);
const wallet2 = new WalletCli(t, "wallet2"); const wallet2 = new WalletCli(t, "wallet2");
// Check that the second wallet is a fresh wallet. // Check that the second wallet is a fresh wallet.
{ {
const bal = await wallet2.getBalances(); const bal = await wallet2.client.call(WalletApiOperation.GetBalances, {});
t.assertTrue(bal.balances.length === 0); t.assertTrue(bal.balances.length === 0);
} }
await wallet2.importBackupRecovery({ recovery: backupRecovery }); await wallet2.client.call(WalletApiOperation.ImportBackupRecovery, {
recovery: backupRecovery,
});
await wallet2.runBackupCycle(); await wallet2.client.call(WalletApiOperation.RunBackupCycle, {});
// Check that now the old balance is available! // Check that now the old balance is available!
{ {
const bal = await wallet2.getBalances(); const bal = await wallet2.client.call(WalletApiOperation.GetBalances, {});
t.assertTrue(bal.balances.length === 1); t.assertTrue(bal.balances.length === 1);
console.log(bal); console.log(bal);
} }
// Now do some basic checks that the restored wallet is still functional // Now do some basic checks that the restored wallet is still functional
{ {
const bal1 = await wallet2.getBalances(); const bal1 = await wallet2.client.call(WalletApiOperation.GetBalances, {});
t.assertAmountEquals(bal1.balances[0].available, "TESTKUDOS:14.1"); t.assertAmountEquals(bal1.balances[0].available, "TESTKUDOS:14.1");
@ -134,7 +140,7 @@ export async function runWalletBackupBasicTest(t: GlobalTestState) {
await wallet2.runUntilDone(); await wallet2.runUntilDone();
const bal2 = await wallet2.getBalances(); const bal2 = await wallet2.client.call(WalletApiOperation.GetBalances, {});
t.assertAmountEquals(bal2.balances[0].available, "TESTKUDOS:23.82"); t.assertAmountEquals(bal2.balances[0].available, "TESTKUDOS:23.82");
} }

View File

@ -18,6 +18,7 @@
* Imports. * Imports.
*/ */
import { PreparePayResultType } from "@gnu-taler/taler-util"; import { PreparePayResultType } from "@gnu-taler/taler-util";
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
import { GlobalTestState, WalletCli, MerchantPrivateApi } from "./harness"; import { GlobalTestState, WalletCli, MerchantPrivateApi } from "./harness";
import { import {
createSimpleTestkudosEnvironment, createSimpleTestkudosEnvironment,
@ -54,26 +55,34 @@ export async function runWalletBackupDoublespendTest(t: GlobalTestState) {
await sync.start(); await sync.start();
await sync.pingUntilAvailable(); await sync.pingUntilAvailable();
await wallet.addBackupProvider({ await wallet.client.call(WalletApiOperation.AddBackupProvider, {
backupProviderBaseUrl: sync.baseUrl, backupProviderBaseUrl: sync.baseUrl,
activate: true, activate: true,
}); });
await withdrawViaBank(t, { wallet, bank, exchange, amount: "TESTKUDOS:10" }); await withdrawViaBank(t, { wallet, bank, exchange, amount: "TESTKUDOS:10" });
await wallet.runBackupCycle(); await wallet.client.call(WalletApiOperation.RunBackupCycle, {});
await wallet.runUntilDone(); await wallet.runUntilDone();
await wallet.runBackupCycle(); await wallet.client.call(WalletApiOperation.RunBackupCycle, {});
const backupRecovery = await wallet.exportBackupRecovery(); const backupRecovery = await wallet.client.call(
WalletApiOperation.ExportBackupRecovery,
{},
);
const wallet2 = new WalletCli(t, "wallet2"); const wallet2 = new WalletCli(t, "wallet2");
await wallet2.importBackupRecovery({ recovery: backupRecovery }); await wallet2.client.call(WalletApiOperation.ImportBackupRecovery, {
recovery: backupRecovery,
});
await wallet2.runBackupCycle(); await wallet2.client.call(WalletApiOperation.RunBackupCycle, {});
console.log("wallet1 balance before spend:", await wallet.getBalances()); console.log(
"wallet1 balance before spend:",
await wallet.client.call(WalletApiOperation.GetBalances, {}),
);
await makeTestPayment(t, { await makeTestPayment(t, {
merchant, merchant,
@ -86,10 +95,16 @@ export async function runWalletBackupDoublespendTest(t: GlobalTestState) {
await wallet.runUntilDone(); await wallet.runUntilDone();
console.log("wallet1 balance after spend:", await wallet.getBalances()); console.log(
"wallet1 balance after spend:",
await wallet.client.call(WalletApiOperation.GetBalances, {}),
);
{ {
console.log("wallet2 balance:", await wallet2.getBalances()); console.log(
"wallet2 balance:",
await wallet2.client.call(WalletApiOperation.GetBalances, {}),
);
} }
// Now we double-spend with the second wallet // Now we double-spend with the second wallet
@ -116,15 +131,18 @@ export async function runWalletBackupDoublespendTest(t: GlobalTestState) {
// Make wallet pay for the order // Make wallet pay for the order
const preparePayResult = await wallet2.preparePay({ const preparePayResult = await wallet2.client.call(
WalletApiOperation.PreparePayForUri,
{
talerPayUri: orderStatus.taler_pay_uri, talerPayUri: orderStatus.taler_pay_uri,
}); },
);
t.assertTrue( t.assertTrue(
preparePayResult.status === PreparePayResultType.PaymentPossible, preparePayResult.status === PreparePayResultType.PaymentPossible,
); );
const res = await wallet2.confirmPay({ const res = await wallet2.client.call(WalletApiOperation.ConfirmPay, {
proposalId: preparePayResult.proposalId, proposalId: preparePayResult.proposalId,
}); });
@ -139,7 +157,7 @@ export async function runWalletBackupDoublespendTest(t: GlobalTestState) {
amount: "TESTKUDOS:50", amount: "TESTKUDOS:50",
}); });
const bal = await wallet2.getBalances(); const bal = await wallet2.client.call(WalletApiOperation.GetBalances, {});
console.log("bal", bal); console.log("bal", bal);
await wallet2.runUntilDone(); await wallet2.runUntilDone();

View File

@ -22,6 +22,7 @@
/** /**
* Imports. * Imports.
*/ */
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
import { CoinConfig, defaultCoinConfig } from "./denomStructures"; import { CoinConfig, defaultCoinConfig } from "./denomStructures";
import { import {
BankService, BankService,
@ -114,7 +115,7 @@ export async function createMyEnvironment(
export async function runWallettestingTest(t: GlobalTestState) { export async function runWallettestingTest(t: GlobalTestState) {
const { wallet, bank, exchange, merchant } = await createMyEnvironment(t); const { wallet, bank, exchange, merchant } = await createMyEnvironment(t);
await wallet.runIntegrationTest({ await wallet.client.call(WalletApiOperation.RunIntegrationTest, {
amountToSpend: "TESTKUDOS:5", amountToSpend: "TESTKUDOS:5",
amountToWithdraw: "TESTKUDOS:10", amountToWithdraw: "TESTKUDOS:10",
bankBaseUrl: bank.baseUrl, bankBaseUrl: bank.baseUrl,
@ -123,7 +124,7 @@ export async function runWallettestingTest(t: GlobalTestState) {
merchantBaseUrl: merchant.makeInstanceBaseUrl(), merchantBaseUrl: merchant.makeInstanceBaseUrl(),
}); });
let txns = await wallet.getTransactions(); let txns = await wallet.client.call(WalletApiOperation.GetTransactions, {});
console.log(JSON.stringify(txns, undefined, 2)); console.log(JSON.stringify(txns, undefined, 2));
let txTypes = txns.transactions.map((x) => x.type); let txTypes = txns.transactions.map((x) => x.type);
@ -138,7 +139,7 @@ export async function runWallettestingTest(t: GlobalTestState) {
wallet.deleteDatabase(); wallet.deleteDatabase();
await wallet.withdrawTestBalance({ await wallet.client.call(WalletApiOperation.WithdrawTestBalance, {
amount: "TESTKUDOS:10", amount: "TESTKUDOS:10",
bankBaseUrl: bank.baseUrl, bankBaseUrl: bank.baseUrl,
exchangeBaseUrl: exchange.baseUrl, exchangeBaseUrl: exchange.baseUrl,
@ -146,7 +147,7 @@ export async function runWallettestingTest(t: GlobalTestState) {
await wallet.runUntilDone(); await wallet.runUntilDone();
await wallet.testPay({ await wallet.client.call(WalletApiOperation.TestPay, {
amount: "TESTKUDOS:5", amount: "TESTKUDOS:5",
merchantAuthToken: merchantAuthToken, merchantAuthToken: merchantAuthToken,
merchantBaseUrl: merchant.makeInstanceBaseUrl(), merchantBaseUrl: merchant.makeInstanceBaseUrl(),
@ -155,7 +156,7 @@ export async function runWallettestingTest(t: GlobalTestState) {
await wallet.runUntilDone(); await wallet.runUntilDone();
txns = await wallet.getTransactions(); txns = await wallet.client.call(WalletApiOperation.GetTransactions, {});
console.log(JSON.stringify(txns, undefined, 2)); console.log(JSON.stringify(txns, undefined, 2));
txTypes = txns.transactions.map((x) => x.type); txTypes = txns.transactions.map((x) => x.type);

View File

@ -18,6 +18,7 @@
* Imports. * Imports.
*/ */
import { TalerErrorCode } from "@gnu-taler/taler-util"; import { TalerErrorCode } from "@gnu-taler/taler-util";
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
import { GlobalTestState, BankApi, BankAccessApi } from "./harness"; import { GlobalTestState, BankApi, BankAccessApi } from "./harness";
import { createSimpleTestkudosEnvironment } from "./helpers"; import { createSimpleTestkudosEnvironment } from "./helpers";
@ -40,10 +41,9 @@ export async function runWithdrawalAbortBankTest(t: GlobalTestState) {
// Hand it to the wallet // Hand it to the wallet
const r1 = await wallet.apiRequest("getWithdrawalDetailsForUri", { await wallet.client.call(WalletApiOperation.GetWithdrawalDetailsForUri, {
talerWithdrawUri: wop.taler_withdraw_uri, talerWithdrawUri: wop.taler_withdraw_uri,
}); });
t.assertTrue(r1.type === "response");
await wallet.runPending(); await wallet.runPending();
@ -53,13 +53,17 @@ export async function runWithdrawalAbortBankTest(t: GlobalTestState) {
// Withdraw // Withdraw
const r2 = await wallet.apiRequest("acceptBankIntegratedWithdrawal", { const e = await t.assertThrowsOperationErrorAsync(async () => {
await wallet.client.call(
WalletApiOperation.AcceptBankIntegratedWithdrawal,
{
exchangeBaseUrl: exchange.baseUrl, exchangeBaseUrl: exchange.baseUrl,
talerWithdrawUri: wop.taler_withdraw_uri, talerWithdrawUri: wop.taler_withdraw_uri,
},
);
}); });
t.assertTrue(r2.type === "error"); t.assertDeepEqual(
t.assertTrue( e.operationError.code,
r2.error.code ===
TalerErrorCode.WALLET_WITHDRAWAL_OPERATION_ABORTED_BY_BANK, TalerErrorCode.WALLET_WITHDRAWAL_OPERATION_ABORTED_BY_BANK,
); );

View File

@ -20,6 +20,7 @@
import { GlobalTestState, BankApi, BankAccessApi } from "./harness"; import { GlobalTestState, BankApi, BankAccessApi } from "./harness";
import { createSimpleTestkudosEnvironment } from "./helpers"; import { createSimpleTestkudosEnvironment } from "./helpers";
import { codecForBalancesResponse } from "@gnu-taler/taler-util"; import { codecForBalancesResponse } from "@gnu-taler/taler-util";
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
/** /**
* Run test for basic, bank-integrated withdrawal. * Run test for basic, bank-integrated withdrawal.
@ -40,10 +41,9 @@ export async function runWithdrawalBankIntegratedTest(t: GlobalTestState) {
// Hand it to the wallet // Hand it to the wallet
const r1 = await wallet.apiRequest("getWithdrawalDetailsForUri", { const r1 = await wallet.client.call(WalletApiOperation.GetWithdrawalDetailsForUri, {
talerWithdrawUri: wop.taler_withdraw_uri, talerWithdrawUri: wop.taler_withdraw_uri,
}); });
t.assertTrue(r1.type === "response");
await wallet.runPending(); await wallet.runPending();
@ -53,18 +53,15 @@ export async function runWithdrawalBankIntegratedTest(t: GlobalTestState) {
// Withdraw // Withdraw
const r2 = await wallet.apiRequest("acceptBankIntegratedWithdrawal", { const r2 = await wallet.client.call(WalletApiOperation.AcceptBankIntegratedWithdrawal, {
exchangeBaseUrl: exchange.baseUrl, exchangeBaseUrl: exchange.baseUrl,
talerWithdrawUri: wop.taler_withdraw_uri, talerWithdrawUri: wop.taler_withdraw_uri,
}); });
t.assertTrue(r2.type === "response");
await wallet.runUntilDone(); await wallet.runUntilDone();
// Check balance // Check balance
const balApiResp = await wallet.apiRequest("getBalances", {}); const balResp = await wallet.client.call(WalletApiOperation.GetBalances, {});
t.assertTrue(balApiResp.type === "response");
const balResp = codecForBalancesResponse().decode(balApiResp.result);
t.assertAmountEquals("TESTKUDOS:9.72", balResp.balances[0].available); t.assertAmountEquals("TESTKUDOS:9.72", balResp.balances[0].available);
await t.shutdown(); await t.shutdown();

View File

@ -21,6 +21,7 @@ import { GlobalTestState, BankApi } from "./harness";
import { createSimpleTestkudosEnvironment } from "./helpers"; import { createSimpleTestkudosEnvironment } from "./helpers";
import { CoreApiResponse } from "@gnu-taler/taler-util"; import { CoreApiResponse } from "@gnu-taler/taler-util";
import { codecForBalancesResponse } from "@gnu-taler/taler-util"; import { codecForBalancesResponse } from "@gnu-taler/taler-util";
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
/** /**
* Run test for basic, bank-integrated withdrawal. * Run test for basic, bank-integrated withdrawal.
@ -41,20 +42,17 @@ export async function runTestWithdrawalManualTest(t: GlobalTestState) {
let wresp: CoreApiResponse; let wresp: CoreApiResponse;
wresp = await wallet.apiRequest("addExchange", { await wallet.client.call(WalletApiOperation.AddExchange, {
exchangeBaseUrl: exchange.baseUrl, exchangeBaseUrl: exchange.baseUrl,
}); });
t.assertTrue(wresp.type === "response");
wresp = await wallet.apiRequest("acceptManualWithdrawal", { const wres = await wallet.client.call(WalletApiOperation.AcceptManualWithdrawal, {
exchangeBaseUrl: exchange.baseUrl, exchangeBaseUrl: exchange.baseUrl,
amount: "TESTKUDOS:10", amount: "TESTKUDOS:10",
}); });
t.assertTrue(wresp.type === "response"); const reservePub: string = wres.reservePub;
const reservePub: string = (wresp.result as any).reservePub;
await BankApi.adminAddIncoming(bank, { await BankApi.adminAddIncoming(bank, {
exchangeBankAccount, exchangeBankAccount,
@ -69,9 +67,7 @@ export async function runTestWithdrawalManualTest(t: GlobalTestState) {
// Check balance // Check balance
const balApiResp = await wallet.apiRequest("getBalances", {}); const balResp = await wallet.client.call(WalletApiOperation.GetBalances, {});
t.assertTrue(balApiResp.type === "response");
const balResp = codecForBalancesResponse().decode(balApiResp.result);
t.assertAmountEquals("TESTKUDOS:9.72", balResp.balances[0].available); t.assertAmountEquals("TESTKUDOS:9.72", balResp.balances[0].available);
await t.shutdown(); await t.shutdown();

View File

@ -22,6 +22,7 @@
* Imports. * Imports.
*/ */
import { import {
AbortPayWithRefundRequest,
AcceptBankIntegratedWithdrawalRequest, AcceptBankIntegratedWithdrawalRequest,
AcceptExchangeTosRequest, AcceptExchangeTosRequest,
AcceptManualWithdrawalRequest, AcceptManualWithdrawalRequest,
@ -45,6 +46,7 @@ import {
GetExchangeTosResult, GetExchangeTosResult,
GetWithdrawalDetailsForAmountRequest, GetWithdrawalDetailsForAmountRequest,
GetWithdrawalDetailsForUriRequest, GetWithdrawalDetailsForUriRequest,
IntegrationTestArgs,
ManualWithdrawalDetails, ManualWithdrawalDetails,
PreparePayRequest, PreparePayRequest,
PreparePayResult, PreparePayResult,
@ -54,12 +56,14 @@ import {
RetryTransactionRequest, RetryTransactionRequest,
SetCoinSuspendedRequest, SetCoinSuspendedRequest,
SetWalletDeviceIdRequest, SetWalletDeviceIdRequest,
TestPayArgs,
TrackDepositGroupRequest, TrackDepositGroupRequest,
TrackDepositGroupResponse, TrackDepositGroupResponse,
TransactionsRequest, TransactionsRequest,
TransactionsResponse, TransactionsResponse,
WalletBackupContentV1, WalletBackupContentV1,
WalletCurrencyInfo, WalletCurrencyInfo,
WithdrawTestBalanceRequest,
WithdrawUriInfoResponse, WithdrawUriInfoResponse,
} from "@gnu-taler/taler-util"; } from "@gnu-taler/taler-util";
import { AddBackupProviderRequest, BackupInfo } from "./operations/backup"; import { AddBackupProviderRequest, BackupInfo } from "./operations/backup";
@ -85,7 +89,7 @@ export enum WalletApiOperation {
AcceptBankIntegratedWithdrawal = "acceptBankIntegratedWithdrawal", AcceptBankIntegratedWithdrawal = "acceptBankIntegratedWithdrawal",
GetExchangeTos = "getExchangeTos", GetExchangeTos = "getExchangeTos",
RetryPendingNow = "retryPendingNow", RetryPendingNow = "retryPendingNow",
PreparePay = "preparePay", AbortFailedPayWithRefund = "abortFailedPayWithRefund",
ConfirmPay = "confirmPay", ConfirmPay = "confirmPay",
DumpCoins = "dumpCoins", DumpCoins = "dumpCoins",
SetCoinSuspended = "setCoinSuspended", SetCoinSuspended = "setCoinSuspended",
@ -117,14 +121,14 @@ export type WalletOperations = {
request: {}; request: {};
response: {}; response: {};
}; };
[WalletApiOperation.PreparePay]: {
request: PreparePayRequest;
response: PreparePayResult;
};
[WalletApiOperation.ConfirmPay]: { [WalletApiOperation.ConfirmPay]: {
request: ConfirmPayRequest; request: ConfirmPayRequest;
response: ConfirmPayResult; response: ConfirmPayResult;
}; };
[WalletApiOperation.AbortFailedPayWithRefund]: {
request: AbortPayWithRefundRequest;
response: {};
};
[WalletApiOperation.GetBalances]: { [WalletApiOperation.GetBalances]: {
request: {}; request: {};
response: BalancesResponse; response: BalancesResponse;
@ -241,6 +245,18 @@ export type WalletOperations = {
request: {}; request: {};
response: BackupInfo; response: BackupInfo;
}; };
[WalletApiOperation.RunIntegrationTest]: {
request: IntegrationTestArgs;
response: {};
};
[WalletApiOperation.WithdrawTestBalance]: {
request: WithdrawTestBalanceRequest;
response: {};
};
[WalletApiOperation.TestPay]: {
request: TestPayArgs;
response: {};
}
}; };
export type RequestType< export type RequestType<

View File

@ -791,6 +791,8 @@ async function dispatchRequestInternal(
await runPending(ws, true); await runPending(ws, true);
return {}; return {};
} }
// FIXME: Deprecate one of the aliases!
case "preparePayForUri":
case "preparePay": { case "preparePay": {
const req = codecForPreparePayRequest().decode(payload); const req = codecForPreparePayRequest().decode(payload);
return await preparePayForUri(ws, req.talerPayUri); return await preparePayForUri(ws, req.talerPayUri);