diff options
Diffstat (limited to 'packages/taler-harness/src/integrationtests')
-rw-r--r-- | packages/taler-harness/src/integrationtests/test-peer-to-peer-push.ts | 72 |
1 files changed, 50 insertions, 22 deletions
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", |