aboutsummaryrefslogtreecommitdiff
path: root/packages
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2024-06-05 19:37:49 +0200
committerFlorian Dold <florian@dold.me>2024-06-05 19:37:49 +0200
commit93623571b0146c9a67085455bc3721e106a207cb (patch)
tree24313826ace1485690f4975247d93185efb6cde7 /packages
parent7631db2a902664f475b9074e305a95b0ad71a9df (diff)
downloadwallet-core-93623571b0146c9a67085455bc3721e106a207cb.tar.xz
wallet-core: properly adjust visibleCoinCount in availability record when refreshing a fresh coin
Diffstat (limited to 'packages')
-rw-r--r--packages/taler-harness/src/harness/harness.ts4
-rw-r--r--packages/taler-harness/src/integrationtests/test-timetravel-autorefresh.ts21
-rw-r--r--packages/taler-wallet-core/src/refresh.ts7
3 files changed, 17 insertions, 15 deletions
diff --git a/packages/taler-harness/src/harness/harness.ts b/packages/taler-harness/src/harness/harness.ts
index 136ec3d15..4fc462ddf 100644
--- a/packages/taler-harness/src/harness/harness.ts
+++ b/packages/taler-harness/src/harness/harness.ts
@@ -274,6 +274,7 @@ export class GlobalTestState {
procs: ProcessWrapper[];
servers: http.Server[];
inShutdown: boolean = false;
+ stepSet: Set<string> = new Set();
constructor(params: GlobalTestParams) {
this.testDir = params.testDir;
this.procs = [];
@@ -423,6 +424,9 @@ export class GlobalTestState {
// Now we just log, later we may report the steps that were done
// to easily see where the test hangs.
console.info(`STEP: ${stepName}`);
+ if (this.stepSet.has(stepName)) {
+ throw Error(`duplicate step (${stepName})`);
+ }
}
}
diff --git a/packages/taler-harness/src/integrationtests/test-timetravel-autorefresh.ts b/packages/taler-harness/src/integrationtests/test-timetravel-autorefresh.ts
index 8b8b45c40..f3e3802e5 100644
--- a/packages/taler-harness/src/integrationtests/test-timetravel-autorefresh.ts
+++ b/packages/taler-harness/src/integrationtests/test-timetravel-autorefresh.ts
@@ -18,14 +18,12 @@
* 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";
@@ -134,6 +132,7 @@ export async function runTimetravelAutorefreshTest(t: GlobalTestState) {
const { walletClient } = await createWalletDaemonWithClient(t, {
name: "w1",
+ persistent: true,
});
const merchantClient = new MerchantApiClient(merchant.makeInstanceBaseUrl());
@@ -160,9 +159,7 @@ export async function runTimetravelAutorefreshTest(t: GlobalTestState) {
await walletClient.call(WalletApiOperation.TestingWaitTransactionsFinal, {});
{
const balance = await walletClient.call(WalletApiOperation.GetBalances, {});
- t.assertTrue(
- Amounts.cmp(balance.balances[0].available, "TESTKUDOS:15") === 0,
- );
+ t.assertAmountEquals(balance.balances[0].available, "TESTKUDOS:15");
}
// Travel into the future, the deposit expiration is two years
@@ -180,13 +177,11 @@ 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");
+ t.logStep("exchange updated, waiting for tx");
await walletClient.call(WalletApiOperation.TestingWaitTransactionsFinal, {});
{
const balance = await walletClient.call(WalletApiOperation.GetBalances, {});
- t.assertTrue(
- Amounts.cmp(balance.balances[0].available, "TESTKUDOS:15") === 0,
- );
+ t.assertAmountEquals(balance.balances[0].available, "TESTKUDOS:15");
}
t.logStep("withdrawing second time");
@@ -203,9 +198,7 @@ export async function runTimetravelAutorefreshTest(t: GlobalTestState) {
{
const balance = await walletClient.call(WalletApiOperation.GetBalances, {});
- t.assertTrue(
- Amounts.cmp(balance.balances[0].available, "TESTKUDOS:35") === 0,
- );
+ t.assertAmountEquals(balance.balances[0].available, "TESTKUDOS:35");
}
const exchangeUpdated2Cond = walletClient.waitForNotificationCond(
@@ -232,9 +225,7 @@ export async function runTimetravelAutorefreshTest(t: GlobalTestState) {
await walletClient.call(WalletApiOperation.TestingWaitTransactionsFinal, {});
{
const balance = await walletClient.call(WalletApiOperation.GetBalances, {});
- t.assertTrue(
- Amounts.cmp(balance.balances[0].available, "TESTKUDOS:35") === 0,
- );
+ t.assertAmountEquals(balance.balances[0].available, "TESTKUDOS:35");
}
// At this point, the original coins should've been refreshed.
diff --git a/packages/taler-wallet-core/src/refresh.ts b/packages/taler-wallet-core/src/refresh.ts
index 7dcb755be..a8f1cc61d 100644
--- a/packages/taler-wallet-core/src/refresh.ts
+++ b/packages/taler-wallet-core/src/refresh.ts
@@ -1584,6 +1584,13 @@ async function applyRefreshToOldCoins(
`no fresh coins for ${coin.denomPubHash}`,
);
coinAv.freshCoinCount--;
+ if (coin.visible) {
+ if (!coinAv.visibleCoinCount) {
+ logger.error("coin availability inconsistent");
+ } else {
+ coinAv.visibleCoinCount--;
+ }
+ }
await tx.coinAvailability.put(coinAv);
break;
}