commit f3568d46d5af40f382ecd06f1fdde324f113b6f2
parent 885b4f9bb6ba53a67048d3ec7ea7d41c6184f5c1
Author: Florian Dold <florian@dold.me>
Date: Wed, 23 Apr 2025 12:18:07 +0200
harness: formatting, add logStep
Diffstat:
1 file changed, 76 insertions(+), 81 deletions(-)
diff --git a/packages/taler-harness/src/integrationtests/test-peer-push.ts b/packages/taler-harness/src/integrationtests/test-peer-push.ts
@@ -32,11 +32,8 @@ import {
} from "../harness/environments.js";
import { GlobalTestState, WalletClient } from "../harness/harness.js";
-const purse_expiration = AbsoluteTime.toProtocolTimestamp(
- AbsoluteTime.addDuration(
- AbsoluteTime.now(),
- Duration.fromSpec({ days: 2 }),
- ),
+const purseExpiration = AbsoluteTime.toProtocolTimestamp(
+ AbsoluteTime.addDuration(AbsoluteTime.now(), Duration.fromSpec({ days: 2 })),
);
/**
@@ -51,14 +48,14 @@ export async function runPeerPushTest(t: GlobalTestState) {
] = await Promise.all([
createSimpleTestkudosEnvironmentV3(t),
createWalletDaemonWithClient(t, {
- name: "w2"
+ name: "w2",
}),
createWalletDaemonWithClient(t, {
- name: "w3"
+ name: "w3",
}),
createWalletDaemonWithClient(t, {
- name: "w4"
- })
+ name: "w4",
+ }),
]);
// Withdraw digital cash into the wallet.
@@ -70,14 +67,18 @@ export async function runPeerPushTest(t: GlobalTestState) {
});
await withdrawRes.withdrawalFinishedCond;
- async function init_peer_push_debit(w: WalletClient, summary: string, amount: AmountString = "TESTKUDOS:5"): Promise<TransactionPeerPushDebit> {
+ async function initPeerPushDebit(
+ w: WalletClient,
+ summary: string,
+ amount: AmountString = "TESTKUDOS:5",
+ ): Promise<TransactionPeerPushDebit> {
const initiate = await wallet1.call(
WalletApiOperation.InitiatePeerPushDebit,
{
partialContractTerms: {
summary,
amount,
- purse_expiration,
+ purse_expiration: purseExpiration,
},
},
);
@@ -86,43 +87,29 @@ export async function runPeerPushTest(t: GlobalTestState) {
transactionId: initiate.transactionId,
txState: {
major: TransactionMajorState.Pending,
- minor: TransactionMinorState.Ready
+ minor: TransactionMinorState.Ready,
},
});
- const tx = await wallet1.call(
- WalletApiOperation.GetTransactionById,
- { transactionId: initiate.transactionId }
- );
+ const tx = await wallet1.call(WalletApiOperation.GetTransactionById, {
+ transactionId: initiate.transactionId,
+ });
t.assertDeepEqual(tx.type, TransactionType.PeerPushDebit);
- return tx
+ return tx;
}
t.logStep("P2P push amount logic");
{
- const [
- maxpeer,
- checkzero,
- checkfive
- ] = await Promise.all([
- wallet1.call(
- WalletApiOperation.GetMaxPeerPushDebitAmount,
- {
- currency: "TESTKUDOS"
- }
- ),
- wallet1.call(
- WalletApiOperation.CheckPeerPushDebit,
- {
- amount: "TESTKUDOS:0"
- }
- ),
- wallet1.call(
- WalletApiOperation.CheckPeerPushDebit,
- {
- amount: "TESTKUDOS:5"
- }
- )
+ const [maxpeer, checkzero, checkfive] = await Promise.all([
+ wallet1.call(WalletApiOperation.GetMaxPeerPushDebitAmount, {
+ currency: "TESTKUDOS",
+ }),
+ wallet1.call(WalletApiOperation.CheckPeerPushDebit, {
+ amount: "TESTKUDOS:0",
+ }),
+ wallet1.call(WalletApiOperation.CheckPeerPushDebit, {
+ amount: "TESTKUDOS:5",
+ }),
]);
t.assertDeepEqual(maxpeer.exchangeBaseUrl, exchange.baseUrl);
@@ -143,18 +130,20 @@ export async function runPeerPushTest(t: GlobalTestState) {
partialContractTerms: {
summary: "(this will fail)",
amount: "TESTKUDOS:250",
- purse_expiration,
+ purse_expiration: purseExpiration,
},
- })
+ }),
+ );
+ t.assertTrue(
+ ex1.errorDetail.code === TalerErrorCode.WALLET_UNEXPECTED_EXCEPTION,
);
- t.assertTrue(ex1.errorDetail.code === TalerErrorCode.WALLET_UNEXPECTED_EXCEPTION);
// FIXME propagate the error correctly
// t.assertTrue(ex1.errorDetail.code === TalerErrorCode.WALLET_PEER_PUSH_PAYMENT_INSUFFICIENT_BALANCE);
}
t.logStep("P2P push confirm");
{
- const tx = await init_peer_push_debit(wallet1, "confirm");
+ const tx = await initPeerPushDebit(wallet1, "confirm");
// Check balance update
{
@@ -162,16 +151,17 @@ export async function runPeerPushTest(t: GlobalTestState) {
t.assertAmountEquals(bal.balances[0].pendingOutgoing, "TESTKUDOS:5.49");
}
- const [prepare2, prepare3, prepare4] = await Promise.all([wallet2, wallet3, wallet4].map(w =>
- w.call(
- WalletApiOperation.PreparePeerPushCredit,
- { talerUri: tx.talerUri! }
- ))
+ const [prepare2, prepare3, prepare4] = await Promise.all(
+ [wallet2, wallet3, wallet4].map((w) =>
+ w.call(WalletApiOperation.PreparePeerPushCredit, {
+ talerUri: tx.talerUri!,
+ }),
+ ),
);
{
const idempotent = await wallet2.call(
WalletApiOperation.PreparePeerPushCredit,
- { talerUri: tx.talerUri! }
+ { talerUri: tx.talerUri! },
);
t.assertTrue(prepare2.transactionId === idempotent.transactionId);
}
@@ -212,7 +202,7 @@ export async function runPeerPushTest(t: GlobalTestState) {
transactionId: prepare3.transactionId,
txState: {
major: TransactionMajorState.Pending,
- minor: TransactionMinorState.Merge
+ minor: TransactionMinorState.Merge,
},
}),
wallet4.call(WalletApiOperation.TestingWaitTransactionState, {
@@ -220,7 +210,7 @@ export async function runPeerPushTest(t: GlobalTestState) {
txState: {
major: TransactionMajorState.Aborted,
},
- })
+ }),
]);
{
@@ -231,25 +221,25 @@ export async function runPeerPushTest(t: GlobalTestState) {
// Check scan after completion
const prepare1 = await wallet1.call(
WalletApiOperation.PreparePeerPushCredit,
- { talerUri: tx.talerUri! }
+ { talerUri: tx.talerUri! },
); // FIXME this should fails
- await wallet1.call(
- WalletApiOperation.ConfirmPeerPushCredit,
- { transactionId: prepare1.transactionId }
- );
- // FIXME this should also fail
+ await wallet1.call(WalletApiOperation.ConfirmPeerPushCredit, {
+ transactionId: prepare1.transactionId,
+ });
+ // FIXME this should also fail
}
t.logStep("P2P push abort");
{
- const tx = await init_peer_push_debit(wallet1, "abort");
+ const tx = await initPeerPushDebit(wallet1, "abort");
- const [prepare2, prepare3] = await Promise.all([wallet2, wallet3].map(w =>
- w.call(
- WalletApiOperation.PreparePeerPushCredit,
- { talerUri: tx.talerUri! }
- )
- ));
+ const [prepare2, prepare3] = await Promise.all(
+ [wallet2, wallet3].map((w) =>
+ w.call(WalletApiOperation.PreparePeerPushCredit, {
+ talerUri: tx.talerUri!,
+ }),
+ ),
+ );
await wallet1.call(WalletApiOperation.AbortTransaction, {
transactionId: tx.transactionId,
@@ -278,13 +268,13 @@ export async function runPeerPushTest(t: GlobalTestState) {
transactionId: prepare2.transactionId,
txState: {
major: TransactionMajorState.Pending,
- minor: TransactionMinorState.Merge
+ minor: TransactionMinorState.Merge,
},
}),
wallet3.call(WalletApiOperation.TestingWaitTransactionState, {
transactionId: prepare3.transactionId,
txState: {
- major: TransactionMajorState.Aborted
+ major: TransactionMajorState.Aborted,
},
}),
]);
@@ -295,14 +285,15 @@ export async function runPeerPushTest(t: GlobalTestState) {
t.logStep("P2P push expire");
{
- const tx = await init_peer_push_debit(wallet1, "expire");
+ const tx = await initPeerPushDebit(wallet1, "expire");
- const [prepare2, prepare3] = await Promise.all([wallet2, wallet3].map(w =>
- w.call(
- WalletApiOperation.PreparePeerPushCredit,
- { talerUri: tx.talerUri! }
- )
- ));
+ const [prepare2, prepare3] = await Promise.all(
+ [wallet2, wallet3].map((w) =>
+ w.call(WalletApiOperation.PreparePeerPushCredit, {
+ talerUri: tx.talerUri!,
+ }),
+ ),
+ );
const timetravelOffsetMs = Duration.toMilliseconds(
Duration.fromSpec({ days: 5 }),
@@ -314,16 +305,20 @@ export async function runPeerPushTest(t: GlobalTestState) {
await exchange.pingUntilAvailable();
await exchange.runExpireOnce();
- await Promise.all([wallet1, wallet2, wallet3].map(w =>
- w.call(WalletApiOperation.TestingSetTimetravel, {
- offsetMs: timetravelOffsetMs,
- })
- ));
+ await Promise.all(
+ [wallet1, wallet2, wallet3].map((w) =>
+ w.call(WalletApiOperation.TestingSetTimetravel, {
+ offsetMs: timetravelOffsetMs,
+ }),
+ ),
+ );
await wallet2.client.call(WalletApiOperation.ConfirmPeerPushCredit, {
transactionId: prepare2.transactionId,
});
+ t.logStep("P2P start wait for expiration");
+
await Promise.all([
wallet1.call(WalletApiOperation.TestingWaitTransactionState, {
transactionId: tx.transactionId,
@@ -336,13 +331,13 @@ export async function runPeerPushTest(t: GlobalTestState) {
transactionId: prepare2.transactionId,
txState: {
major: TransactionMajorState.Pending,
- minor: TransactionMinorState.Merge
+ minor: TransactionMinorState.Merge,
},
}),
wallet3.call(WalletApiOperation.TestingWaitTransactionState, {
transactionId: prepare3.transactionId,
txState: {
- major: TransactionMajorState.Aborted
+ major: TransactionMajorState.Aborted,
},
}),
]);