quickjs-tart

quickjs-based runtime for wallet-core logic
Log | Files | Refs | README | LICENSE

commit dd601e6b7bad5628d715fc1237540097ac017bc0
parent be93b6ac80f366d400abe7aaffb1e53d231cae32
Author: Florian Dold <florian@dold.me>
Date:   Thu, 19 Jun 2025 23:29:10 +0200

tests

Diffstat:
Dtest_sqlite3.js | 63---------------------------------------------------------------
Rtest_prelude.js -> tests/test_prelude.js | 0
Atests/test_sqlite3_error.js | 0
Atests/test_wallet_export.js | 23+++++++++++++++++++++++
4 files changed, 23 insertions(+), 63 deletions(-)

diff --git a/test_sqlite3.js b/test_sqlite3.js @@ -1,63 +0,0 @@ -import * as tart from "tart"; -import * as std from "std"; - -function expectThrows(f) { - try { - f(); - } catch (e) { - return e; - } - throw Error("expected exception, but function did not throw"); -} - -function expectStrictEquals(actual, expected) { - if (actual !== expected) { - throw Error(); - } -} - -const db = tart.sqlite3Open(":memory:"); - -tart.sqlite3Exec(db, "create table foo ( name string unique, age number)"); - -let res; - -const stmt1 = tart.sqlite3Prepare(db, "insert into foo(name, age) values ($name, $value)") -res = tart.sqlite3StmtRun(stmt1, { name: "foo", value: 42 }); -console.log("stmt1 res:", res.lastInsertRowid); -res = tart.sqlite3StmtRun(stmt1, { name: "bar", value: 10 }); -console.log("stmt1 res:", res.lastInsertRowid); - -const stmt2 = tart.sqlite3Prepare(db, "select * from foo") -res = tart.sqlite3StmtGetAll(stmt2); - -console.log("result:", JSON.stringify(res)); - -const stmt3 = tart.sqlite3Prepare(db, "select * from foo") -res = tart.sqlite3StmtGetFirst(stmt3); - -console.log("result:", JSON.stringify(res)); - -tart.sqlite3Exec(db, "create table bla ( name string unique, data blob)"); -const stmt4 = tart.sqlite3Prepare(db, "insert into bla(name, data) values ($name, $value)") -const d = new Uint8Array(4); -d[0] = 42; -d[1] = 43; -d[2] = 44; -d[3] = 46; -res = tart.sqlite3StmtRun(stmt4, { name: "v1", value: d }); - -tart.sqlite3Exec(db, "create table t ( name string unique, data blob)"); -const stmt5 = tart.sqlite3Prepare(db, "insert into t(name, data) values ($name, $value)") - -res = tart.sqlite3StmtRun(stmt4, { name: "n1", value: "v1" }); -res = tart.sqlite3StmtRun(stmt4, { name: "n2", value: "v2" }); - -const exc = expectThrows(() => { - res = tart.sqlite3StmtRun(stmt4, { name: "n2", value: "v3" }); -}); - -expectStrictEquals(exc.code, "SQLITE_CONSTRAINT"); - -// Make sure that we can continue properly after a failed run -res = tart.sqlite3StmtRun(stmt4, { name: "n4", value: "v4" }); diff --git a/test_prelude.js b/tests/test_prelude.js diff --git a/tests/test_sqlite3_error.js b/tests/test_sqlite3_error.js diff --git a/tests/test_wallet_export.js b/tests/test_wallet_export.js @@ -0,0 +1,23 @@ +import * as tart from "tart"; + +const { talerUtilHttp, talerWalletCore, talerUtil } = talerModules; + +const { j2s } = talerUtil; + +const httpLib = talerUtilHttp.createPlatformHttpLib(); + +const { wallet } = await talerWalletCore.createNativeWalletHost2({ + httpLib, +}); + + +const initResp = await wallet.client.call(talerWalletCore.WalletApiOperation.InitWallet, {}); + +console.log(j2s(initResp)); + +const exportResp = await wallet.client.call(talerWalletCore.WalletApiOperation.ExportDbToFile, { + directory: "/tmp", + stem: "taler-wallet-export", + forceFormat: "json", +}); +