harness: improve peer-pull integration test, check notifications
This commit is contained in:
parent
a3c7da975b
commit
b648238c41
@ -31,6 +31,7 @@ import {
|
|||||||
PreparePayResultType,
|
PreparePayResultType,
|
||||||
NotificationType,
|
NotificationType,
|
||||||
WithdrawalGroupFinishedNotification,
|
WithdrawalGroupFinishedNotification,
|
||||||
|
WalletNotification,
|
||||||
} from "@gnu-taler/taler-util";
|
} from "@gnu-taler/taler-util";
|
||||||
import {
|
import {
|
||||||
BankAccessApi,
|
BankAccessApi,
|
||||||
@ -297,7 +298,6 @@ export async function createSimpleTestkudosEnvironmentV2(
|
|||||||
|
|
||||||
const walletService = new WalletService(t, {
|
const walletService = new WalletService(t, {
|
||||||
name: "wallet",
|
name: "wallet",
|
||||||
useInMemoryDb: true,
|
|
||||||
});
|
});
|
||||||
await walletService.start();
|
await walletService.start();
|
||||||
await walletService.pingUntilAvailable();
|
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 {
|
export interface FaultyMerchantTestEnvironment {
|
||||||
commonDb: DbInfo;
|
commonDb: DbInfo;
|
||||||
bank: BankService;
|
bank: BankService;
|
||||||
|
@ -17,12 +17,21 @@
|
|||||||
/**
|
/**
|
||||||
* Imports.
|
* 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 { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
|
||||||
import { GlobalTestState, WalletCli } from "../harness/harness.js";
|
import { GlobalTestState, WalletCli } from "../harness/harness.js";
|
||||||
import {
|
import {
|
||||||
createSimpleTestkudosEnvironment,
|
createSimpleTestkudosEnvironment,
|
||||||
|
createSimpleTestkudosEnvironmentV2,
|
||||||
|
createWalletDaemonWithClient,
|
||||||
withdrawViaBank,
|
withdrawViaBank,
|
||||||
|
withdrawViaBankV2,
|
||||||
} from "../harness/helpers.js";
|
} from "../harness/helpers.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -31,19 +40,40 @@ import {
|
|||||||
export async function runPeerToPeerPullTest(t: GlobalTestState) {
|
export async function runPeerToPeerPullTest(t: GlobalTestState) {
|
||||||
// Set up test environment
|
// 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.
|
// Withdraw digital cash into the wallet.
|
||||||
const wallet1 = new WalletCli(t, "w1");
|
const wallet1 = w1.walletClient;
|
||||||
const wallet2 = new WalletCli(t, "w2");
|
const wallet2 = w2.walletClient;
|
||||||
await withdrawViaBank(t, {
|
|
||||||
wallet: wallet2,
|
const withdrawalDoneCond = wallet2.waitForNotificationCond(
|
||||||
|
(x) => x.type === NotificationType.WithdrawGroupFinished,
|
||||||
|
);
|
||||||
|
|
||||||
|
await withdrawViaBankV2(t, {
|
||||||
|
walletClient: wallet2,
|
||||||
bank,
|
bank,
|
||||||
exchange,
|
exchange,
|
||||||
amount: "TESTKUDOS:20",
|
amount: "TESTKUDOS:20",
|
||||||
});
|
});
|
||||||
|
|
||||||
await wallet1.runUntilDone();
|
await withdrawalDoneCond;
|
||||||
|
|
||||||
const purse_expiration = AbsoluteTime.toTimestamp(
|
const purse_expiration = AbsoluteTime.toTimestamp(
|
||||||
AbsoluteTime.addDuration(
|
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(
|
const resp = await wallet1.client.call(
|
||||||
WalletApiOperation.InitiatePeerPullCredit,
|
WalletApiOperation.InitiatePeerPullCredit,
|
||||||
{
|
{
|
||||||
@ -64,9 +98,7 @@ export async function runPeerToPeerPullTest(t: GlobalTestState) {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
// Wait until the initiation is actually done.
|
await peerPullCreditReadyCond;
|
||||||
// FIXME: Use the daemonized wallet and notifications to know this
|
|
||||||
await wallet1.runPending();
|
|
||||||
|
|
||||||
const checkResp = await wallet2.client.call(
|
const checkResp = await wallet2.client.call(
|
||||||
WalletApiOperation.PreparePeerPullDebit,
|
WalletApiOperation.PreparePeerPullDebit,
|
||||||
@ -77,20 +109,23 @@ export async function runPeerToPeerPullTest(t: GlobalTestState) {
|
|||||||
|
|
||||||
console.log(`checkResp: ${j2s(checkResp)}`);
|
console.log(`checkResp: ${j2s(checkResp)}`);
|
||||||
|
|
||||||
const acceptResp = await wallet2.client.call(
|
// FIXME: The wallet should emit a more appropriate notification here.
|
||||||
WalletApiOperation.ConfirmPeerPullDebit,
|
// Yes, it's technically a withdrawal.
|
||||||
{
|
const peerPullCreditDoneCond = wallet1.waitForNotificationCond(
|
||||||
peerPullPaymentIncomingId: checkResp.peerPullPaymentIncomingId,
|
(x) => x.type === NotificationType.WithdrawGroupFinished,
|
||||||
},
|
|
||||||
);
|
);
|
||||||
|
|
||||||
await wallet1.runUntilDone();
|
await wallet2.client.call(WalletApiOperation.ConfirmPeerPullDebit, {
|
||||||
await wallet2.runUntilDone();
|
peerPullPaymentIncomingId: checkResp.peerPullPaymentIncomingId,
|
||||||
|
});
|
||||||
|
|
||||||
|
await peerPullCreditDoneCond;
|
||||||
|
|
||||||
const txn1 = await wallet1.client.call(
|
const txn1 = await wallet1.client.call(
|
||||||
WalletApiOperation.GetTransactions,
|
WalletApiOperation.GetTransactions,
|
||||||
{},
|
{},
|
||||||
);
|
);
|
||||||
|
|
||||||
const txn2 = await wallet2.client.call(
|
const txn2 = await wallet2.client.call(
|
||||||
WalletApiOperation.GetTransactions,
|
WalletApiOperation.GetTransactions,
|
||||||
{},
|
{},
|
||||||
@ -98,6 +133,11 @@ export async function runPeerToPeerPullTest(t: GlobalTestState) {
|
|||||||
|
|
||||||
console.log(`txn1: ${j2s(txn1)}`);
|
console.log(`txn1: ${j2s(txn1)}`);
|
||||||
console.log(`txn2: ${j2s(txn2)}`);
|
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"];
|
runPeerToPeerPullTest.suites = ["wallet"];
|
||||||
|
@ -65,6 +65,7 @@ export enum NotificationType {
|
|||||||
WithdrawalGroupKycRequested = "withdrawal-group-kyc-requested",
|
WithdrawalGroupKycRequested = "withdrawal-group-kyc-requested",
|
||||||
WithdrawalGroupBankConfirmed = "withdrawal-group-bank-confirmed",
|
WithdrawalGroupBankConfirmed = "withdrawal-group-bank-confirmed",
|
||||||
WithdrawalGroupReserveReady = "withdrawal-group-reserve-ready",
|
WithdrawalGroupReserveReady = "withdrawal-group-reserve-ready",
|
||||||
|
PeerPullCreditReady = "peer-pull-credit-ready",
|
||||||
DepositOperationError = "deposit-operation-error",
|
DepositOperationError = "deposit-operation-error",
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,11 +136,20 @@ export interface WithdrawalGroupBankConfirmed {
|
|||||||
transactionId: string;
|
transactionId: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface WithdrawalGroupReserveReady {
|
export interface WithdrawalGroupReserveReadyNotification {
|
||||||
type: NotificationType.WithdrawalGroupReserveReady;
|
type: NotificationType.WithdrawalGroupReserveReady;
|
||||||
transactionId: string;
|
transactionId: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The purse creation of a peer-pull-credit transaction
|
||||||
|
* is done, and the other party can now pay.
|
||||||
|
*/
|
||||||
|
export interface PeerPullCreditReadyNotification {
|
||||||
|
type: NotificationType.PeerPullCreditReady;
|
||||||
|
transactionId: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface RefreshRevealedNotification {
|
export interface RefreshRevealedNotification {
|
||||||
type: NotificationType.RefreshRevealed;
|
type: NotificationType.RefreshRevealed;
|
||||||
}
|
}
|
||||||
@ -316,4 +326,5 @@ export type WalletNotification =
|
|||||||
| PayOperationSuccessNotification
|
| PayOperationSuccessNotification
|
||||||
| WithdrawalGroupKycRequested
|
| WithdrawalGroupKycRequested
|
||||||
| WithdrawalGroupBankConfirmed
|
| WithdrawalGroupBankConfirmed
|
||||||
| WithdrawalGroupReserveReady;
|
| WithdrawalGroupReserveReadyNotification
|
||||||
|
| PeerPullCreditReadyNotification;
|
||||||
|
@ -72,6 +72,7 @@ import {
|
|||||||
codecOptional,
|
codecOptional,
|
||||||
codecForTimestamp,
|
codecForTimestamp,
|
||||||
CancellationToken,
|
CancellationToken,
|
||||||
|
NotificationType,
|
||||||
} from "@gnu-taler/taler-util";
|
} from "@gnu-taler/taler-util";
|
||||||
import { SpendCoinDetails } from "../crypto/cryptoImplementation.js";
|
import { SpendCoinDetails } from "../crypto/cryptoImplementation.js";
|
||||||
import {
|
import {
|
||||||
@ -119,7 +120,10 @@ import {
|
|||||||
processWithdrawalGroup,
|
processWithdrawalGroup,
|
||||||
} from "./withdraw.js";
|
} from "./withdraw.js";
|
||||||
import { PendingTaskType } from "../pending-types.js";
|
import { PendingTaskType } from "../pending-types.js";
|
||||||
import { stopLongpolling } from "./transactions.js";
|
import {
|
||||||
|
constructTransactionIdentifier,
|
||||||
|
stopLongpolling,
|
||||||
|
} from "./transactions.js";
|
||||||
|
|
||||||
const logger = new Logger("operations/peer-to-peer.ts");
|
const logger = new Logger("operations/peer-to-peer.ts");
|
||||||
|
|
||||||
@ -1507,6 +1511,14 @@ export async function processPeerPullCredit(
|
|||||||
await tx.peerPullPaymentInitiations.put(pi2);
|
await tx.peerPullPaymentInitiations.put(pi2);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
ws.notify({
|
||||||
|
type: NotificationType.PeerPullCreditReady,
|
||||||
|
transactionId: constructTransactionIdentifier({
|
||||||
|
tag: TransactionType.PeerPullCredit,
|
||||||
|
pursePub: pullIni.pursePub,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
type: OperationAttemptResultType.Finished,
|
type: OperationAttemptResultType.Finished,
|
||||||
result: undefined,
|
result: undefined,
|
||||||
@ -1626,9 +1638,6 @@ export async function initiatePeerPullPayment(
|
|||||||
const pursePair = await ws.cryptoApi.createEddsaKeypair({});
|
const pursePair = await ws.cryptoApi.createEddsaKeypair({});
|
||||||
const mergePair = await ws.cryptoApi.createEddsaKeypair({});
|
const mergePair = await ws.cryptoApi.createEddsaKeypair({});
|
||||||
|
|
||||||
const instructedAmount = Amounts.parseOrThrow(
|
|
||||||
req.partialContractTerms.amount,
|
|
||||||
);
|
|
||||||
const contractTerms = req.partialContractTerms;
|
const contractTerms = req.partialContractTerms;
|
||||||
|
|
||||||
const hContractTerms = ContractTermsUtil.hashContractTerms(contractTerms);
|
const hContractTerms = ContractTermsUtil.hashContractTerms(contractTerms);
|
||||||
|
@ -64,6 +64,7 @@ import {
|
|||||||
} from "../db.js";
|
} from "../db.js";
|
||||||
import { InternalWalletState } from "../internal-wallet-state.js";
|
import { InternalWalletState } from "../internal-wallet-state.js";
|
||||||
import { PendingTaskType } from "../pending-types.js";
|
import { PendingTaskType } from "../pending-types.js";
|
||||||
|
import { assertUnreachable } from "../util/assertUnreachable.js";
|
||||||
import { checkDbInvariant } from "../util/invariants.js";
|
import { checkDbInvariant } from "../util/invariants.js";
|
||||||
import { constructTaskIdentifier, TaskIdentifiers } from "../util/retries.js";
|
import { constructTaskIdentifier, TaskIdentifiers } from "../util/retries.js";
|
||||||
import {
|
import {
|
||||||
@ -1376,6 +1377,35 @@ export type ParsedTransactionIdentifier =
|
|||||||
| { tag: TransactionType.Tip; walletTipId: string }
|
| { tag: TransactionType.Tip; walletTipId: string }
|
||||||
| { tag: TransactionType.Withdrawal; withdrawalGroupId: string };
|
| { tag: TransactionType.Withdrawal; withdrawalGroupId: string };
|
||||||
|
|
||||||
|
export function constructTransactionIdentifier(
|
||||||
|
pTxId: ParsedTransactionIdentifier,
|
||||||
|
): string {
|
||||||
|
switch (pTxId.tag) {
|
||||||
|
case TransactionType.Deposit:
|
||||||
|
return `txn:${pTxId.tag}:${pTxId.depositGroupId}`;
|
||||||
|
case TransactionType.Payment:
|
||||||
|
return `txn:${pTxId.tag}:${pTxId.proposalId}`;
|
||||||
|
case TransactionType.PeerPullCredit:
|
||||||
|
return `txn:${pTxId.tag}:${pTxId.pursePub}`;
|
||||||
|
case TransactionType.PeerPullDebit:
|
||||||
|
return `txn:${pTxId.tag}:${pTxId.peerPullPaymentIncomingId}`;
|
||||||
|
case TransactionType.PeerPushCredit:
|
||||||
|
return `txn:${pTxId.tag}:${pTxId.peerPushPaymentIncomingId}`;
|
||||||
|
case TransactionType.PeerPushDebit:
|
||||||
|
return `txn:${pTxId.tag}:${pTxId.pursePub}`;
|
||||||
|
case TransactionType.Refresh:
|
||||||
|
return `txn:${pTxId.tag}:${pTxId.refreshGroupId}`;
|
||||||
|
case TransactionType.Refund:
|
||||||
|
return `txn:${pTxId.tag}:${pTxId.proposalId}:${pTxId.executionTime}`;
|
||||||
|
case TransactionType.Tip:
|
||||||
|
return `txn:${pTxId.tag}:${pTxId.walletTipId}`;
|
||||||
|
case TransactionType.Withdrawal:
|
||||||
|
return `txn:${pTxId.tag}:${pTxId.withdrawalGroupId}`;
|
||||||
|
default:
|
||||||
|
assertUnreachable(pTxId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse a transaction identifier string into a typed, structured representation.
|
* Parse a transaction identifier string into a typed, structured representation.
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user