commit d25d762c4217b4e44ea7f62a918d59fd2d1894dd
parent 09e3ada3923999266aa82e3ec807b0acef7eb975
Author: Iván Ávalos <avalos@disroot.org>
Date: Wed, 23 Apr 2025 19:08:45 +0200
harness: extend share idemporency test
Diffstat:
1 file changed, 93 insertions(+), 5 deletions(-)
diff --git a/packages/taler-harness/src/integrationtests/test-payment-share-idempotency.ts b/packages/taler-harness/src/integrationtests/test-payment-share-idempotency.ts
@@ -107,9 +107,10 @@ export async function runPaymentShareIdempotencyTest(t: GlobalTestState) {
t.logStep("orders-created");
/**
- * Case 1:
- * - Claim with first wallet and pay in the second wallet.
- * - First wallet should be notified.
+ * Scenario A (a)
+ * - Claim with first wallet, don't confirm.
+ * - Claim shared URI with second wallet, don't confirm.
+ * - Claim with second wallet again, should still be able to confirm.
*/
{
const order = await createOrder("TESTKUDOS:5");
@@ -148,9 +149,21 @@ export async function runPaymentShareIdempotencyTest(t: GlobalTestState) {
t.logStep("w2-claimed");
+ // claim from the second wallet (again)
+ const claimSecondWalletAgain = await secondWallet.call(
+ WalletApiOperation.PreparePayForUri,
+ { talerPayUri: privatePayUri },
+ );
+
+ t.assertTrue(
+ claimSecondWallet.status === PreparePayResultType.PaymentPossible,
+ );
+
+ t.logStep("w2-claimed-again");
+
// pay from the second wallet
const r2 = await secondWallet.call(WalletApiOperation.ConfirmPay, {
- transactionId: claimSecondWallet.transactionId,
+ transactionId: claimSecondWalletAgain.transactionId,
});
t.assertTrue(r2.type === ConfirmPayResultType.Done);
@@ -176,6 +189,81 @@ export async function runPaymentShareIdempotencyTest(t: GlobalTestState) {
}
t.logStep("wait-for-payment");
+ }
+
+ t.logStep("scenario-a-a-done");
+
+ /**
+ * Scenario A (b)
+ * - Claim with first wallet, don't confirm.
+ * - Claim shared URI with second wallet, confirm.
+ * - Claim with second wallet again, tx should transition to `done`.
+ */
+ {
+ const order = await createOrder("TESTKUDOS:5");
+ // Claim the order with the first wallet
+ const claimFirstWallet = await firstWallet.call(
+ WalletApiOperation.PreparePayForUri,
+ { talerPayUri: order.uri },
+ );
+
+ t.assertTrue(
+ claimFirstWallet.status === PreparePayResultType.PaymentPossible,
+ );
+
+ t.logStep("w1-payment-possible");
+
+ // share order from the first wallet
+ const { privatePayUri } = await firstWallet.call(
+ WalletApiOperation.SharePayment,
+ {
+ merchantBaseUrl: merchant.makeInstanceBaseUrl(),
+ orderId: order.id,
+ },
+ );
+
+ t.logStep("w1-payment-shared");
+
+ // claim from the second wallet
+ const claimSecondWallet = await secondWallet.call(
+ WalletApiOperation.PreparePayForUri,
+ { talerPayUri: privatePayUri },
+ );
+
+ t.assertTrue(
+ claimSecondWallet.status === PreparePayResultType.PaymentPossible,
+ );
+
+ t.logStep("w2-claimed");
+
+ // pay from the second wallet
+ const r2 = await secondWallet.call(WalletApiOperation.ConfirmPay, {
+ transactionId: claimSecondWallet.transactionId,
+ });
+
+ t.assertTrue(r2.type === ConfirmPayResultType.Done);
+
+ t.logStep("w2-confirmed");
+
+ // Wait for refresh to settle before we do checks
+ await secondWallet.call(
+ WalletApiOperation.TestingWaitTransactionsFinal,
+ {},
+ );
+
+ t.logStep("w2-refresh-settled");
+
+ {
+ const first = await firstWallet.call(WalletApiOperation.GetBalances, {});
+ const second = await secondWallet.call(
+ WalletApiOperation.GetBalances,
+ {},
+ );
+ t.assertAmountEquals(first.balances[0].available, "TESTKUDOS:19.53");
+ t.assertAmountEquals(second.balances[0].available, "TESTKUDOS:8.95");
+ }
+
+ t.logStep("wait-for-payment");
// claim from the second wallet (again)
const claimSecondWalletAgain = await secondWallet.call(
@@ -195,7 +283,7 @@ export async function runPaymentShareIdempotencyTest(t: GlobalTestState) {
});
}
- t.logStep("second-case-done");
+ t.logStep("scenario-a-b-done");
}
runPaymentShareIdempotencyTest.suites = ["wallet"];