diff options
Diffstat (limited to 'packages/taler-harness/src/integrationtests/test-wallet-refresh.ts')
-rw-r--r-- | packages/taler-harness/src/integrationtests/test-wallet-refresh.ts | 70 |
1 files changed, 66 insertions, 4 deletions
diff --git a/packages/taler-harness/src/integrationtests/test-wallet-refresh.ts b/packages/taler-harness/src/integrationtests/test-wallet-refresh.ts index 9f8d1503e..b86dfadcf 100644 --- a/packages/taler-harness/src/integrationtests/test-wallet-refresh.ts +++ b/packages/taler-harness/src/integrationtests/test-wallet-refresh.ts @@ -17,14 +17,21 @@ /** * Imports. */ -import { Wallet, WalletApiOperation } from "@gnu-taler/taler-wallet-core"; -import { GlobalTestState } from "../harness/harness.js"; +import { + AmountString, + NotificationType, + TransactionMajorState, + TransactionType, + j2s, +} from "@gnu-taler/taler-util"; +import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; +import { parseTransactionIdentifier } from "../../../taler-wallet-core/src/transactions.js"; +import { GlobalTestState, generateRandomPayto } from "../harness/harness.js"; import { createSimpleTestkudosEnvironmentV2, - withdrawViaBankV2, makeTestPaymentV2, + withdrawViaBankV2, } from "../harness/helpers.js"; -import { TransactionType, j2s } from "@gnu-taler/taler-util"; /** * Run test for refreshe after a payment. @@ -77,6 +84,61 @@ export async function runWalletRefreshTest(t: GlobalTestState) { ); t.assertDeepEqual(refreshTx.type, TransactionType.Refresh); + + // Now we test a pending refresh operation. + { + await exchange.stop(); + + const refreshCreatedCond = walletClient.waitForNotificationCond((x) => { + if ( + x.type === NotificationType.TransactionStateTransition && + parseTransactionIdentifier(x.transactionId)?.tag === + TransactionType.Refresh + ) { + return true; + } + return false; + }); + + const refreshDoneCond = walletClient.waitForNotificationCond((x) => { + if ( + x.type === NotificationType.TransactionStateTransition && + parseTransactionIdentifier(x.transactionId)?.tag === + TransactionType.Refresh && + x.newTxState.major === TransactionMajorState.Done + ) { + return true; + } + return false; + }); + + const depositGroupResult = await walletClient.client.call( + WalletApiOperation.CreateDepositGroup, + { + amount: "TESTKUDOS:10.5" as AmountString, + depositPaytoUri: generateRandomPayto("foo"), + }, + ); + + await refreshCreatedCond; + + // Here, the refresh operation should be in a pending state. + + const bal1 = await walletClient.call(WalletApiOperation.GetBalances, {}); + + await exchange.start(); + + await refreshDoneCond; + + const bal2 = await walletClient.call(WalletApiOperation.GetBalances, {}); + + // The refresh operation completing should not change the available balance, + // as we're accounting pending refreshes towards the available (but not material!) balance. + t.assertAmountEquals( + bal1.balances[0].available, + bal2.balances[0].available, + ); + } } runWalletRefreshTest.suites = ["wallet"]; |