aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-harness/src/harness
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2023-07-01 01:43:29 +0200
committerFlorian Dold <florian@dold.me>2023-07-01 01:43:29 +0200
commit5695ae0a9f469ddbcd86e675f8f74b30032be457 (patch)
treedaf5f7de0d9c3549ac9acf6dde4189a2ddbe3ec9 /packages/taler-harness/src/harness
parentf93ab03a1b946af441e35b9c057f129d25311273 (diff)
downloadwallet-core-5695ae0a9f469ddbcd86e675f8f74b30032be457.tar.xz
wallet-core: use testingWaitTransactionsFinal to wait for transactions
Diffstat (limited to 'packages/taler-harness/src/harness')
-rw-r--r--packages/taler-harness/src/harness/harness.ts32
-rw-r--r--packages/taler-harness/src/harness/helpers.ts70
2 files changed, 101 insertions, 1 deletions
diff --git a/packages/taler-harness/src/harness/harness.ts b/packages/taler-harness/src/harness/harness.ts
index 7b2f980cc..1120eae84 100644
--- a/packages/taler-harness/src/harness/harness.ts
+++ b/packages/taler-harness/src/harness/harness.ts
@@ -41,17 +41,21 @@ import {
Logger,
MerchantReserveCreateConfirmation,
MerchantTemplateAddDetails,
+ NotificationType,
parsePaytoUri,
stringToBytes,
TalerError,
TalerProtocolDuration,
+ TransactionMajorState,
WalletNotification,
} from "@gnu-taler/taler-util";
import {
BankApi,
BankServiceHandle,
HarnessExchangeBankAccount,
+ OpenedPromise,
openPromise,
+ WalletApiOperation,
WalletCoreApiClient,
WalletCoreRequestType,
WalletCoreResponseType,
@@ -934,7 +938,12 @@ export class FakebankService
);
await this.pingUntilAvailable();
for (const acc of this.accounts) {
- await BankApi.registerAccount(this, acc.accountName, acc.accountPassword, {});
+ await BankApi.registerAccount(
+ this,
+ acc.accountName,
+ acc.accountPassword,
+ {},
+ );
}
}
@@ -2246,9 +2255,26 @@ export interface WalletClientArgs {
onNotification?(n: WalletNotification): void;
}
+export type CancelFn = () => void;
+export type NotificationHandler = (n: WalletNotification) => void;
+
+/**
+ * Convenience wrapper around a (remote) wallet handle.
+ */
export class WalletClient {
remoteWallet: RemoteWallet | undefined = undefined;
private waiter: WalletNotificationWaiter = makeNotificationWaiter();
+ notificationHandlers: NotificationHandler[] = [];
+
+ addNotificationListener(f: NotificationHandler): CancelFn {
+ this.notificationHandlers.push(f);
+ return () => {
+ const idx = this.notificationHandlers.indexOf(f);
+ if (idx >= 0) {
+ this.notificationHandlers.splice(idx, 1);
+ }
+ };
+ }
async call<Op extends keyof WalletOperations>(
operation: Op,
@@ -2260,6 +2286,7 @@ export class WalletClient {
const client = getClientFromRemoteWallet(this.remoteWallet);
return client.call(operation, payload);
}
+
constructor(private args: WalletClientArgs) {}
async connect(): Promise<void> {
@@ -2272,6 +2299,9 @@ export class WalletClient {
walletClient.args.onNotification(n);
}
waiter.notify(n);
+ for (const h of walletClient.notificationHandlers) {
+ h(n);
+ }
},
});
this.remoteWallet = w;
diff --git a/packages/taler-harness/src/harness/helpers.ts b/packages/taler-harness/src/harness/helpers.ts
index fd6e9aa2e..8c62aef37 100644
--- a/packages/taler-harness/src/harness/helpers.ts
+++ b/packages/taler-harness/src/harness/helpers.ts
@@ -689,3 +689,73 @@ export async function makeTestPayment(
t.assertTrue(orderStatus.order_status === "paid");
}
+
+/**
+ * Make a simple payment and check that it succeeded.
+ */
+export async function makeTestPaymentV2(
+ t: GlobalTestState,
+ args: {
+ merchant: MerchantServiceInterface;
+ walletClient: WalletClient;
+ order: Partial<MerchantContractTerms>;
+ instance?: string;
+ },
+ auth: WithAuthorization = {},
+): Promise<void> {
+ // Set up order.
+
+ const { walletClient, merchant } = args;
+ const instance = args.instance ?? "default";
+
+ const orderResp = await MerchantPrivateApi.createOrder(
+ merchant,
+ instance,
+ {
+ order: args.order,
+ },
+ auth,
+ );
+
+ let orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(
+ merchant,
+ {
+ orderId: orderResp.order_id,
+ },
+ auth,
+ );
+
+ t.assertTrue(orderStatus.order_status === "unpaid");
+
+ // Make wallet pay for the order
+
+ const preparePayResult = await walletClient.call(
+ WalletApiOperation.PreparePayForUri,
+ {
+ talerPayUri: orderStatus.taler_pay_uri,
+ },
+ );
+
+ t.assertTrue(
+ preparePayResult.status === PreparePayResultType.PaymentPossible,
+ );
+
+ const r2 = await walletClient.call(WalletApiOperation.ConfirmPay, {
+ proposalId: preparePayResult.proposalId,
+ });
+
+ t.assertTrue(r2.type === ConfirmPayResultType.Done);
+
+ // Check if payment was successful.
+
+ orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(
+ merchant,
+ {
+ orderId: orderResp.order_id,
+ instance,
+ },
+ auth,
+ );
+
+ t.assertTrue(orderStatus.order_status === "paid");
+}