summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2023-06-21 08:17:25 +0200
committerFlorian Dold <florian@dold.me>2023-06-21 08:17:25 +0200
commit9f8faed2d170a37efa0328e42c83e6e5717bf06c (patch)
tree6e6021dfe58a22aa8c4a56a097b1018fe69c674b
parent7dcfd02dae23fe2a6249893ae19ab59b8b5a09f5 (diff)
downloadwallet-core-9f8faed2d170a37efa0328e42c83e6e5717bf06c.tar.gz
wallet-core-9f8faed2d170a37efa0328e42c83e6e5717bf06c.tar.bz2
wallet-core-9f8faed2d170a37efa0328e42c83e6e5717bf06c.zip
harness: fix/modernize peer-to-peer-push
-rw-r--r--packages/taler-harness/src/harness/harness.ts13
-rw-r--r--packages/taler-harness/src/integrationtests/test-peer-to-peer-push.ts72
2 files changed, 63 insertions, 22 deletions
diff --git a/packages/taler-harness/src/harness/harness.ts b/packages/taler-harness/src/harness/harness.ts
index a2ff451d8..7b2f980cc 100644
--- a/packages/taler-harness/src/harness/harness.ts
+++ b/packages/taler-harness/src/harness/harness.ts
@@ -53,6 +53,9 @@ import {
HarnessExchangeBankAccount,
openPromise,
WalletCoreApiClient,
+ WalletCoreRequestType,
+ WalletCoreResponseType,
+ WalletOperations,
} from "@gnu-taler/taler-wallet-core";
import { deepStrictEqual } from "assert";
import axiosImp, { AxiosError } from "axios";
@@ -2247,6 +2250,16 @@ export class WalletClient {
remoteWallet: RemoteWallet | undefined = undefined;
private waiter: WalletNotificationWaiter = makeNotificationWaiter();
+ async call<Op extends keyof WalletOperations>(
+ operation: Op,
+ payload: WalletCoreRequestType<Op>,
+ ): Promise<WalletCoreResponseType<Op>> {
+ if (!this.remoteWallet) {
+ throw Error("wallet not connected");
+ }
+ const client = getClientFromRemoteWallet(this.remoteWallet);
+ return client.call(operation, payload);
+ }
constructor(private args: WalletClientArgs) {}
async connect(): Promise<void> {
diff --git a/packages/taler-harness/src/integrationtests/test-peer-to-peer-push.ts b/packages/taler-harness/src/integrationtests/test-peer-to-peer-push.ts
index b179f6722..4817b572a 100644
--- a/packages/taler-harness/src/integrationtests/test-peer-to-peer-push.ts
+++ b/packages/taler-harness/src/integrationtests/test-peer-to-peer-push.ts
@@ -17,35 +17,55 @@
/**
* Imports.
*/
-import { AbsoluteTime, Duration, j2s } from "@gnu-taler/taler-util";
+import {
+ AbsoluteTime,
+ Duration,
+ NotificationType,
+ TransactionMajorState,
+ TransactionMinorState,
+ WalletNotification,
+ j2s,
+} from "@gnu-taler/taler-util";
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
-import { GlobalTestState, WalletCli } from "../harness/harness.js";
+import { GlobalTestState } from "../harness/harness.js";
import {
- createSimpleTestkudosEnvironment,
- withdrawViaBank,
+ createSimpleTestkudosEnvironmentV2,
+ createWalletDaemonWithClient,
+ withdrawViaBankV2,
} from "../harness/helpers.js";
/**
- * Run test for basic, bank-integrated withdrawal and payment.
+ * Run a test for basic peer-push payments.
*/
export async function runPeerToPeerPushTest(t: GlobalTestState) {
- // Set up test environment
+ const { bank, exchange } = await createSimpleTestkudosEnvironmentV2(t);
- const { bank, exchange } = await createSimpleTestkudosEnvironment(t);
+ let allW1Notifications: WalletNotification[] = [];
+ let allW2Notifications: WalletNotification[] = [];
- const wallet1 = new WalletCli(t, "w1");
- const wallet2 = new WalletCli(t, "w2");
+ 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.
- await withdrawViaBank(t, {
- wallet: wallet1,
+ const withdrawRes = await withdrawViaBankV2(t, {
+ walletClient: w1.walletClient,
bank,
exchange,
amount: "TESTKUDOS:20",
});
- await wallet1.runUntilDone();
+ await withdrawRes.withdrawalFinishedCond;
const purse_expiration = AbsoluteTime.toProtocolTimestamp(
AbsoluteTime.addDuration(
@@ -55,7 +75,7 @@ export async function runPeerToPeerPushTest(t: GlobalTestState) {
);
{
- const resp = await wallet1.client.call(
+ const resp = await w1.walletClient.call(
WalletApiOperation.InitiatePeerPushDebit,
{
partialContractTerms: {
@@ -68,7 +88,8 @@ export async function runPeerToPeerPushTest(t: GlobalTestState) {
console.log(resp);
}
- const resp = await wallet1.client.call(
+
+ const resp = await w1.walletClient.call(
WalletApiOperation.InitiatePeerPushDebit,
{
partialContractTerms: {
@@ -81,7 +102,17 @@ export async function runPeerToPeerPushTest(t: GlobalTestState) {
console.log(resp);
- const checkResp = await wallet2.client.call(
+ const peerPushReadyCond = w1.walletClient.waitForNotificationCond(
+ (x) =>
+ x.type === NotificationType.TransactionStateTransition &&
+ x.newTxState.major === TransactionMajorState.Pending &&
+ x.newTxState.minor === TransactionMinorState.Ready &&
+ x.transactionId === resp.transactionId,
+ );
+
+ await peerPushReadyCond;
+
+ const checkResp = await w2.walletClient.call(
WalletApiOperation.PreparePeerPushCredit,
{
talerUri: resp.talerUri,
@@ -90,7 +121,7 @@ export async function runPeerToPeerPushTest(t: GlobalTestState) {
console.log(checkResp);
- const acceptResp = await wallet2.client.call(
+ const acceptResp = await w2.walletClient.call(
WalletApiOperation.ConfirmPeerPushCredit,
{
peerPushPaymentIncomingId: checkResp.peerPushPaymentIncomingId,
@@ -99,14 +130,11 @@ export async function runPeerToPeerPushTest(t: GlobalTestState) {
console.log(acceptResp);
- await wallet1.runUntilDone();
- await wallet2.runUntilDone();
-
- const txn1 = await wallet1.client.call(
+ const txn1 = await w1.walletClient.call(
WalletApiOperation.GetTransactions,
{},
);
- const txn2 = await wallet2.client.call(
+ const txn2 = await w2.walletClient.call(
WalletApiOperation.GetTransactions,
{},
);
@@ -115,7 +143,7 @@ export async function runPeerToPeerPushTest(t: GlobalTestState) {
console.log(`txn2: ${j2s(txn2)}`);
const ex1 = await t.assertThrowsTalerErrorAsync(async () => {
- await wallet1.client.call(WalletApiOperation.InitiatePeerPushDebit, {
+ await w1.walletClient.call(WalletApiOperation.InitiatePeerPushDebit, {
partialContractTerms: {
summary: "(this will fail)",
amount: "TESTKUDOS:15",