harness: fix/modernize peer-to-peer-push
This commit is contained in:
parent
7dcfd02dae
commit
9f8faed2d1
@ -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> {
|
||||
|
@ -17,35 +17,55 @@
|
||||
/**
|
||||
* Imports.
|
||||
*/
|
||||
import { AbsoluteTime, Duration, j2s } from "@gnu-taler/taler-util";
|
||||
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
|
||||
import { GlobalTestState, WalletCli } from "../harness/harness.js";
|
||||
import {
|
||||
createSimpleTestkudosEnvironment,
|
||||
withdrawViaBank,
|
||||
AbsoluteTime,
|
||||
Duration,
|
||||
NotificationType,
|
||||
TransactionMajorState,
|
||||
TransactionMinorState,
|
||||
WalletNotification,
|
||||
j2s,
|
||||
} from "@gnu-taler/taler-util";
|
||||
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
|
||||
import { GlobalTestState } from "../harness/harness.js";
|
||||
import {
|
||||
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",
|
||||
|
Loading…
Reference in New Issue
Block a user