diff options
author | Florian Dold <florian@dold.me> | 2024-01-09 16:23:26 +0100 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2024-01-09 16:23:26 +0100 |
commit | f8cde03f0cb6a7584fb92885f8979a01916a917d (patch) | |
tree | 6f120387f8f5297f436e2d2bd2d4d7b5c1814146 /packages/taler-harness | |
parent | de39d432374a3ecd1bddd788b1ac1585461af8c1 (diff) | |
download | wallet-core-f8cde03f0cb6a7584fb92885f8979a01916a917d.tar.xz |
wallet-core: refactor peer-pull-debit and test aborting
Diffstat (limited to 'packages/taler-harness')
-rw-r--r-- | packages/taler-harness/src/integrationtests/test-peer-to-peer-pull.ts | 145 |
1 files changed, 137 insertions, 8 deletions
diff --git a/packages/taler-harness/src/integrationtests/test-peer-to-peer-pull.ts b/packages/taler-harness/src/integrationtests/test-peer-to-peer-pull.ts index 7ed716bc1..a71175407 100644 --- a/packages/taler-harness/src/integrationtests/test-peer-to-peer-pull.ts +++ b/packages/taler-harness/src/integrationtests/test-peer-to-peer-pull.ts @@ -25,10 +25,17 @@ import { NotificationType, TransactionMajorState, TransactionMinorState, + TransactionType, WalletNotification, } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; -import { GlobalTestState } from "../harness/harness.js"; +import { + BankServiceHandle, + ExchangeService, + GlobalTestState, + WalletCli, + WalletClient, +} from "../harness/harness.js"; import { createSimpleTestkudosEnvironmentV2, createWalletDaemonWithClient, @@ -65,6 +72,23 @@ export async function runPeerToPeerPullTest(t: GlobalTestState) { const wallet1 = w1.walletClient; const wallet2 = w2.walletClient; + await checkNormalPeerPull(t, bank, exchange, wallet1, wallet2); + + console.log(`w1 notifications: ${j2s(allW1Notifications)}`); + + // Check that we don't have an excessive number of notifications. + t.assertTrue(allW1Notifications.length <= 60); + + await checkAbortedPeerPull(t, bank, exchange, wallet1, wallet2); +} + +async function checkNormalPeerPull( + t: GlobalTestState, + bank: BankServiceHandle, + exchange: ExchangeService, + wallet1: WalletClient, + wallet2: WalletClient, +): Promise<void> { const withdrawRes = await withdrawViaBankV2(t, { walletClient: wallet2, bank, @@ -94,7 +118,8 @@ export async function runPeerToPeerPullTest(t: GlobalTestState) { ); const peerPullCreditReadyCond = wallet1.waitForNotificationCond( - (x) => x.type === NotificationType.TransactionStateTransition && + (x) => + x.type === NotificationType.TransactionStateTransition && x.transactionId === resp.transactionId && x.newTxState.major === TransactionMajorState.Pending && x.newTxState.minor === TransactionMinorState.Ready, @@ -102,23 +127,32 @@ export async function runPeerToPeerPullTest(t: GlobalTestState) { await peerPullCreditReadyCond; + const creditTx = await wallet1.call(WalletApiOperation.GetTransactionById, { + transactionId: resp.transactionId, + }); + + t.assertDeepEqual(creditTx.type, TransactionType.PeerPullCredit); + t.assertTrue(!!creditTx.talerUri); + const checkResp = await wallet2.client.call( WalletApiOperation.PreparePeerPullDebit, { - talerUri: resp.talerUri, + talerUri: creditTx.talerUri, }, ); console.log(`checkResp: ${j2s(checkResp)}`); const peerPullCreditDoneCond = wallet1.waitForNotificationCond( - (x) => x.type === NotificationType.TransactionStateTransition && + (x) => + x.type === NotificationType.TransactionStateTransition && x.transactionId === resp.transactionId && x.newTxState.major === TransactionMajorState.Done, ); const peerPullDebitDoneCond = wallet2.waitForNotificationCond( - (x) => x.type === NotificationType.TransactionStateTransition && + (x) => + x.type === NotificationType.TransactionStateTransition && x.transactionId === checkResp.transactionId && x.newTxState.major === TransactionMajorState.Done, ); @@ -142,11 +176,106 @@ export async function runPeerToPeerPullTest(t: GlobalTestState) { console.log(`txn1: ${j2s(txn1)}`); console.log(`txn2: ${j2s(txn2)}`); +} - console.log(`w1 notifications: ${j2s(allW1Notifications)}`); +async function checkAbortedPeerPull( + t: GlobalTestState, + bank: BankServiceHandle, + exchange: ExchangeService, + wallet1: WalletClient, + wallet2: WalletClient, +): Promise<void> { + const withdrawRes = await withdrawViaBankV2(t, { + walletClient: wallet2, + bank, + exchange, + amount: "TESTKUDOS:20", + }); - // Check that we don't have an excessive number of notifications. - t.assertTrue(allW1Notifications.length <= 60); + await withdrawRes.withdrawalFinishedCond; + + const purseExpiration = AbsoluteTime.toProtocolTimestamp( + AbsoluteTime.addDuration( + AbsoluteTime.now(), + Duration.fromSpec({ days: 2 }), + ), + ); + + const resp = await wallet1.client.call( + WalletApiOperation.InitiatePeerPullCredit, + { + exchangeBaseUrl: exchange.baseUrl, + partialContractTerms: { + summary: "Hello World", + amount: "TESTKUDOS:5" as AmountString, + purse_expiration: purseExpiration, + }, + }, + ); + + const peerPullCreditReadyCond = wallet1.waitForNotificationCond( + (x) => + x.type === NotificationType.TransactionStateTransition && + x.transactionId === resp.transactionId && + x.newTxState.major === TransactionMajorState.Pending && + x.newTxState.minor === TransactionMinorState.Ready, + ); + + await peerPullCreditReadyCond; + + const creditTx = await wallet1.call(WalletApiOperation.GetTransactionById, { + transactionId: resp.transactionId, + }); + + t.assertDeepEqual(creditTx.type, TransactionType.PeerPullCredit); + t.assertTrue(!!creditTx.talerUri); + + const checkResp = await wallet2.client.call( + WalletApiOperation.PreparePeerPullDebit, + { + talerUri: creditTx.talerUri, + }, + ); + + console.log(`checkResp: ${j2s(checkResp)}`); + + const peerPullCreditAbortedCond = wallet1.waitForNotificationCond( + (x) => + x.type === NotificationType.TransactionStateTransition && + x.transactionId === resp.transactionId && + x.newTxState.major === TransactionMajorState.Aborted, + ); + + const peerPullDebitAbortedCond = wallet2.waitForNotificationCond( + (x) => + x.type === NotificationType.TransactionStateTransition && + x.transactionId === checkResp.transactionId && + x.newTxState.major === TransactionMajorState.Aborted, + ); + + await wallet1.call(WalletApiOperation.AbortTransaction, { + transactionId: resp.transactionId, + }); + + await wallet2.client.call(WalletApiOperation.ConfirmPeerPullDebit, { + peerPullDebitId: checkResp.peerPullDebitId, + }); + + await peerPullCreditAbortedCond; + await peerPullDebitAbortedCond; + + const txn1 = await wallet1.client.call( + WalletApiOperation.GetTransactions, + {}, + ); + + const txn2 = await wallet2.client.call( + WalletApiOperation.GetTransactions, + {}, + ); + + console.log(`txn1: ${j2s(txn1)}`); + console.log(`txn2: ${j2s(txn2)}`); } runPeerToPeerPullTest.suites = ["wallet"]; |