[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-wallet-core] branch master updated: fix preparePay bug and add in
From: |
gnunet |
Subject: |
[taler-wallet-core] branch master updated: fix preparePay bug and add integration test for it |
Date: |
Wed, 12 Aug 2020 13:02:13 +0200 |
This is an automated email from the git hooks/post-receive script.
dold pushed a commit to branch master
in repository wallet-core.
The following commit(s) were added to refs/heads/master by this push:
new 11fa3397 fix preparePay bug and add integration test for it
11fa3397 is described below
commit 11fa3397053c16cfcbf594c1389a75eaad94a40e
Author: Florian Dold <florian.dold@gmail.com>
AuthorDate: Wed Aug 12 16:32:07 2020 +0530
fix preparePay bug and add integration test for it
---
packages/taler-integrationtests/src/harness.ts | 11 ++++++--
...test-payment.ts => test-payment-idempotency.ts} | 31 +++++++++++++++++++---
.../taler-integrationtests/src/test-payment.ts | 8 +++---
packages/taler-wallet-core/src/operations/pay.ts | 8 +++---
.../taler-wallet-core/src/types/walletTypes.ts | 9 +++++++
5 files changed, 54 insertions(+), 13 deletions(-)
diff --git a/packages/taler-integrationtests/src/harness.ts
b/packages/taler-integrationtests/src/harness.ts
index ecb0758d..e8a0941d 100644
--- a/packages/taler-integrationtests/src/harness.ts
+++ b/packages/taler-integrationtests/src/harness.ts
@@ -41,6 +41,9 @@ import {
CoreApiResponse,
PreparePayResult,
PreparePayRequest,
+ codecForPreparePayResultPaymentPossible,
+ codecForPreparePayResult,
+ OperationFailedError,
} from "taler-wallet-core";
import { URL } from "url";
import axios from "axios";
@@ -1111,7 +1114,7 @@ export class WalletCli {
async apiRequest(
request: string,
- payload: Record<string, unknown>,
+ payload: unknown,
): Promise<CoreApiResponse> {
const wdb = this.globalTestState.testDir + "/walletdb.json";
const resp = await sh(
@@ -1144,6 +1147,10 @@ export class WalletCli {
}
async preparePay(req: PreparePayRequest): Promise<PreparePayResult> {
- throw Error("not implemented");
+ const resp = await this.apiRequest("preparePay", req);
+ if (resp.type === "response") {
+ return codecForPreparePayResult().decode(resp.result);
+ }
+ throw new OperationFailedError(resp.error);
}
}
diff --git a/packages/taler-integrationtests/src/test-payment.ts
b/packages/taler-integrationtests/src/test-payment-idempotency.ts
similarity index 69%
copy from packages/taler-integrationtests/src/test-payment.ts
copy to packages/taler-integrationtests/src/test-payment-idempotency.ts
index 3fd87958..4d672771 100644
--- a/packages/taler-integrationtests/src/test-payment.ts
+++ b/packages/taler-integrationtests/src/test-payment-idempotency.ts
@@ -19,9 +19,11 @@
*/
import { runTest, GlobalTestState } from "./harness";
import { createSimpleTestkudosEnvironment, withdrawViaBank } from "./helpers";
+import { PreparePayResultType } from "taler-wallet-core";
/**
- * Run test for basic, bank-integrated withdrawal.
+ * Test the wallet-core payment API, especially that repeated operations
+ * return the expected result.
*/
runTest(async (t: GlobalTestState) => {
// Set up test environment
@@ -54,16 +56,30 @@ runTest(async (t: GlobalTestState) => {
t.assertTrue(orderStatus.order_status === "unpaid");
+ const talerPayUri = orderStatus.taler_pay_uri;
+
// Make wallet pay for the order
- const r1 = await wallet.apiRequest("preparePay", {
+ const preparePayResult = await wallet.preparePay({
+ talerPayUri: orderStatus.taler_pay_uri,
+ });
+
+ const preparePayResultRep = await wallet.preparePay({
talerPayUri: orderStatus.taler_pay_uri,
});
- t.assertTrue(r1.type === "response");
+
+ t.assertTrue(
+ preparePayResult.status === PreparePayResultType.PaymentPossible,
+ );
+ t.assertTrue(
+ preparePayResultRep.status === PreparePayResultType.PaymentPossible,
+ );
+
+ const proposalId = preparePayResult.proposalId;
const r2 = await wallet.apiRequest("confirmPay", {
// FIXME: should be validated, don't cast!
- proposalId: (r1.result as any).proposalId,
+ proposalId: proposalId,
});
t.assertTrue(r2.type === "response");
@@ -76,5 +92,12 @@ runTest(async (t: GlobalTestState) => {
t.assertTrue(orderStatus.order_status === "paid");
+ const preparePayResultAfter = await wallet.preparePay({
+ talerPayUri,
+ });
+
+ t.assertTrue(preparePayResultAfter.status ===
PreparePayResultType.AlreadyConfirmed);
+ t.assertTrue(preparePayResultAfter.paid === true);
+
await t.shutdown();
});
diff --git a/packages/taler-integrationtests/src/test-payment.ts
b/packages/taler-integrationtests/src/test-payment.ts
index 3fd87958..77645909 100644
--- a/packages/taler-integrationtests/src/test-payment.ts
+++ b/packages/taler-integrationtests/src/test-payment.ts
@@ -19,6 +19,7 @@
*/
import { runTest, GlobalTestState } from "./harness";
import { createSimpleTestkudosEnvironment, withdrawViaBank } from "./helpers";
+import { PreparePayResultType } from "taler-wallet-core";
/**
* Run test for basic, bank-integrated withdrawal.
@@ -56,14 +57,15 @@ runTest(async (t: GlobalTestState) => {
// Make wallet pay for the order
- const r1 = await wallet.apiRequest("preparePay", {
+ const preparePayResult = await wallet.preparePay({
talerPayUri: orderStatus.taler_pay_uri,
});
- t.assertTrue(r1.type === "response");
+
+ t.assertTrue(preparePayResult.status ===
PreparePayResultType.PaymentPossible);
const r2 = await wallet.apiRequest("confirmPay", {
// FIXME: should be validated, don't cast!
- proposalId: (r1.result as any).proposalId,
+ proposalId: preparePayResult.proposalId,
});
t.assertTrue(r2.type === "response");
diff --git a/packages/taler-wallet-core/src/operations/pay.ts
b/packages/taler-wallet-core/src/operations/pay.ts
index db5a56d1..0576f7ea 100644
--- a/packages/taler-wallet-core/src/operations/pay.ts
+++ b/packages/taler-wallet-core/src/operations/pay.ts
@@ -980,17 +980,17 @@ export async function preparePayForUri(
amountRaw: Amounts.stringify(purchase.contractData.amount),
amountEffective: Amounts.stringify(purchase.payCostInfo.totalCost),
};
- } else if (purchase.paymentSubmitPending) {
+ } else {
+ const paid = !purchase.paymentSubmitPending;
return {
status: PreparePayResultType.AlreadyConfirmed,
contractTerms: JSON.parse(purchase.contractTermsRaw),
- paid: false,
+ paid,
amountRaw: Amounts.stringify(purchase.contractData.amount),
amountEffective: Amounts.stringify(purchase.payCostInfo.totalCost),
+ ...(paid ? { nextUrl: purchase.contractData.orderId } : {}),
};
}
- // FIXME: we don't handle aborted payments correctly here.
- throw Error("BUG: invariant violation (purchase status)");
}
/**
diff --git a/packages/taler-wallet-core/src/types/walletTypes.ts
b/packages/taler-wallet-core/src/types/walletTypes.ts
index 7a648dd5..ec57e7d2 100644
--- a/packages/taler-wallet-core/src/types/walletTypes.ts
+++ b/packages/taler-wallet-core/src/types/walletTypes.ts
@@ -48,6 +48,7 @@ import {
codecForBoolean,
codecForConstString,
codecForAny,
+ buildCodecForUnion,
} from "../util/codec";
import { AmountString, codecForContractTerms } from "./talerTypes";
import { TransactionError } from "./transactions";
@@ -399,6 +400,14 @@ export const codecForPreparePayResultAlreadyConfirmed =
(): Codec<
.property("contractTerms", codecForAny())
.build("PreparePayResultAlreadyConfirmed");
+export const codecForPreparePayResult = (): Codec<PreparePayResult> =>
+ buildCodecForUnion<PreparePayResult>()
+ .discriminateOn("status")
+ .alternative(PreparePayResultType.AlreadyConfirmed,
codecForPreparePayResultAlreadyConfirmed())
+ .alternative(PreparePayResultType.InsufficientBalance,
codecForPreparePayResultInsufficientBalance())
+ .alternative(PreparePayResultType.PaymentPossible,
codecForPreparePayResultPaymentPossible())
+ .build("PreparePayResult");
+
export type PreparePayResult =
| PreparePayResultInsufficientBalance
| PreparePayResultAlreadyConfirmed
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [taler-wallet-core] branch master updated: fix preparePay bug and add integration test for it,
gnunet <=