commit c3893d9a80e201e4b64724794bd406e1999e2418
parent a0e677863906ac7587fe065612da550751ba9a02
Author: Florian Dold <florian@dold.me>
Date: Wed, 4 Dec 2024 22:12:52 +0100
wallet-core: fix exchange list filtering by scope, test it
Diffstat:
2 files changed, 37 insertions(+), 6 deletions(-)
diff --git a/packages/taler-harness/src/integrationtests/test-currency-scope.ts b/packages/taler-harness/src/integrationtests/test-currency-scope.ts
@@ -17,7 +17,12 @@
/**
* Imports.
*/
-import { Duration, TalerCorebankApiClient, j2s } from "@gnu-taler/taler-util";
+import {
+ Duration,
+ ScopeType,
+ TalerCorebankApiClient,
+ j2s,
+} from "@gnu-taler/taler-util";
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
import { defaultCoinConfig } from "../harness/denomStructures.js";
import {
@@ -202,12 +207,32 @@ export async function runCurrencyScopeTest(t: GlobalTestState) {
exchangeMasterPub: exchangeOne.masterPub,
});
+ {
+ const exch1 = await walletClient.call(WalletApiOperation.ListExchanges, {
+ filterByScope: {
+ type: ScopeType.Global,
+ currency: "TESTKUDOS",
+ },
+ });
+ t.assertDeepEqual(exch1.exchanges.length, 1);
+ }
+
await walletClient.call(WalletApiOperation.AddGlobalCurrencyExchange, {
currency: "TESTKUDOS",
exchangeBaseUrl: exchangeTwo.baseUrl,
exchangeMasterPub: exchangeTwo.masterPub,
});
+ {
+ const exch1 = await walletClient.call(WalletApiOperation.ListExchanges, {
+ filterByScope: {
+ type: ScopeType.Global,
+ currency: "TESTKUDOS",
+ },
+ });
+ t.assertDeepEqual(exch1.exchanges.length, 2);
+ }
+
const ex = walletClient.call(
WalletApiOperation.ListGlobalCurrencyExchanges,
{},
diff --git a/packages/taler-wallet-core/src/exchanges.ts b/packages/taler-wallet-core/src/exchanges.ts
@@ -3612,6 +3612,9 @@ export async function checkExchangeInScopeTx(
exchangeBaseUrl: string,
scope: ScopeInfo,
): Promise<boolean> {
+ logger.trace(
+ `checking if exchange ${exchangeBaseUrl} is in scope ${j2s(scope)}`,
+ );
switch (scope.type) {
case ScopeType.Exchange: {
return scope.url === exchangeBaseUrl;
@@ -3622,13 +3625,16 @@ export async function checkExchangeInScopeTx(
exchangeBaseUrl,
);
if (!exchangeDetails) {
+ logger.trace(`no details for ${exchangeBaseUrl}`);
return false;
}
- const gr = await tx.globalCurrencyExchanges.get([
- exchangeDetails.currency,
- exchangeBaseUrl,
- exchangeDetails.masterPublicKey,
- ]);
+ const gr =
+ await tx.globalCurrencyExchanges.indexes.byCurrencyAndUrlAndPub.get([
+ exchangeDetails.currency,
+ exchangeBaseUrl,
+ exchangeDetails.masterPublicKey,
+ ]);
+ logger.trace(`global currency record: ${j2s(gr)}`);
return gr != null;
}
case ScopeType.Auditor: