diff options
author | Florian Dold <florian@dold.me> | 2023-11-09 13:32:08 +0100 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2023-11-09 14:54:27 +0100 |
commit | 7e3d6938bf5184b88ab4d0b75e4dc3d10af7c60a (patch) | |
tree | 788fc3b96d0aece0810c0654f9e0162eb9c1fe67 | |
parent | 1024665001060b8a33378ff45f12426a1b152f25 (diff) | |
download | wallet-core-7e3d6938bf5184b88ab4d0b75e4dc3d10af7c60a.tar.xz |
wallet-core: fix bogus timestamp logic
-rw-r--r-- | packages/taler-harness/src/integrationtests/test-wallettesting.ts | 56 | ||||
-rw-r--r-- | packages/taler-util/src/time.test.ts | 2 | ||||
-rw-r--r-- | packages/taler-wallet-core/src/db.ts | 2 | ||||
-rw-r--r-- | packages/taler-wallet-core/src/operations/testing.ts | 60 | ||||
-rw-r--r-- | packages/taler-wallet-core/src/operations/transactions.ts | 91 |
5 files changed, 102 insertions, 109 deletions
diff --git a/packages/taler-harness/src/integrationtests/test-wallettesting.ts b/packages/taler-harness/src/integrationtests/test-wallettesting.ts index 69637b875..6b4444d07 100644 --- a/packages/taler-harness/src/integrationtests/test-wallettesting.ts +++ b/packages/taler-harness/src/integrationtests/test-wallettesting.ts @@ -34,7 +34,11 @@ import { WalletCli, generateRandomPayto, } from "../harness/harness.js"; -import { SimpleTestEnvironment } from "../harness/helpers.js"; +import { + SimpleTestEnvironment, + SimpleTestEnvironmentNg, + createWalletDaemonWithClient, +} from "../harness/helpers.js"; const merchantAuthToken = "secret-token:sandbox"; @@ -45,7 +49,7 @@ const merchantAuthToken = "secret-token:sandbox"; export async function createMyEnvironment( t: GlobalTestState, coinConfig: CoinConfig[] = defaultCoinConfig.map((x) => x("TESTKUDOS")), -): Promise<SimpleTestEnvironment> { +): Promise<SimpleTestEnvironmentNg> { const db = await setupDb(t); const bank = await BankService.create(t, { @@ -99,13 +103,19 @@ export async function createMyEnvironment( console.log("setup done!"); - const wallet = new WalletCli(t); + const { walletClient, walletService } = await createWalletDaemonWithClient( + t, + { + name: "w1", + }, + ); return { commonDb: db, exchange, merchant, - wallet, + walletClient, + walletService, bank, exchangeBankAccount, }; @@ -115,9 +125,11 @@ export async function createMyEnvironment( * Run test for basic, bank-integrated withdrawal. */ export async function runWallettestingTest(t: GlobalTestState) { - const { wallet, bank, exchange, merchant } = await createMyEnvironment(t); + const { walletClient, bank, exchange, merchant } = await createMyEnvironment( + t, + ); - await wallet.client.call(WalletApiOperation.RunIntegrationTest, { + await walletClient.call(WalletApiOperation.RunIntegrationTest, { amountToSpend: "TESTKUDOS:5" as AmountString, amountToWithdraw: "TESTKUDOS:10" as AmountString, corebankApiBaseUrl: bank.corebankApiBaseUrl, @@ -126,7 +138,7 @@ export async function runWallettestingTest(t: GlobalTestState) { merchantBaseUrl: merchant.makeInstanceBaseUrl(), }); - let txns = await wallet.client.call(WalletApiOperation.GetTransactions, {}); + let txns = await walletClient.call(WalletApiOperation.GetTransactions, {}); console.log(JSON.stringify(txns, undefined, 2)); let txTypes = txns.transactions.map((x) => x.type); @@ -139,42 +151,42 @@ export async function runWallettestingTest(t: GlobalTestState) { "payment", ]); - wallet.deleteDatabase(); + await walletClient.call(WalletApiOperation.ClearDb, {}); - await wallet.client.call(WalletApiOperation.WithdrawTestBalance, { + await walletClient.call(WalletApiOperation.WithdrawTestBalance, { amount: "TESTKUDOS:10" as AmountString, corebankApiBaseUrl: bank.corebankApiBaseUrl, exchangeBaseUrl: exchange.baseUrl, }); - await wallet.runUntilDone(); + await walletClient.call(WalletApiOperation.TestingWaitTransactionsFinal, {}); - await wallet.client.call(WalletApiOperation.TestPay, { + await walletClient.call(WalletApiOperation.TestPay, { amount: "TESTKUDOS:5" as AmountString, merchantAuthToken: merchantAuthToken, merchantBaseUrl: merchant.makeInstanceBaseUrl(), summary: "foo", }); - await wallet.runUntilDone(); + await walletClient.call(WalletApiOperation.TestingWaitTransactionsFinal, {}); - txns = await wallet.client.call(WalletApiOperation.GetTransactions, {}); + txns = await walletClient.call(WalletApiOperation.GetTransactions, {}); console.log(JSON.stringify(txns, undefined, 2)); txTypes = txns.transactions.map((x) => x.type); t.assertDeepEqual(txTypes, ["withdrawal", "payment"]); - wallet.deleteDatabase(); + await walletClient.call(WalletApiOperation.ClearDb, {}); - await wallet.client.call(WalletApiOperation.WithdrawTestBalance, { + await walletClient.call(WalletApiOperation.WithdrawTestBalance, { amount: "TESTKUDOS:10" as AmountString, corebankApiBaseUrl: bank.corebankApiBaseUrl, exchangeBaseUrl: exchange.baseUrl, }); - await wallet.runUntilDone(); + await walletClient.call(WalletApiOperation.TestingWaitTransactionsFinal, {}); - const coinDump = await wallet.client.call(WalletApiOperation.DumpCoins, {}); + const coinDump = await walletClient.call(WalletApiOperation.DumpCoins, {}); console.log("coin dump:", JSON.stringify(coinDump, undefined, 2)); @@ -194,7 +206,7 @@ export async function runWallettestingTest(t: GlobalTestState) { console.log("suspending coin"); - await wallet.client.call(WalletApiOperation.SetCoinSuspended, { + await walletClient.call(WalletApiOperation.SetCoinSuspended, { coinPub: susp, suspended: true, }); @@ -202,7 +214,7 @@ export async function runWallettestingTest(t: GlobalTestState) { // This should fail, as we've suspended a coin that we need // to pay. await t.assertThrowsAsync(async () => { - await wallet.client.call(WalletApiOperation.TestPay, { + await walletClient.call(WalletApiOperation.TestPay, { amount: "TESTKUDOS:5" as AmountString, merchantAuthToken: merchantAuthToken, merchantBaseUrl: merchant.makeInstanceBaseUrl(), @@ -212,19 +224,17 @@ export async function runWallettestingTest(t: GlobalTestState) { console.log("unsuspending coin"); - await wallet.client.call(WalletApiOperation.SetCoinSuspended, { + await walletClient.call(WalletApiOperation.SetCoinSuspended, { coinPub: susp, suspended: false, }); - await wallet.client.call(WalletApiOperation.TestPay, { + await walletClient.call(WalletApiOperation.TestPay, { amount: "TESTKUDOS:5" as AmountString, merchantAuthToken: merchantAuthToken, merchantBaseUrl: merchant.makeInstanceBaseUrl(), summary: "foo", }); - - await t.shutdown(); } runWallettestingTest.suites = ["wallet"]; diff --git a/packages/taler-util/src/time.test.ts b/packages/taler-util/src/time.test.ts index 876b35b9a..5dd8c7715 100644 --- a/packages/taler-util/src/time.test.ts +++ b/packages/taler-util/src/time.test.ts @@ -15,7 +15,7 @@ */ import test from "ava"; -import { Duration } from "./time.js"; +import { AbsoluteTime, Duration } from "./time.js"; test("duration parsing", (t) => { const d1 = Duration.fromPrettyString("1h"); diff --git a/packages/taler-wallet-core/src/db.ts b/packages/taler-wallet-core/src/db.ts index d59085dcc..3e8452bcd 100644 --- a/packages/taler-wallet-core/src/db.ts +++ b/packages/taler-wallet-core/src/db.ts @@ -189,7 +189,7 @@ export function timestampPreciseToDb( } else { let tUs = stamp.t_s * 1000000; if (stamp.off_us) { - tUs == stamp.off_us; + tUs += stamp.off_us; } return tUs as DbPreciseTimestamp; } diff --git a/packages/taler-wallet-core/src/operations/testing.ts b/packages/taler-wallet-core/src/operations/testing.ts index 3fff9ccaa..62766556c 100644 --- a/packages/taler-wallet-core/src/operations/testing.ts +++ b/packages/taler-wallet-core/src/operations/testing.ts @@ -15,66 +15,66 @@ */ /** + * @file + * Implementation of wallet-core operations that are used for testing, + * but typically not in the production wallet. + */ + +/** * Imports. */ import { AbsoluteTime, - base64FromArrayBuffer, + Amounts, + AmountString, + CheckPaymentResponse, + codecForAny, + codecForCheckPaymentResponse, ConfirmPayResultType, Duration, + IntegrationTestArgs, IntegrationTestV2Args, j2s, Logger, NotificationType, - RegisterAccountRequest, - stringToBytes, + PreparePayResultType, TalerCorebankApiClient, + TestPayArgs, TestPayResult, TransactionMajorState, TransactionMinorState, TransactionState, TransactionType, + URL, WithdrawTestBalanceRequest, } from "@gnu-taler/taler-util"; import { HttpRequestLibrary, readSuccessResponseJsonOrThrow, - checkSuccessResponseOrThrow, } from "@gnu-taler/taler-util/http"; -import { - AmountString, - codecForAny, - CheckPaymentResponse, - codecForCheckPaymentResponse, - IntegrationTestArgs, - Amounts, - TestPayArgs, - URL, - PreparePayResultType, -} from "@gnu-taler/taler-util"; +import { OpenedPromise, openPromise } from "../index.js"; import { InternalWalletState } from "../internal-wallet-state.js"; +import { checkLogicInvariant } from "../util/invariants.js"; +import { getBalances } from "./balance.js"; +import { updateExchangeFromUrl } from "./exchanges.js"; import { confirmPay, preparePayForUri, startRefundQueryForUri, } from "./pay-merchant.js"; -import { getBalances } from "./balance.js"; -import { checkLogicInvariant } from "../util/invariants.js"; -import { acceptWithdrawalFromUri } from "./withdraw.js"; -import { updateExchangeFromUrl } from "./exchanges.js"; import { initiatePeerPullPayment } from "./pay-peer-pull-credit.js"; import { - preparePeerPullDebit, confirmPeerPullDebit, + preparePeerPullDebit, } from "./pay-peer-pull-debit.js"; import { - preparePeerPushCredit, confirmPeerPushCredit, + preparePeerPushCredit, } from "./pay-peer-push-credit.js"; import { initiatePeerPushDebit } from "./pay-peer-push-debit.js"; -import { OpenedPromise, openPromise } from "../index.js"; -import { getTransactionById, getTransactions } from "./transactions.js"; import { getPendingOperations } from "./pending.js"; +import { getTransactionById, getTransactions } from "./transactions.js"; +import { acceptWithdrawalFromUri } from "./withdraw.js"; const logger = new Logger("operations/testing.ts"); @@ -83,20 +83,6 @@ interface MerchantBackendInfo { authToken?: string; } -/** - * Generate a random alphanumeric ID. Does *not* use cryptographically - * secure randomness. - */ -function makeId(length: number): string { - let result = ""; - const characters = - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; - for (let i = 0; i < length; i++) { - result += characters.charAt(Math.floor(Math.random() * characters.length)); - } - return result; -} - export async function withdrawTestBalance( ws: InternalWalletState, req: WithdrawTestBalanceRequest, diff --git a/packages/taler-wallet-core/src/operations/transactions.ts b/packages/taler-wallet-core/src/operations/transactions.ts index bebb3d60b..33ee2b424 100644 --- a/packages/taler-wallet-core/src/operations/transactions.ts +++ b/packages/taler-wallet-core/src/operations/transactions.ts @@ -31,8 +31,6 @@ import { stringifyPayPullUri, stringifyPayPushUri, TalerErrorCode, - TalerPreciseTimestamp, - TalerProtocolTimestamp, Transaction, TransactionByIdRequest, TransactionIdStr, @@ -50,12 +48,12 @@ import { DepositGroupRecord, ExchangeDetailsRecord, OperationRetryRecord, - PeerPullPaymentIncomingRecord, - PeerPullDebitRecordStatus, PeerPullCreditRecord, - PeerPushPaymentIncomingRecord, + PeerPullDebitRecordStatus, + PeerPullPaymentIncomingRecord, PeerPushCreditStatus, PeerPushDebitRecord, + PeerPushPaymentIncomingRecord, PurchaseRecord, PurchaseStatus, RefreshGroupRecord, @@ -68,7 +66,6 @@ import { } from "../db.js"; import { GetReadOnlyAccess, - timestampOptionalPreciseFromDb, timestampPreciseFromDb, timestampProtocolFromDb, WalletStoresV1, @@ -85,81 +82,56 @@ import { } from "./common.js"; import { abortDepositGroup, - failDepositTransaction, + computeDepositTransactionActions, computeDepositTransactionStatus, deleteDepositGroup, + failDepositTransaction, resumeDepositGroup, suspendDepositGroup, - computeDepositTransactionActions, } from "./deposits.js"; import { getExchangeDetails } from "./exchanges.js"; import { abortPayMerchant, - failPaymentTransaction, + computePayMerchantTransactionActions, computePayMerchantTransactionState, computeRefundTransactionState, expectProposalDownload, extractContractData, + failPaymentTransaction, resumePayMerchant, suspendPayMerchant, - computePayMerchantTransactionActions, } from "./pay-merchant.js"; import { - abortRefreshGroup, - failRefreshGroup, - computeRefreshTransactionState, - resumeRefreshGroup, - suspendRefreshGroup, - computeRefreshTransactionActions, -} from "./refresh.js"; -import { - abortTipTransaction, - failTipTransaction, - computeRewardTransactionStatus, - resumeTipTransaction, - suspendRewardTransaction, - computeTipTransactionActions, -} from "./reward.js"; -import { - abortWithdrawalTransaction, - augmentPaytoUrisForWithdrawal, - failWithdrawalTransaction, - computeWithdrawalTransactionStatus, - resumeWithdrawalTransaction, - suspendWithdrawalTransaction, - computeWithdrawalTransactionActions, -} from "./withdraw.js"; -import { - computePeerPullCreditTransactionState, + abortPeerPullCreditTransaction, computePeerPullCreditTransactionActions, - suspendPeerPullCreditTransaction, + computePeerPullCreditTransactionState, failPeerPullCreditTransaction, resumePeerPullCreditTransaction, - abortPeerPullCreditTransaction, + suspendPeerPullCreditTransaction, } from "./pay-peer-pull-credit.js"; import { - computePeerPullDebitTransactionState, + abortPeerPullDebitTransaction, computePeerPullDebitTransactionActions, - suspendPeerPullDebitTransaction, + computePeerPullDebitTransactionState, failPeerPullDebitTransaction, resumePeerPullDebitTransaction, - abortPeerPullDebitTransaction, + suspendPeerPullDebitTransaction, } from "./pay-peer-pull-debit.js"; import { - computePeerPushCreditTransactionState, + abortPeerPushCreditTransaction, computePeerPushCreditTransactionActions, - suspendPeerPushCreditTransaction, + computePeerPushCreditTransactionState, failPeerPushCreditTransaction, resumePeerPushCreditTransaction, - abortPeerPushCreditTransaction, + suspendPeerPushCreditTransaction, } from "./pay-peer-push-credit.js"; import { - computePeerPushDebitTransactionState, + abortPeerPushDebitTransaction, computePeerPushDebitTransactionActions, - suspendPeerPushDebitTransaction, + computePeerPushDebitTransactionState, failPeerPushDebitTransaction, resumePeerPushDebitTransaction, - abortPeerPushDebitTransaction, + suspendPeerPushDebitTransaction, } from "./pay-peer-push-debit.js"; import { iterRecordsForDeposit, @@ -173,6 +145,31 @@ import { iterRecordsForReward, iterRecordsForWithdrawal, } from "./pending.js"; +import { + abortRefreshGroup, + computeRefreshTransactionActions, + computeRefreshTransactionState, + failRefreshGroup, + resumeRefreshGroup, + suspendRefreshGroup, +} from "./refresh.js"; +import { + abortTipTransaction, + computeRewardTransactionStatus, + computeTipTransactionActions, + failTipTransaction, + resumeTipTransaction, + suspendRewardTransaction, +} from "./reward.js"; +import { + abortWithdrawalTransaction, + augmentPaytoUrisForWithdrawal, + computeWithdrawalTransactionActions, + computeWithdrawalTransactionStatus, + failWithdrawalTransaction, + resumeWithdrawalTransaction, + suspendWithdrawalTransaction, +} from "./withdraw.js"; const logger = new Logger("taler-wallet-core:transactions.ts"); |