aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-harness
diff options
context:
space:
mode:
Diffstat (limited to 'packages/taler-harness')
-rw-r--r--packages/taler-harness/src/harness/helpers.ts35
-rw-r--r--packages/taler-harness/src/integrationtests/test-peer-to-peer-pull.ts74
2 files changed, 91 insertions, 18 deletions
diff --git a/packages/taler-harness/src/harness/helpers.ts b/packages/taler-harness/src/harness/helpers.ts
index c1ce463fa..d203cc608 100644
--- a/packages/taler-harness/src/harness/helpers.ts
+++ b/packages/taler-harness/src/harness/helpers.ts
@@ -31,6 +31,7 @@ import {
PreparePayResultType,
NotificationType,
WithdrawalGroupFinishedNotification,
+ WalletNotification,
} from "@gnu-taler/taler-util";
import {
BankAccessApi,
@@ -297,7 +298,6 @@ export async function createSimpleTestkudosEnvironmentV2(
const walletService = new WalletService(t, {
name: "wallet",
- useInMemoryDb: true,
});
await walletService.start();
await walletService.pingUntilAvailable();
@@ -326,6 +326,39 @@ export async function createSimpleTestkudosEnvironmentV2(
};
}
+export interface CreateWalletArgs {
+ handleNotification?(wn: WalletNotification): void;
+ name: string;
+}
+
+export async function createWalletDaemonWithClient(
+ t: GlobalTestState,
+ args: CreateWalletArgs,
+): Promise<{ walletClient: WalletClient; walletService: WalletService }> {
+ const walletService = new WalletService(t, {
+ name: "wallet",
+ useInMemoryDb: true,
+ });
+ await walletService.start();
+ await walletService.pingUntilAvailable();
+
+ const walletClient = new WalletClient({
+ unixPath: walletService.socketPath,
+ onNotification(n) {
+ console.log("got notification", n);
+ if (args.handleNotification) {
+ args.handleNotification(n);
+ }
+ },
+ });
+ await walletClient.connect();
+ await walletClient.client.call(WalletApiOperation.InitWallet, {
+ skipDefaults: true,
+ });
+
+ return { walletClient, walletService };
+}
+
export interface FaultyMerchantTestEnvironment {
commonDb: DbInfo;
bank: BankService;
diff --git a/packages/taler-harness/src/integrationtests/test-peer-to-peer-pull.ts b/packages/taler-harness/src/integrationtests/test-peer-to-peer-pull.ts
index 0bab14578..58a1f271e 100644
--- a/packages/taler-harness/src/integrationtests/test-peer-to-peer-pull.ts
+++ b/packages/taler-harness/src/integrationtests/test-peer-to-peer-pull.ts
@@ -17,12 +17,21 @@
/**
* Imports.
*/
-import { AbsoluteTime, Duration, j2s } from "@gnu-taler/taler-util";
+import {
+ AbsoluteTime,
+ Duration,
+ j2s,
+ NotificationType,
+ WalletNotification,
+} from "@gnu-taler/taler-util";
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
import { GlobalTestState, WalletCli } from "../harness/harness.js";
import {
createSimpleTestkudosEnvironment,
+ createSimpleTestkudosEnvironmentV2,
+ createWalletDaemonWithClient,
withdrawViaBank,
+ withdrawViaBankV2,
} from "../harness/helpers.js";
/**
@@ -31,19 +40,40 @@ import {
export async function runPeerToPeerPullTest(t: GlobalTestState) {
// Set up test environment
- const { bank, exchange } = await createSimpleTestkudosEnvironment(t);
+ const { bank, exchange } = await createSimpleTestkudosEnvironmentV2(t);
+
+ let allW1Notifications: WalletNotification[] = [];
+ let allW2Notifications: WalletNotification[] = [];
+
+ const w1 = await createWalletDaemonWithClient(t, {
+ name: "w1",
+ handleNotification(wn) {
+ allW1Notifications.push(wn);
+ },
+ });
+ const w2 = await createWalletDaemonWithClient(t, {
+ name: "w2",
+ handleNotification(wn) {
+ allW2Notifications.push(wn);
+ },
+ });
// Withdraw digital cash into the wallet.
- const wallet1 = new WalletCli(t, "w1");
- const wallet2 = new WalletCli(t, "w2");
- await withdrawViaBank(t, {
- wallet: wallet2,
+ const wallet1 = w1.walletClient;
+ const wallet2 = w2.walletClient;
+
+ const withdrawalDoneCond = wallet2.waitForNotificationCond(
+ (x) => x.type === NotificationType.WithdrawGroupFinished,
+ );
+
+ await withdrawViaBankV2(t, {
+ walletClient: wallet2,
bank,
exchange,
amount: "TESTKUDOS:20",
});
- await wallet1.runUntilDone();
+ await withdrawalDoneCond;
const purse_expiration = AbsoluteTime.toTimestamp(
AbsoluteTime.addDuration(
@@ -52,6 +82,10 @@ export async function runPeerToPeerPullTest(t: GlobalTestState) {
),
);
+ const peerPullCreditReadyCond = wallet2.waitForNotificationCond(
+ (x) => x.type === NotificationType.PeerPullCreditReady,
+ );
+
const resp = await wallet1.client.call(
WalletApiOperation.InitiatePeerPullCredit,
{
@@ -64,9 +98,7 @@ export async function runPeerToPeerPullTest(t: GlobalTestState) {
},
);
- // Wait until the initiation is actually done.
- // FIXME: Use the daemonized wallet and notifications to know this
- await wallet1.runPending();
+ await peerPullCreditReadyCond;
const checkResp = await wallet2.client.call(
WalletApiOperation.PreparePeerPullDebit,
@@ -77,20 +109,23 @@ export async function runPeerToPeerPullTest(t: GlobalTestState) {
console.log(`checkResp: ${j2s(checkResp)}`);
- const acceptResp = await wallet2.client.call(
- WalletApiOperation.ConfirmPeerPullDebit,
- {
- peerPullPaymentIncomingId: checkResp.peerPullPaymentIncomingId,
- },
+ // FIXME: The wallet should emit a more appropriate notification here.
+ // Yes, it's technically a withdrawal.
+ const peerPullCreditDoneCond = wallet1.waitForNotificationCond(
+ (x) => x.type === NotificationType.WithdrawGroupFinished,
);
- await wallet1.runUntilDone();
- await wallet2.runUntilDone();
+ await wallet2.client.call(WalletApiOperation.ConfirmPeerPullDebit, {
+ peerPullPaymentIncomingId: checkResp.peerPullPaymentIncomingId,
+ });
+
+ await peerPullCreditDoneCond;
const txn1 = await wallet1.client.call(
WalletApiOperation.GetTransactions,
{},
);
+
const txn2 = await wallet2.client.call(
WalletApiOperation.GetTransactions,
{},
@@ -98,6 +133,11 @@ export async function runPeerToPeerPullTest(t: GlobalTestState) {
console.log(`txn1: ${j2s(txn1)}`);
console.log(`txn2: ${j2s(txn2)}`);
+
+ console.log(`w1 notifications: ${j2s(allW1Notifications)}`);
+
+ // Check that we don't have an excessive number of notifications.
+ t.assertTrue(allW1Notifications.length <= 60);
}
runPeerToPeerPullTest.suites = ["wallet"];