From 7b7e3b4565169835ad04062d5c76ba655abd770a Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Thu, 10 Jun 2021 10:37:49 +0200 Subject: transaction fixes --- packages/idb-bridge/src/bridge-idb.ts | 19 +++++++++++++------ .../src/integrationtests/test-payment-multiple.ts | 12 ++++++------ .../src/integrationtests/test-revocation.ts | 12 ++++++------ .../integrationtests/test-timetravel-autorefresh.ts | 12 ++++++------ packages/taler-wallet-core/src/db.ts | 19 +++++++++++++++++++ packages/taler-wallet-core/src/util/query.ts | 14 ++++++++++---- 6 files changed, 60 insertions(+), 28 deletions(-) diff --git a/packages/idb-bridge/src/bridge-idb.ts b/packages/idb-bridge/src/bridge-idb.ts index 58cec8673..ecabfbc7a 100644 --- a/packages/idb-bridge/src/bridge-idb.ts +++ b/packages/idb-bridge/src/bridge-idb.ts @@ -1201,19 +1201,26 @@ export class BridgeIDBIndex implements IDBIndex { private _confirmIndexExists() { const storeSchema = this._schema.objectStores[this._objectStore._name]; if (!storeSchema) { - throw new InvalidStateError(); + throw new InvalidStateError( + `no schema for object store '${this._objectStore._name}'`, + ); } if (!storeSchema.indexes[this._name]) { - throw new InvalidStateError(); + throw new InvalidStateError( + `no schema for index '${this._name}' of object store '${this._objectStore._name}'`, + ); } } get(key: BridgeIDBKeyRange | IDBValidKey) { - this._confirmIndexExists(); - this._confirmActiveTransaction(); if (this._deleted) { throw new InvalidStateError(); } + if (this._objectStore._deleted) { + throw new InvalidStateError(); + } + this._confirmActiveTransaction(); + this._confirmIndexExists(); if (!(key instanceof BridgeIDBKeyRange)) { key = BridgeIDBKeyRange._valueToKeyRange(key); @@ -1595,10 +1602,10 @@ export class BridgeIDBObjectStore implements IDBObjectStore { */ _confirmActiveTransaction(): void { if (!this._transaction._active) { - throw new TransactionInactiveError(); + throw new TransactionInactiveError("transaction is not active"); } if (this._transaction._aborted) { - throw new TransactionInactiveError(); + throw new TransactionInactiveError("transaction has been aborted"); } } diff --git a/packages/taler-wallet-cli/src/integrationtests/test-payment-multiple.ts b/packages/taler-wallet-cli/src/integrationtests/test-payment-multiple.ts index 1dfbe4dba..5197967b8 100644 --- a/packages/taler-wallet-cli/src/integrationtests/test-payment-multiple.ts +++ b/packages/taler-wallet-cli/src/integrationtests/test-payment-multiple.ts @@ -82,18 +82,18 @@ async function setupTest( await merchant.start(); await merchant.pingUntilAvailable(); - await merchant.addInstance({ - id: "minst1", - name: "minst1", - paytoUris: ["payto://x-taler-bank/minst1"], - }); - await merchant.addInstance({ id: "default", name: "Default Instance", paytoUris: [`payto://x-taler-bank/merchant-default`], }); + await merchant.addInstance({ + id: "minst1", + name: "minst1", + paytoUris: ["payto://x-taler-bank/minst1"], + }); + console.log("setup done!"); return { diff --git a/packages/taler-wallet-cli/src/integrationtests/test-revocation.ts b/packages/taler-wallet-cli/src/integrationtests/test-revocation.ts index f6aad31ca..cf1eded12 100644 --- a/packages/taler-wallet-cli/src/integrationtests/test-revocation.ts +++ b/packages/taler-wallet-cli/src/integrationtests/test-revocation.ts @@ -117,18 +117,18 @@ async function createTestEnvironment( await merchant.start(); await merchant.pingUntilAvailable(); - await merchant.addInstance({ - id: "minst1", - name: "minst1", - paytoUris: ["payto://x-taler-bank/minst1"], - }); - await merchant.addInstance({ id: "default", name: "Default Instance", paytoUris: [`payto://x-taler-bank/merchant-default`], }); + await merchant.addInstance({ + id: "minst1", + name: "minst1", + paytoUris: ["payto://x-taler-bank/minst1"], + }); + console.log("setup done!"); const wallet = new WalletCli(t); diff --git a/packages/taler-wallet-cli/src/integrationtests/test-timetravel-autorefresh.ts b/packages/taler-wallet-cli/src/integrationtests/test-timetravel-autorefresh.ts index a1a0defb7..3f26aaf0d 100644 --- a/packages/taler-wallet-cli/src/integrationtests/test-timetravel-autorefresh.ts +++ b/packages/taler-wallet-cli/src/integrationtests/test-timetravel-autorefresh.ts @@ -114,18 +114,18 @@ export async function runTimetravelAutorefreshTest(t: GlobalTestState) { await merchant.start(); await merchant.pingUntilAvailable(); - await merchant.addInstance({ - id: "minst1", - name: "minst1", - paytoUris: ["payto://x-taler-bank/minst1"], - }); - await merchant.addInstance({ id: "default", name: "Default Instance", paytoUris: [`payto://x-taler-bank/merchant-default`], }); + await merchant.addInstance({ + id: "minst1", + name: "minst1", + paytoUris: ["payto://x-taler-bank/minst1"], + }); + console.log("setup done!"); const wallet = new WalletCli(t); diff --git a/packages/taler-wallet-core/src/db.ts b/packages/taler-wallet-core/src/db.ts index b6bab02c5..d02ea192f 100644 --- a/packages/taler-wallet-core/src/db.ts +++ b/packages/taler-wallet-core/src/db.ts @@ -1,3 +1,22 @@ +/* + This file is part of GNU Taler + (C) 2021 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see + */ + +/** + * Imports. + */ import { openDatabase, describeStore, diff --git a/packages/taler-wallet-core/src/util/query.ts b/packages/taler-wallet-core/src/util/query.ts index ab5a1fc7a..cf3f791d5 100644 --- a/packages/taler-wallet-core/src/util/query.ts +++ b/packages/taler-wallet-core/src/util/query.ts @@ -454,8 +454,11 @@ function makeReadContext( const indexes: { [s: string]: IndexReadOnlyAccessor } = {}; const swi = storePick[storeAlias]; const storeName = swi.store.name; - for (const indexName in storePick[storeAlias].indexMap) { - indexes[indexName] = { + for (const indexAlias in storePick[storeAlias].indexMap) { + const indexDescriptor: IndexDescriptor = + storePick[storeAlias].indexMap[indexAlias]; + const indexName = indexDescriptor.name; + indexes[indexAlias] = { get(key) { const req = tx.objectStore(storeName).index(indexName).get(key); return requestToPromise(req); @@ -493,8 +496,11 @@ function makeWriteContext( const indexes: { [s: string]: IndexReadWriteAccessor } = {}; const swi = storePick[storeAlias]; const storeName = swi.store.name; - for (const indexName in storePick[storeAlias].indexMap) { - indexes[indexName] = { + for (const indexAlias in storePick[storeAlias].indexMap) { + const indexDescriptor: IndexDescriptor = + storePick[storeAlias].indexMap[indexAlias]; + const indexName = indexDescriptor.name; + indexes[indexAlias] = { get(key) { const req = tx.objectStore(storeName).index(indexName).get(key); return requestToPromise(req); -- cgit v1.2.3