diff options
author | Florian Dold <florian@dold.me> | 2023-11-22 15:20:10 +0100 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2023-11-22 17:08:15 +0100 |
commit | bd37a0b04123d734e1e3fae105f0d9c24279629f (patch) | |
tree | 31f03c2acd3c1f123f8762391456b1aa22df9803 /packages/taler-harness | |
parent | 32182fb1b912e1136ba933c4a4f204e6e2f33de2 (diff) | |
download | wallet-core-bd37a0b04123d734e1e3fae105f0d9c24279629f.tar.xz |
wallet-core: implement and test currency conversion withdrawals
Diffstat (limited to 'packages/taler-harness')
-rw-r--r-- | packages/taler-harness/src/harness/harness.ts | 39 | ||||
-rw-r--r-- | packages/taler-harness/src/integrationtests/test-withdrawal-conversion.ts | 34 |
2 files changed, 53 insertions, 20 deletions
diff --git a/packages/taler-harness/src/harness/harness.ts b/packages/taler-harness/src/harness/harness.ts index 37e0b02a7..242bf2207 100644 --- a/packages/taler-harness/src/harness/harness.ts +++ b/packages/taler-harness/src/harness/harness.ts @@ -928,6 +928,8 @@ export class ExchangeService implements ExchangeServiceInterface { private currentTimetravelOffsetMs: number | undefined; + private exchangeBankAccounts: HarnessExchangeBankAccount[] = []; + setTimetravel(t: number | undefined): void { if (this.isRunning()) { throw Error("can't set time travel while the exchange is running"); @@ -1132,6 +1134,7 @@ export class ExchangeService implements ExchangeServiceInterface { localName: string, exchangeBankAccount: HarnessExchangeBankAccount, ): Promise<void> { + this.exchangeBankAccounts.push(exchangeBankAccount); const config = Configuration.load(this.configFilename); config.setString( `exchange-account-${localName}`, @@ -1277,32 +1280,32 @@ export class ExchangeService implements ExchangeServiceInterface { ["-c", this.configFilename, "download", "sign", "upload"], ); - const accounts: string[] = []; const accountTargetTypes: Set<string> = new Set(); - const config = Configuration.load(this.configFilename); - for (const sectionName of config.getSectionNames()) { - if (sectionName.startsWith("EXCHANGE-ACCOUNT-")) { - const paytoUri = config.getString(sectionName, "payto_uri").required(); - const p = parsePaytoUri(paytoUri); - if (!p) { - throw Error(`invalid payto uri in exchange config: ${paytoUri}`); - } - accountTargetTypes.add(p?.targetType); - accounts.push(paytoUri); + for (const acct of this.exchangeBankAccounts) { + const paytoUri = acct.accountPaytoUri; + const p = parsePaytoUri(paytoUri); + if (!p) { + throw Error(`invalid payto uri in exchange config: ${paytoUri}`); + } + accountTargetTypes.add(p?.targetType); + const optArgs: string[] = []; + if (acct.conversionUrl != null) { + optArgs.push("conversion-url", acct.conversionUrl); } - } - - const accountsDescription = accounts.map((acc) => ` * ${acc}`).join("\n"); - logger.info("configuring bank accounts:"); - logger.info(accountsDescription); - for (const acc of accounts) { await runCommand( this.globalState, "exchange-offline", "taler-exchange-offline", - ["-c", this.configFilename, "enable-account", acc, "upload"], + [ + "-c", + this.configFilename, + "enable-account", + paytoUri, + ...optArgs, + "upload", + ], ); } diff --git a/packages/taler-harness/src/integrationtests/test-withdrawal-conversion.ts b/packages/taler-harness/src/integrationtests/test-withdrawal-conversion.ts index 2a9dd5800..6fc403be4 100644 --- a/packages/taler-harness/src/integrationtests/test-withdrawal-conversion.ts +++ b/packages/taler-harness/src/integrationtests/test-withdrawal-conversion.ts @@ -23,7 +23,9 @@ import { Duration, Logger, TalerCorebankApiClient, + TransactionType, WireGatewayApiClient, + WithdrawalType, j2s, } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; @@ -184,16 +186,21 @@ export async function runWithdrawalConversionTest(t: GlobalTestState) { exchangeBaseUrl: exchange.baseUrl, }); - const infoRes = walletClient.call( + const infoRes = await walletClient.call( WalletApiOperation.GetWithdrawalDetailsForAmount, { exchangeBaseUrl: exchange.baseUrl, - amount: "EXTCOIN:20" as AmountString, + amount: "TESTKUDOS:20" as AmountString, }, ); console.log(`withdrawal details: ${j2s(infoRes)}`); + t.assertAmountEquals( + infoRes.withdrawalAccountList[0].transferAmount, + "FOO:123", + ); + const tStart = AbsoluteTime.now(); logger.info("starting AcceptManualWithdrawal request"); @@ -210,6 +217,29 @@ export async function runWithdrawalConversionTest(t: GlobalTestState) { logger.info("AcceptManualWithdrawal finished"); logger.info(`result: ${j2s(wres)}`); + t.assertAmountEquals( + wres.withdrawalAccountsList[0].transferAmount, + "FOO:123", + ); + + const txInfo = await walletClient.call( + WalletApiOperation.GetTransactionById, + { + transactionId: wres.transactionId, + }, + ); + + t.assertDeepEqual(txInfo.type, TransactionType.Withdrawal); + t.assertDeepEqual( + txInfo.withdrawalDetails.type, + WithdrawalType.ManualTransfer, + ); + t.assertTrue(!!txInfo.withdrawalDetails.exchangeCreditAccounts); + t.assertDeepEqual( + txInfo.withdrawalDetails.exchangeCreditAccounts[0].transferAmount, + "FOO:123", + ); + // Check that the request did not go into long-polling. const duration = AbsoluteTime.difference(tStart, AbsoluteTime.now()); if (typeof duration.d_ms !== "number" || duration.d_ms > 5 * 1000) { |