diff options
Diffstat (limited to 'packages/taler-harness/src/integrationtests/test-timetravel-autorefresh.ts')
-rw-r--r-- | packages/taler-harness/src/integrationtests/test-timetravel-autorefresh.ts | 92 |
1 files changed, 77 insertions, 15 deletions
diff --git a/packages/taler-harness/src/integrationtests/test-timetravel-autorefresh.ts b/packages/taler-harness/src/integrationtests/test-timetravel-autorefresh.ts index e144683cb..8b8b45c40 100644 --- a/packages/taler-harness/src/integrationtests/test-timetravel-autorefresh.ts +++ b/packages/taler-harness/src/integrationtests/test-timetravel-autorefresh.ts @@ -18,11 +18,14 @@ * Imports. */ import { + Amounts, ConfirmPayResultType, Duration, MerchantApiClient, NotificationType, PreparePayResultType, + TalerCorebankApiClient, + j2s, } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { makeNoFeeCoinConfig } from "../harness/denomStructures.js"; @@ -37,7 +40,7 @@ import { import { applyTimeTravelV2, createWalletDaemonWithClient, - withdrawViaBankV2, + withdrawViaBankV3, } from "../harness/helpers.js"; /** @@ -69,18 +72,42 @@ export async function runTimetravelAutorefreshTest(t: GlobalTestState) { database: db.connStr, }); - const exchangeBankAccount = await bank.createExchangeAccount( - "myexchange", - "x", - ); - exchange.addBankAccount("1", exchangeBankAccount); + let receiverName = "Exchange"; + let exchangeBankUsername = "exchange"; + let exchangeBankPassword = "mypw"; + let exchangePaytoUri = generateRandomPayto(exchangeBankUsername); + + await exchange.addBankAccount("1", { + accountName: exchangeBankUsername, + accountPassword: exchangeBankPassword, + wireGatewayApiBaseUrl: new URL( + "accounts/exchange/taler-wire-gateway/", + bank.baseUrl, + ).href, + accountPaytoUri: exchangePaytoUri, + }); - bank.setSuggestedExchange(exchange, exchangeBankAccount.accountPaytoUri); + bank.setSuggestedExchange(exchange, exchangePaytoUri); await bank.start(); await bank.pingUntilAvailable(); + const bankClient = new TalerCorebankApiClient(bank.corebankApiBaseUrl, { + auth: { + username: "admin", + password: "adminpw", + }, + }); + + await bankClient.registerAccountExtended({ + name: receiverName, + password: exchangeBankPassword, + username: exchangeBankUsername, + is_taler_exchange: true, + payto_uri: exchangePaytoUri, + }); + exchange.addCoinConfigList(makeNoFeeCoinConfig("TESTKUDOS")); await exchange.start(); @@ -111,14 +138,17 @@ export async function runTimetravelAutorefreshTest(t: GlobalTestState) { const merchantClient = new MerchantApiClient(merchant.makeInstanceBaseUrl()); - // Withdraw digital cash into the wallet. + t.logStep("exchangeUpdated1Cond"); - const wres = await withdrawViaBankV2(t, { + // Withdraw digital cash into the wallet. + t.logStep("Withdraw digital cash into the wallet."); + const wres = await withdrawViaBankV3(t, { walletClient, - bank, + bankClient, exchange, amount: "TESTKUDOS:15", }); + t.logStep("wait"); await wres.withdrawalFinishedCond; const exchangeUpdated1Cond = walletClient.waitForNotificationCond( @@ -126,10 +156,18 @@ export async function runTimetravelAutorefreshTest(t: GlobalTestState) { x.type === NotificationType.ExchangeStateTransition && x.exchangeBaseUrl === exchange.baseUrl, ); + t.logStep("waiting tx"); + await walletClient.call(WalletApiOperation.TestingWaitTransactionsFinal, {}); + { + const balance = await walletClient.call(WalletApiOperation.GetBalances, {}); + t.assertTrue( + Amounts.cmp(balance.balances[0].available, "TESTKUDOS:15") === 0, + ); + } // Travel into the future, the deposit expiration is two years // into the future. - console.log("applying first time travel"); + t.logStep("applying first time travel"); await applyTimeTravelV2( Duration.toMilliseconds(Duration.fromSpec({ days: 400 })), { @@ -140,19 +178,36 @@ export async function runTimetravelAutorefreshTest(t: GlobalTestState) { ); // The time travel should cause exchanges to update. + t.logStep("The time travel should cause exchanges to update"); await exchangeUpdated1Cond; + t.logStep("exchange updated, wahting tx"); await walletClient.call(WalletApiOperation.TestingWaitTransactionsFinal, {}); - - const wres2 = await withdrawViaBankV2(t, { + { + const balance = await walletClient.call(WalletApiOperation.GetBalances, {}); + t.assertTrue( + Amounts.cmp(balance.balances[0].available, "TESTKUDOS:15") === 0, + ); + } + + t.logStep("withdrawing second time"); + const wres2 = await withdrawViaBankV3(t, { walletClient, - bank, + bankClient, exchange, amount: "TESTKUDOS:20", }); await wres2.withdrawalFinishedCond; + t.logStep("witdrawn, waiting tx"); await walletClient.call(WalletApiOperation.TestingWaitTransactionsFinal, {}); + { + const balance = await walletClient.call(WalletApiOperation.GetBalances, {}); + t.assertTrue( + Amounts.cmp(balance.balances[0].available, "TESTKUDOS:35") === 0, + ); + } + const exchangeUpdated2Cond = walletClient.waitForNotificationCond( (x) => x.type === NotificationType.ExchangeStateTransition && @@ -161,7 +216,7 @@ export async function runTimetravelAutorefreshTest(t: GlobalTestState) { // Travel into the future, the deposit expiration is two years // into the future. - console.log("applying second time travel"); + t.logStep("applying second time travel"); await applyTimeTravelV2( Duration.toMilliseconds(Duration.fromSpec({ years: 2, months: 6 })), { @@ -172,8 +227,15 @@ export async function runTimetravelAutorefreshTest(t: GlobalTestState) { ); // The time travel should cause exchanges to update. + t.logStep("The time travel should cause exchanges to update."); await exchangeUpdated2Cond; await walletClient.call(WalletApiOperation.TestingWaitTransactionsFinal, {}); + { + const balance = await walletClient.call(WalletApiOperation.GetBalances, {}); + t.assertTrue( + Amounts.cmp(balance.balances[0].available, "TESTKUDOS:35") === 0, + ); + } // At this point, the original coins should've been refreshed. // It would be too late to refresh them now, as we're past |