diff options
author | Florian Dold <florian@dold.me> | 2024-09-11 16:13:53 +0200 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2024-09-11 16:14:01 +0200 |
commit | 08e5fafee3ecd140ef0c59f1183b7f592ad19e11 (patch) | |
tree | 047043c3c2781af8a75638412167153d4ebf4faa /packages/taler-harness/src | |
parent | fccab85a58e5eed4a9c12816ab255bc8c8b92960 (diff) | |
download | wallet-core-08e5fafee3ecd140ef0c59f1183b7f592ad19e11.tar.xz |
wallet-core: fix perExchange insufficient balance reporting
Also tests the expected behavior in the integration test
Diffstat (limited to 'packages/taler-harness/src')
6 files changed, 131 insertions, 36 deletions
diff --git a/packages/taler-harness/src/harness/helpers.ts b/packages/taler-harness/src/harness/helpers.ts index 488be33fa..30f2bea63 100644 --- a/packages/taler-harness/src/harness/helpers.ts +++ b/packages/taler-harness/src/harness/helpers.ts @@ -109,6 +109,7 @@ export interface SimpleTestEnvironmentNg { */ export interface SimpleTestEnvironmentNg3 { commonDb: DbInfo; + bank: BankService; bankClient: TalerCorebankApiClient; exchange: ExchangeService; exchangeBankAccount: HarnessExchangeBankAccount; @@ -475,7 +476,7 @@ export async function createSimpleTestkudosEnvironmentV3( const exchangeBankPassword = "mypw"; const exchangePaytoUri = generateRandomPayto(exchangeBankUsername); const wireGatewayApiBaseUrl = new URL( - "accounts/exchange/taler-wire-gateway/", + `accounts/${exchangeBankUsername}/taler-wire-gateway/`, bank.corebankApiBaseUrl, ).href; @@ -539,7 +540,6 @@ export async function createSimpleTestkudosEnvironmentV3( opts.additionalExchangeConfig(exchange); } await exchange.start(); - await exchange.pingUntilAvailable(); merchant.addExchange(exchange); @@ -584,6 +584,7 @@ export async function createSimpleTestkudosEnvironmentV3( merchant, walletClient, walletService, + bank, bankClient, exchangeBankAccount, }; diff --git a/packages/taler-harness/src/integrationtests/test-fee-regression.ts b/packages/taler-harness/src/integrationtests/test-fee-regression.ts index 6ae7b5de8..72f56fb0e 100644 --- a/packages/taler-harness/src/integrationtests/test-fee-regression.ts +++ b/packages/taler-harness/src/integrationtests/test-fee-regression.ts @@ -189,6 +189,7 @@ export async function createMyTestkudosEnvironment( walletClient, walletService, bankClient, + bank, exchangeBankAccount: { accountName: "", accountPassword: "", diff --git a/packages/taler-harness/src/integrationtests/test-kyc.ts b/packages/taler-harness/src/integrationtests/test-kyc.ts index 09647331a..169c14698 100644 --- a/packages/taler-harness/src/integrationtests/test-kyc.ts +++ b/packages/taler-harness/src/integrationtests/test-kyc.ts @@ -265,6 +265,7 @@ async function createKycTestkudosEnvironment( merchant, walletClient, walletService, + bank, bankClient, exchangeBankAccount: { accountName: "", diff --git a/packages/taler-harness/src/integrationtests/test-revocation.ts b/packages/taler-harness/src/integrationtests/test-revocation.ts index 8714a3769..6441ae974 100644 --- a/packages/taler-harness/src/integrationtests/test-revocation.ts +++ b/packages/taler-harness/src/integrationtests/test-revocation.ts @@ -179,6 +179,7 @@ async function createTestEnvironment( merchant, walletClient, walletService, + bank, bankClient, exchangeBankAccount: { accountName: "", diff --git a/packages/taler-harness/src/integrationtests/test-wallet-insufficient-balance.ts b/packages/taler-harness/src/integrationtests/test-wallet-insufficient-balance.ts index d02c658f1..eb8b958a8 100644 --- a/packages/taler-harness/src/integrationtests/test-wallet-insufficient-balance.ts +++ b/packages/taler-harness/src/integrationtests/test-wallet-insufficient-balance.ts @@ -20,35 +20,78 @@ import { AmountString, Duration, + j2s, PaymentInsufficientBalanceDetails, TalerErrorCode, } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { CoinConfig, defaultCoinConfig } from "../harness/denomStructures.js"; import { - GlobalTestState, + ExchangeService, generateRandomPayto, + GlobalTestState, + HarnessExchangeBankAccount, setupDb, } from "../harness/harness.js"; -import { createSimpleTestkudosEnvironmentV3, withdrawViaBankV3 } from "../harness/helpers.js"; +import { + createSimpleTestkudosEnvironmentV3, + withdrawViaBankV3, +} from "../harness/helpers.js"; export async function runWalletInsufficientBalanceTest(t: GlobalTestState) { // Set up test environment - const db = await setupDb(t); - const coinConfig: CoinConfig[] = defaultCoinConfig.map((x) => x("TESTKUDOS")); - let { - bankClient, - exchange, - merchant, - walletService, - walletClient, - } = await createSimpleTestkudosEnvironmentV3(t, coinConfig, { - skipWireFeeCreation: true, + let { bankClient, bank, exchange, merchant, walletClient } = + await createSimpleTestkudosEnvironmentV3(t, coinConfig, { + skipWireFeeCreation: true, + }); + + const dbTwo = await setupDb(t, { + nameSuffix: "two", + }); + + const exchangeTwo = ExchangeService.create(t, { + name: "testexchange-2", + currency: "TESTKUDOS", + httpPort: 9081, + database: dbTwo.connStr, }); + { + const receiverName = "Exchange2"; + const exchangeBankUsername = "exchange2"; + const exchangeBankPassword = "mypw"; + const exchangePaytoUri = generateRandomPayto(exchangeBankUsername); + const wireGatewayApiBaseUrl = new URL( + `accounts/${exchangeBankUsername}/taler-wire-gateway/`, + bank.corebankApiBaseUrl, + ).href; + + const exchangeBankAccount: HarnessExchangeBankAccount = { + wireGatewayApiBaseUrl, + accountName: exchangeBankUsername, + accountPassword: exchangeBankPassword, + accountPaytoUri: exchangePaytoUri, + skipWireFeeCreation: true, + }; + + await exchangeTwo.addBankAccount("1", exchangeBankAccount); + + await bankClient.registerAccountExtended({ + name: receiverName, + password: exchangeBankPassword, + username: exchangeBankUsername, + is_taler_exchange: true, + payto_uri: exchangePaytoUri, + }); + + exchangeTwo.addCoinConfigList(coinConfig); + + await exchangeTwo.start(); + } + await merchant.addInstanceWithWireAccount({ id: "default", name: "Default Instance", @@ -75,6 +118,8 @@ export async function runWalletInsufficientBalanceTest(t: GlobalTestState) { }, }); + t.logStep("setup-done"); + const wres = await withdrawViaBankV3(t, { amount: "TESTKUDOS:10", bankClient, @@ -83,29 +128,74 @@ export async function runWalletInsufficientBalanceTest(t: GlobalTestState) { }); await wres.withdrawalFinishedCond; - const exc = await t.assertThrowsTalerErrorAsync(async () => { - await walletClient.call(WalletApiOperation.CheckDeposit, { - amount: "TESTKUDOS:5" as AmountString, - depositPaytoUri: "payto://x-taler-bank/localhost/foobar", + { + const exc = await t.assertThrowsTalerErrorAsync(async () => { + await walletClient.call(WalletApiOperation.CheckDeposit, { + amount: "TESTKUDOS:5" as AmountString, + depositPaytoUri: "payto://x-taler-bank/localhost/foobar", + }); + }); + + t.assertDeepEqual( + exc.errorDetail.code, + TalerErrorCode.WALLET_DEPOSIT_GROUP_INSUFFICIENT_BALANCE, + ); + + const insufficientBalanceDetails: PaymentInsufficientBalanceDetails = + exc.errorDetail.insufficientBalanceDetails; + + t.assertAmountEquals( + insufficientBalanceDetails.balanceAvailable, + "TESTKUDOS:9.72", + ); + t.assertAmountEquals( + insufficientBalanceDetails.balanceExchangeDepositable, + "TESTKUDOS:0", + ); + } + + t.logStep("start-p2p-push-test"); + + // Now check for p2p-push + + { + const wres2 = await withdrawViaBankV3(t, { + amount: "TESTKUDOS:5", + bankClient, + exchange: exchangeTwo, + walletClient, + }); + await wres2.withdrawalFinishedCond; + + const exc = await t.assertThrowsTalerErrorAsync(async () => { + await walletClient.call(WalletApiOperation.CheckPeerPushDebit, { + amount: "TESTKUDOS:20" as AmountString, + }); }); - }); - t.assertDeepEqual( - exc.errorDetail.code, - TalerErrorCode.WALLET_DEPOSIT_GROUP_INSUFFICIENT_BALANCE, - ); - - const insufficientBalanceDetails: PaymentInsufficientBalanceDetails = - exc.errorDetail.insufficientBalanceDetails; - - t.assertAmountEquals( - insufficientBalanceDetails.balanceAvailable, - "TESTKUDOS:9.72", - ); - t.assertAmountEquals( - insufficientBalanceDetails.balanceExchangeDepositable, - "TESTKUDOS:0", - ); + const insufficientBalanceDetails: PaymentInsufficientBalanceDetails = + exc.errorDetail.insufficientBalanceDetails; + + const perMyExchange = + insufficientBalanceDetails.perExchange[exchange.baseUrl]; + + t.assertTrue(!!perMyExchange); + + console.log(j2s(exc.errorDetail)); + + t.assertAmountEquals( + insufficientBalanceDetails.amountRequested, + "TESTKUDOS:20", + ); + t.assertAmountEquals( + insufficientBalanceDetails.maxEffectiveSpendAmount, + "TESTKUDOS:14.22", + ); + t.assertAmountEquals( + perMyExchange.maxEffectiveSpendAmount, + "TESTKUDOS:9.47", + ); + } } runWalletInsufficientBalanceTest.suites = ["wallet"]; diff --git a/packages/taler-harness/src/integrationtests/test-wallettesting.ts b/packages/taler-harness/src/integrationtests/test-wallettesting.ts index 73585e206..42b73654c 100644 --- a/packages/taler-harness/src/integrationtests/test-wallettesting.ts +++ b/packages/taler-harness/src/integrationtests/test-wallettesting.ts @@ -44,7 +44,7 @@ export async function createMyEnvironment( ): Promise<SimpleTestEnvironmentNg3> { const db = await setupDb(t); - const { bankClient, exchange, merchant, exchangeBankAccount } = + const { bankClient, bank, exchange, merchant, exchangeBankAccount } = await createSimpleTestkudosEnvironmentV3(t, coinConfig, {}); console.log("setup done!"); @@ -62,6 +62,7 @@ export async function createMyEnvironment( merchant, walletClient, walletService, + bank, bankClient, exchangeBankAccount, }; |